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 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_uncategorized()){
49 pajeDefineVariableTypeWithColor("power_used", "HOST", "power_used", "0.5 0.5 0.5");
50 pajeDefineVariableTypeWithColor("bandwidth_used", "LINK", "bandwidth_used", "0.5 0.5 0.5");
53 /* type hierarchy for:
54 * --cfg=tracing/msg/process
55 * --cfg=tracing/msg/volume
57 if (TRACE_msg_process_is_enabled() || TRACE_msg_volume_is_enabled()) {
58 //processes grouped by host
59 pajeDefineContainerType("PROCESS", "HOST", "PROCESS");
62 if (TRACE_msg_process_is_enabled()) {
63 pajeDefineStateType("category", "PROCESS", "category");
64 pajeDefineStateType("presence", "PROCESS", "presence");
67 if (TRACE_msg_volume_is_enabled()) {
68 pajeDefineLinkType("volume", "0", "PROCESS", "PROCESS", "volume");
71 /* type hierarchy for:
72 * --cfg=tracing/msg/task
74 if (TRACE_msg_task_is_enabled()) {
75 //tasks grouped by host
76 pajeDefineContainerType("TASK", "HOST", "TASK");
77 pajeDefineStateType("category", "TASK", "category");
78 pajeDefineStateType("presence", "TASK", "presence");
83 * --cfg=tracing/smpi/group
85 if (TRACE_smpi_is_enabled()) {
86 if (TRACE_smpi_is_grouped()){
87 pajeDefineContainerType("MPI_PROCESS", "HOST", "MPI_PROCESS");
89 pajeDefineContainerType("MPI_PROCESS", "PLATFORM", "MPI_PROCESS");
91 pajeDefineStateType("MPI_STATE", "MPI_PROCESS", "MPI_STATE");
92 pajeDefineLinkType("MPI_LINK", "0", "MPI_PROCESS", "MPI_PROCESS",
96 /* creating the platform */
97 pajeCreateContainer(MSG_get_clock(), "platform", "PLATFORM", "0",
100 /* other trace initialization */
101 defined_types = xbt_dict_new();
102 created_categories = xbt_dict_new();
103 TRACE_msg_task_alloc();
104 TRACE_category_alloc();
106 TRACE_msg_process_alloc();
113 if (!TRACE_is_active())
116 /* close the trace file */
119 /* generate uncategorized graph configuration for triva */
120 if (TRACE_get_triva_uncat_conf()){
121 TRACE_generate_triva_uncat_conf();
124 /* generate categorized graph configuration for triva */
125 if (TRACE_get_triva_cat_conf()){
126 TRACE_generate_triva_cat_conf();
130 TRACE_desactivate ();
134 int TRACE_category(const char *category)
136 return TRACE_category_with_color (category, NULL);
139 int TRACE_category_with_color (const char *category, const char *color)
141 static int first_time = 1;
142 if (!TRACE_is_active())
146 TRACE_define_type("user_type", "0", 1);
149 return TRACE_create_category_with_color(category, "user_type", "0", color);
152 void TRACE_define_type(const char *type,
153 const char *parent_type, int final)
155 char *val_one = NULL;
156 if (!TRACE_is_active())
159 //check if type is already defined
160 if (xbt_dict_get_or_null(defined_types, type)) {
161 THROW1(tracing_error, TRACE_ERROR_TYPE_ALREADY_DEFINED,
162 "Type %s is already defined", type);
164 //check if parent_type is already defined
165 if (strcmp(parent_type, "0")
166 && !xbt_dict_get_or_null(defined_types, parent_type)) {
167 THROW1(tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED,
168 "Type (used as parent) %s is not defined", parent_type);
171 pajeDefineContainerType(type, parent_type, type);
174 if (TRACE_msg_process_is_enabled())
175 pajeDefineContainerType("process", type, "process");
176 if (TRACE_msg_process_is_enabled())
177 pajeDefineStateType("process-state", "process", "process-state");
179 if (TRACE_msg_task_is_enabled())
180 pajeDefineContainerType("task", type, "task");
181 if (TRACE_msg_task_is_enabled())
182 pajeDefineStateType("task-state", "task", "task-state");
184 val_one = xbt_strdup("1");
185 xbt_dict_set(defined_types, type, &val_one, xbt_free);
188 int TRACE_create_category(const char *category,
189 const char *type, const char *parent_category)
191 return TRACE_create_category_with_color (category, type, parent_category, NULL);
194 int TRACE_create_category_with_color(const char *category,
196 const char *parent_category,
200 char *val_one = NULL;
201 if (!TRACE_is_active())
204 //check if type is defined
205 if (!xbt_dict_get_or_null(defined_types, type)) {
206 THROW1(tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED,
207 "Type %s is not defined", type);
210 //check if parent_category exists
211 if (strcmp(parent_category, "0")
212 && !xbt_dict_get_or_null(created_categories, parent_category)) {
213 THROW1(tracing_error, TRACE_ERROR_CATEGORY_NOT_DEFINED,
214 "Category (used as parent) %s is not created", parent_category);
217 //check if category is created
218 if (xbt_dict_get_or_null(created_categories, category)) {
222 pajeCreateContainer(MSG_get_clock(), category, type, parent_category,
225 char final_color[INSTR_DEFAULT_STR_SIZE];
227 //generate a random color
228 double red = drand48();
229 double green = drand48();
230 double blue = drand48();
231 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
233 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
236 /* for registering application categories on top of platform */
237 snprintf(state, 100, "b%s", category);
238 if (TRACE_platform_is_enabled())
239 pajeDefineVariableTypeWithColor(state, "LINK", state, final_color);
240 snprintf(state, 100, "p%s", category);
241 if (TRACE_platform_is_enabled())
242 pajeDefineVariableTypeWithColor(state, "HOST", state, final_color);
244 val_one = xbt_strdup("1");
245 xbt_dict_set(created_categories, category, &val_one, xbt_free);
249 void TRACE_declare_mark(const char *mark_type)
251 if (!TRACE_is_active())
256 pajeDefineEventType(mark_type, "0", mark_type);
259 void TRACE_mark(const char *mark_type, const char *mark_value)
261 if (!TRACE_is_active())
263 if (!mark_type || !mark_value)
266 pajeNewEvent(MSG_get_clock(), mark_type, "0", mark_value);
269 #endif /* HAVE_TRACING */