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 static xbt_dict_t defined_types;
16 xbt_dict_t created_categories;
20 // tracing system must be:
21 // - enabled (with --cfg=tracing:1)
22 // - already configured (TRACE_global_init already called)
23 if (!(TRACE_is_enabled() && TRACE_is_configured())){
27 DEBUG0("Tracing starts");
29 /* open the trace file */
35 /* base type hierarchy:
38 pajeDefineContainerType("PLATFORM", "0", "platform");
39 pajeDefineContainerType("HOST", "PLATFORM", "HOST");
40 pajeDefineContainerType("LINK", "PLATFORM", "LINK");
41 pajeDefineVariableType("power", "HOST", "power");
42 pajeDefineVariableType("bandwidth", "LINK", "bandwidth");
43 pajeDefineVariableType("latency", "LINK", "latency");
44 pajeDefineEventType("source", "LINK", "source");
45 pajeDefineEventType("destination", "LINK", "destination");
47 /* type hierarchy for:
48 * --cfg=tracing/uncategorized
50 if (TRACE_uncategorized()){
51 pajeDefineVariableTypeWithColor("power_used", "HOST", "power_used", "0.5 0.5 0.5");
52 pajeDefineVariableTypeWithColor("bandwidth_used", "LINK", "bandwidth_used", "0.5 0.5 0.5");
55 /* type hierarchy for:
56 * --cfg=tracing/msg/process
57 * --cfg=tracing/msg/volume
59 if (TRACE_msg_process_is_enabled() || TRACE_msg_volume_is_enabled()) {
60 //processes grouped by host
61 pajeDefineContainerType("PROCESS", "HOST", "PROCESS");
64 if (TRACE_msg_process_is_enabled()) {
65 pajeDefineStateType("category", "PROCESS", "category");
66 pajeDefineStateType("presence", "PROCESS", "presence");
69 if (TRACE_msg_volume_is_enabled()) {
70 pajeDefineLinkType("volume", "0", "PROCESS", "PROCESS", "volume");
73 /* type hierarchy for:
74 * --cfg=tracing/msg/task
76 if (TRACE_msg_task_is_enabled()) {
77 //tasks grouped by host
78 pajeDefineContainerType("TASK", "HOST", "TASK");
79 pajeDefineStateType("category", "TASK", "category");
80 pajeDefineStateType("presence", "TASK", "presence");
85 * --cfg=tracing/smpi/group
87 if (TRACE_smpi_is_enabled()) {
88 if (TRACE_smpi_is_grouped()){
89 pajeDefineContainerType("MPI_PROCESS", "HOST", "MPI_PROCESS");
91 pajeDefineContainerType("MPI_PROCESS", "PLATFORM", "MPI_PROCESS");
93 pajeDefineStateType("MPI_STATE", "MPI_PROCESS", "MPI_STATE");
94 pajeDefineLinkType("MPI_LINK", "0", "MPI_PROCESS", "MPI_PROCESS",
98 /* creating the platform */
99 pajeCreateContainer(MSG_get_clock(), "platform", "PLATFORM", "0",
102 /* other trace initialization */
103 defined_types = xbt_dict_new();
104 created_categories = xbt_dict_new();
105 TRACE_msg_task_alloc();
106 TRACE_category_alloc();
108 TRACE_msg_process_alloc();
115 if (!TRACE_is_active())
119 /* close the trace file */
122 /* generate uncategorized graph configuration for triva */
123 if (TRACE_get_triva_uncat_conf()){
124 TRACE_generate_triva_uncat_conf();
127 /* generate categorized graph configuration for triva */
128 if (TRACE_get_triva_cat_conf()){
129 TRACE_generate_triva_cat_conf();
133 TRACE_desactivate ();
134 DEBUG0("Tracing system is shutdown");
138 int TRACE_category(const char *category)
140 return TRACE_category_with_color (category, NULL);
143 int TRACE_category_with_color (const char *category, const char *color)
145 static int first_time = 1;
146 if (!TRACE_is_active())
150 TRACE_define_type("user_type", "0", 1);
153 return TRACE_create_category_with_color(category, "user_type", "0", color);
156 void TRACE_define_type(const char *type,
157 const char *parent_type, int final)
159 char *val_one = NULL;
160 if (!TRACE_is_active())
164 //type must not exist
165 defined = xbt_dict_get_or_null(defined_types, type);
166 xbt_assert1 (defined == NULL, "Type %s is already defined", type);
167 //parent_type must exist or be different of 0
168 defined = xbt_dict_get_or_null(defined_types, parent_type);
169 xbt_assert1 (defined != NULL || strcmp(parent_type, "0") == 0,
170 "Type (used as parent) %s is not defined", parent_type);
172 pajeDefineContainerType(type, parent_type, type);
175 if (TRACE_msg_process_is_enabled())
176 pajeDefineContainerType("process", type, "process");
177 if (TRACE_msg_process_is_enabled())
178 pajeDefineStateType("process-state", "process", "process-state");
180 if (TRACE_msg_task_is_enabled())
181 pajeDefineContainerType("task", type, "task");
182 if (TRACE_msg_task_is_enabled())
183 pajeDefineStateType("task-state", "task", "task-state");
185 val_one = xbt_strdup("1");
186 xbt_dict_set(defined_types, type, &val_one, xbt_free);
189 int TRACE_create_category(const char *category,
190 const char *type, const char *parent_category)
192 return TRACE_create_category_with_color (category, type, parent_category, NULL);
195 int TRACE_create_category_with_color(const char *category,
197 const char *parent_category,
201 char *val_one = NULL;
202 if (!TRACE_is_active())
205 char *defined = xbt_dict_get_or_null(defined_types, type);
206 //check if type is defined
207 xbt_assert1 (defined != NULL, "Type %s is not defined", type);
208 //check if parent_category exists
209 defined = xbt_dict_get_or_null(created_categories, parent_category);
210 xbt_assert1 (defined != NULL || strcmp(parent_category, "0") == 0,
211 "Category (used as parent) %s is not created", parent_category);
212 //check if category is created
213 char *created = xbt_dict_get_or_null(created_categories, category);
214 xbt_assert1 (created == NULL, "Category %s is already defined", category);
216 pajeCreateContainer(MSG_get_clock(), category, type, parent_category,
219 char final_color[INSTR_DEFAULT_STR_SIZE];
221 //generate a random color
222 double red = drand48();
223 double green = drand48();
224 double blue = drand48();
225 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
227 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
230 DEBUG2("CAT,declare %s, %s", category, final_color);
232 /* for registering application categories on top of platform */
233 snprintf(state, 100, "b%s", category);
234 if (TRACE_platform_is_enabled())
235 pajeDefineVariableTypeWithColor(state, "LINK", state, final_color);
236 snprintf(state, 100, "p%s", category);
237 if (TRACE_platform_is_enabled())
238 pajeDefineVariableTypeWithColor(state, "HOST", state, final_color);
240 val_one = xbt_strdup("1");
241 xbt_dict_set(created_categories, category, &val_one, xbt_free);
245 void TRACE_declare_mark(const char *mark_type)
247 if (!TRACE_is_active())
252 DEBUG1("MARK,declare %s", mark_type);
253 pajeDefineEventType(mark_type, "0", mark_type);
256 void TRACE_mark(const char *mark_type, const char *mark_value)
258 if (!TRACE_is_active())
260 if (!mark_type || !mark_value)
263 DEBUG2("MARK %s %s", mark_type, mark_value);
264 pajeNewEvent(MSG_get_clock(), mark_type, "0", mark_value);
267 #endif /* HAVE_TRACING */