Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
1f8781239a9d1772a41e1e0ca1f584e071ccefb0
[simgrid.git] / src / instr / instr_categories.c
1 /* Copyright (c) 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5   * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "instr/instr_private.h"
8
9 #ifdef HAVE_TRACING
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_category, instr, "Tracing category set/get/del of SMX processes");
12
13 static xbt_dict_t current_task_category = NULL;
14
15 void TRACE_category_alloc()
16 {
17   current_task_category = xbt_dict_new();
18 }
19
20 void TRACE_category_release()
21 {
22   xbt_dict_free(&current_task_category);
23 }
24
25 void TRACE_category_set(smx_process_t proc, const char *category)
26 {
27   char processid[100];
28   char *var_cpy = NULL;
29   snprintf(processid, 100, "%p", proc);
30   var_cpy = xbt_strdup(category);
31   DEBUG2("SET process %p, category %s", proc, category);
32   xbt_dict_set(current_task_category, processid, var_cpy, xbt_free);
33 }
34
35 char *TRACE_category_get(smx_process_t proc)
36 {
37   char processid[100];
38   snprintf(processid, 100, "%p", proc);
39   char *ret = xbt_dict_get_or_null(current_task_category, processid);
40   DEBUG2("GET process %p, category %s", proc, ret);
41   return ret;
42 }
43
44 void TRACE_category_unset(smx_process_t proc)
45 {
46   char processid[100];
47   snprintf(processid, 100, "%p", proc);
48   char *category = xbt_dict_get_or_null(current_task_category, processid);
49   if (category != NULL) {
50     DEBUG2("DEL process %p, category %s", proc, category);
51     xbt_dict_remove(current_task_category, processid);
52   }
53 }
54
55 #endif /* HAVE_TRACING */