Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] declare smpi category and let instr continues if category already exists
[simgrid.git] / src / instr / instr_interface.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 "simgrid_config.h"
8
9 #ifdef HAVE_TRACING
10
11 #include "instr/instr_private.h"
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
14
15 xbt_dict_t defined_types;
16 xbt_dict_t created_categories;
17
18 int TRACE_category(const char *category)
19 {
20   return TRACE_category_with_color (category, NULL);
21 }
22
23 int TRACE_category_with_color (const char *category, const char *color)
24 {
25   static int first_time = 1;
26   if (!TRACE_is_active())
27     return 1;
28
29   if (first_time) {
30     TRACE_define_type("user_type", "0", 1);
31     first_time = 0;
32   }
33   return TRACE_create_category_with_color(category, "user_type", "0", color);
34 }
35
36 void TRACE_define_type(const char *type,
37                        const char *parent_type, int final)
38 {
39   char *val_one = NULL;
40   if (!TRACE_is_active())
41     return;
42
43   char *defined;
44   //type must not exist
45   defined = xbt_dict_get_or_null(defined_types, type);
46   xbt_assert1 (defined == NULL, "Type %s is already defined", type);
47   //parent_type must exist or be different of 0
48   defined = xbt_dict_get_or_null(defined_types, parent_type);
49   xbt_assert1 (defined != NULL || strcmp(parent_type, "0") == 0,
50       "Type (used as parent) %s is not defined", parent_type);
51
52   pajeDefineContainerType(type, parent_type, type);
53   if (final) {
54     //for m_process_t
55     if (TRACE_msg_process_is_enabled())
56       pajeDefineContainerType("process", type, "process");
57     if (TRACE_msg_process_is_enabled())
58       pajeDefineStateType("process-state", "process", "process-state");
59
60     if (TRACE_msg_task_is_enabled())
61       pajeDefineContainerType("task", type, "task");
62     if (TRACE_msg_task_is_enabled())
63       pajeDefineStateType("task-state", "task", "task-state");
64   }
65   val_one = xbt_strdup("1");
66   xbt_dict_set(defined_types, type, &val_one, xbt_free);
67 }
68
69 int TRACE_create_category(const char *category,
70                           const char *type, const char *parent_category)
71 {
72   return TRACE_create_category_with_color (category, type, parent_category, NULL);
73 }
74
75 int TRACE_create_category_with_color(const char *category,
76                           const char *type,
77                           const char *parent_category,
78                           const char *color)
79 {
80   char state[100];
81   char *val_one = NULL;
82   if (!TRACE_is_active())
83     return 1;
84
85   char *defined = xbt_dict_get_or_null(defined_types, type);
86   //check if type is defined
87   xbt_assert1 (defined != NULL, "Type %s is not defined", type);
88   //check if parent_category exists
89   defined = xbt_dict_get_or_null(created_categories, parent_category);
90   xbt_assert1 (defined != NULL || strcmp(parent_category, "0") == 0,
91       "Category (used as parent) %s is not created", parent_category);
92   //check if category is created
93   char *created = xbt_dict_get_or_null(created_categories, category);
94   if (created) return 0;
95
96   pajeCreateContainer(MSG_get_clock(), category, type, parent_category,
97                       category);
98
99   char final_color[INSTR_DEFAULT_STR_SIZE];
100   if (!color){
101     //generate a random color
102     double red = drand48();
103     double green = drand48();
104     double blue = drand48();
105     snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
106   }else{
107     snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
108   }
109
110   DEBUG2("CAT,declare %s, %s", category, final_color);
111
112   /* for registering application categories on top of platform */
113   snprintf(state, 100, "b%s", category);
114   if (TRACE_platform_is_enabled())
115     pajeDefineVariableTypeWithColor(state, "LINK", state, final_color);
116   snprintf(state, 100, "p%s", category);
117   if (TRACE_platform_is_enabled())
118     pajeDefineVariableTypeWithColor(state, "HOST", state, final_color);
119
120   val_one = xbt_strdup("1");
121   xbt_dict_set(created_categories, category, &val_one, xbt_free);
122   return 0;
123 }
124
125 void TRACE_declare_mark(const char *mark_type)
126 {
127   if (!TRACE_is_active())
128     return;
129   if (!mark_type)
130     return;
131
132   DEBUG1("MARK,declare %s", mark_type);
133   pajeDefineEventType(mark_type, "0", mark_type);
134 }
135
136 void TRACE_mark(const char *mark_type, const char *mark_value)
137 {
138   if (!TRACE_is_active())
139     return;
140   if (!mark_type || !mark_value)
141     return;
142
143   DEBUG2("MARK %s %s", mark_type, mark_value);
144   pajeNewEvent(MSG_get_clock(), mark_type, "0", mark_value);
145 }
146
147 #endif /* HAVE_TRACING */