1 /* Copyright (c) 2010. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "simgrid_config.h"
11 #include "instr/instr_private.h"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
15 xbt_dict_t defined_types;
16 xbt_dict_t created_categories;
18 int TRACE_category(const char *category)
20 return TRACE_category_with_color (category, NULL);
23 int TRACE_category_with_color (const char *category, const char *color)
25 static int first_time = 1;
26 if (!TRACE_is_active())
30 TRACE_define_type("user_type", "0", 1);
33 return TRACE_create_category_with_color(category, "user_type", "0", color);
36 void TRACE_define_type(const char *type,
37 const char *parent_type, int final)
40 if (!TRACE_is_active())
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);
52 pajeDefineContainerType(type, parent_type, type);
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");
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");
65 val_one = xbt_strdup("1");
66 xbt_dict_set(defined_types, type, &val_one, xbt_free);
69 int TRACE_create_category(const char *category,
70 const char *type, const char *parent_category)
72 return TRACE_create_category_with_color (category, type, parent_category, NULL);
75 int TRACE_create_category_with_color(const char *category,
77 const char *parent_category,
82 if (!TRACE_is_active())
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;
96 pajeCreateContainer(MSG_get_clock(), category, type, parent_category,
99 char final_color[INSTR_DEFAULT_STR_SIZE];
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);
107 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
110 DEBUG2("CAT,declare %s, %s", category, final_color);
112 /* for registering application categories on top of platform */
113 snprintf(state, 100, "b%s", category);
114 if (TRACE_categorized ())
115 pajeDefineVariableTypeWithColor(state, "LINK", state, final_color);
116 snprintf(state, 100, "p%s", category);
117 if (TRACE_categorized ())
118 pajeDefineVariableTypeWithColor(state, "HOST", state, final_color);
120 val_one = xbt_strdup("1");
121 xbt_dict_set(created_categories, category, &val_one, xbt_free);
125 void TRACE_declare_mark(const char *mark_type)
127 if (!TRACE_is_active())
132 DEBUG1("MARK,declare %s", mark_type);
133 pajeDefineEventType(mark_type, "0", mark_type);
136 void TRACE_mark(const char *mark_type, const char *mark_value)
138 if (!TRACE_is_active())
140 if (!mark_type || !mark_value)
143 DEBUG2("MARK %s %s", mark_type, mark_value);
144 pajeNewEvent(MSG_get_clock(), mark_type, "0", mark_value);
147 #endif /* HAVE_TRACING */