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_CATEGORY(tracing, "Tracing Interface");
15 static xbt_dict_t defined_types;
16 static 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 /* open the trace file */
33 /* base type hierarchy:
36 pajeDefineContainerType("PLATFORM", "0", "platform");
37 pajeDefineContainerType("HOST", "PLATFORM", "HOST");
38 pajeDefineContainerType("LINK", "PLATFORM", "LINK");
39 pajeDefineVariableType("power", "HOST", "power");
40 pajeDefineVariableType("bandwidth", "LINK", "bandwidth");
41 pajeDefineVariableType("latency", "LINK", "latency");
42 pajeDefineEventType("source", "LINK", "source");
43 pajeDefineEventType("destination", "LINK", "destination");
45 /* type hierarchy for:
46 * --cfg=tracing/uncategorized
48 if (TRACE_platform_is_enabled()) {
49 if (TRACE_uncategorized()){
50 pajeDefineVariableType("power_used", "HOST", "power_used");
51 pajeDefineVariableType("bandwidth_used", "LINK", "bandwidth_used");
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())
118 /* close the trace file */
122 TRACE_desactivate ();
126 int TRACE_category(const char *category)
128 return TRACE_category_with_color (category, NULL);
131 int TRACE_category_with_color (const char *category, const char *color)
133 static int first_time = 1;
134 if (!TRACE_is_active())
138 TRACE_define_type("user_type", "0", 1);
141 return TRACE_create_category_with_color(category, "user_type", "0", color);
144 void TRACE_define_type(const char *type,
145 const char *parent_type, int final)
147 char *val_one = NULL;
148 if (!TRACE_is_active())
151 //check if type is already defined
152 if (xbt_dict_get_or_null(defined_types, type)) {
153 THROW1(tracing_error, TRACE_ERROR_TYPE_ALREADY_DEFINED,
154 "Type %s is already defined", type);
156 //check if parent_type is already defined
157 if (strcmp(parent_type, "0")
158 && !xbt_dict_get_or_null(defined_types, parent_type)) {
159 THROW1(tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED,
160 "Type (used as parent) %s is not defined", parent_type);
163 pajeDefineContainerType(type, parent_type, type);
166 if (TRACE_msg_process_is_enabled())
167 pajeDefineContainerType("process", type, "process");
168 if (TRACE_msg_process_is_enabled())
169 pajeDefineStateType("process-state", "process", "process-state");
171 if (TRACE_msg_task_is_enabled())
172 pajeDefineContainerType("task", type, "task");
173 if (TRACE_msg_task_is_enabled())
174 pajeDefineStateType("task-state", "task", "task-state");
176 val_one = xbt_strdup("1");
177 xbt_dict_set(defined_types, type, &val_one, xbt_free);
180 int TRACE_create_category(const char *category,
181 const char *type, const char *parent_category)
183 return TRACE_create_category_with_color (category, type, parent_category, NULL);
186 int TRACE_create_category_with_color(const char *category,
188 const char *parent_category,
192 char *val_one = NULL;
193 if (!TRACE_is_active())
196 //check if type is defined
197 if (!xbt_dict_get_or_null(defined_types, type)) {
198 THROW1(tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED,
199 "Type %s is not defined", type);
202 //check if parent_category exists
203 if (strcmp(parent_category, "0")
204 && !xbt_dict_get_or_null(created_categories, parent_category)) {
205 THROW1(tracing_error, TRACE_ERROR_CATEGORY_NOT_DEFINED,
206 "Category (used as parent) %s is not created", parent_category);
209 //check if category is created
210 if (xbt_dict_get_or_null(created_categories, category)) {
214 pajeCreateContainer(MSG_get_clock(), category, type, parent_category,
217 char final_color[INSTR_DEFAULT_STR_SIZE];
219 //generate a random color
220 double red = drand48();
221 double green = drand48();
222 double blue = drand48();
223 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
225 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
228 /* for registering application categories on top of platform */
229 snprintf(state, 100, "b%s", category);
230 if (TRACE_platform_is_enabled())
231 pajeDefineVariableTypeWithColor(state, "LINK", state, final_color);
232 snprintf(state, 100, "p%s", category);
233 if (TRACE_platform_is_enabled())
234 pajeDefineVariableTypeWithColor(state, "HOST", state, final_color);
236 val_one = xbt_strdup("1");
237 xbt_dict_set(created_categories, category, &val_one, xbt_free);
241 void TRACE_declare_mark(const char *mark_type)
243 if (!TRACE_is_active())
248 pajeDefineEventType(mark_type, "0", mark_type);
251 void TRACE_mark(const char *mark_type, const char *mark_value)
253 if (!TRACE_is_active())
255 if (!mark_type || !mark_value)
258 pajeNewEvent(MSG_get_clock(), mark_type, "0", mark_value);
261 #endif /* HAVE_TRACING */