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 /* define paje hierarchy for tracing */
34 pajeDefineContainerType("PLATFORM", "0", "platform");
35 pajeDefineContainerType("HOST", "PLATFORM", "HOST");
36 pajeDefineContainerType("LINK", "PLATFORM", "LINK");
37 pajeDefineVariableType("power", "HOST", "power");
38 pajeDefineVariableType("bandwidth", "LINK", "bandwidth");
39 pajeDefineVariableType("latency", "LINK", "latency");
40 pajeDefineEventType("source", "LINK", "source");
41 pajeDefineEventType("destination", "LINK", "destination");
43 if (TRACE_platform_is_enabled()) {
44 if (TRACE_uncategorized()){
45 pajeDefineVariableType("power_used", "HOST", "power_used");
46 pajeDefineVariableType("bandwidth_used", "LINK", "bandwidth_used");
50 if (TRACE_msg_process_is_enabled() || TRACE_msg_volume_is_enabled()) {
51 //processes grouped by host
52 pajeDefineContainerType("PROCESS", "HOST", "PROCESS");
55 if (TRACE_msg_process_is_enabled()) {
56 pajeDefineStateType("category", "PROCESS", "category");
57 pajeDefineStateType("presence", "PROCESS", "presence");
60 if (TRACE_msg_volume_is_enabled()) {
61 pajeDefineLinkType("volume", "0", "PROCESS", "PROCESS", "volume");
64 if (TRACE_msg_task_is_enabled()) {
65 //tasks grouped by host
66 pajeDefineContainerType("TASK", "HOST", "TASK");
67 pajeDefineStateType("category", "TASK", "category");
68 pajeDefineStateType("presence", "TASK", "presence");
71 if (TRACE_smpi_is_enabled()) {
72 if (TRACE_smpi_is_grouped()){
73 pajeDefineContainerType("MPI_PROCESS", "HOST", "MPI_PROCESS");
75 pajeDefineContainerType("MPI_PROCESS", "PLATFORM", "MPI_PROCESS");
77 pajeDefineStateType("MPI_STATE", "MPI_PROCESS", "MPI_STATE");
78 pajeDefineLinkType("MPI_LINK", "0", "MPI_PROCESS", "MPI_PROCESS",
82 /* creating the platform */
83 pajeCreateContainer(MSG_get_clock(), "platform", "PLATFORM", "0",
86 /* other trace initialization */
87 defined_types = xbt_dict_new();
88 created_categories = xbt_dict_new();
89 TRACE_msg_task_alloc();
90 TRACE_category_alloc();
92 TRACE_msg_process_alloc();
99 if (!TRACE_is_active())
102 /* close the trace file */
106 TRACE_desactivate ();
110 int TRACE_category(const char *category)
112 return TRACE_category_with_color (category, NULL);
115 int TRACE_category_with_color (const char *category, const char *color)
117 static int first_time = 1;
118 if (!TRACE_is_active())
122 TRACE_define_type("user_type", "0", 1);
125 return TRACE_create_category_with_color(category, "user_type", "0", color);
128 void TRACE_define_type(const char *type,
129 const char *parent_type, int final)
131 char *val_one = NULL;
132 if (!TRACE_is_active())
135 //check if type is already defined
136 if (xbt_dict_get_or_null(defined_types, type)) {
137 THROW1(tracing_error, TRACE_ERROR_TYPE_ALREADY_DEFINED,
138 "Type %s is already defined", type);
140 //check if parent_type is already defined
141 if (strcmp(parent_type, "0")
142 && !xbt_dict_get_or_null(defined_types, parent_type)) {
143 THROW1(tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED,
144 "Type (used as parent) %s is not defined", parent_type);
147 pajeDefineContainerType(type, parent_type, type);
150 if (TRACE_msg_process_is_enabled())
151 pajeDefineContainerType("process", type, "process");
152 if (TRACE_msg_process_is_enabled())
153 pajeDefineStateType("process-state", "process", "process-state");
155 if (TRACE_msg_task_is_enabled())
156 pajeDefineContainerType("task", type, "task");
157 if (TRACE_msg_task_is_enabled())
158 pajeDefineStateType("task-state", "task", "task-state");
160 val_one = xbt_strdup("1");
161 xbt_dict_set(defined_types, type, &val_one, xbt_free);
164 int TRACE_create_category(const char *category,
165 const char *type, const char *parent_category)
167 return TRACE_create_category_with_color (category, type, parent_category, NULL);
170 int TRACE_create_category_with_color(const char *category,
172 const char *parent_category,
176 char *val_one = NULL;
177 if (!TRACE_is_active())
180 //check if type is defined
181 if (!xbt_dict_get_or_null(defined_types, type)) {
182 THROW1(tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED,
183 "Type %s is not defined", type);
186 //check if parent_category exists
187 if (strcmp(parent_category, "0")
188 && !xbt_dict_get_or_null(created_categories, parent_category)) {
189 THROW1(tracing_error, TRACE_ERROR_CATEGORY_NOT_DEFINED,
190 "Category (used as parent) %s is not created", parent_category);
193 //check if category is created
194 if (xbt_dict_get_or_null(created_categories, category)) {
198 pajeCreateContainer(MSG_get_clock(), category, type, parent_category,
201 char final_color[INSTR_DEFAULT_STR_SIZE];
203 //generate a random color
204 double red = drand48();
205 double green = drand48();
206 double blue = drand48();
207 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
209 snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
212 /* for registering application categories on top of platform */
213 snprintf(state, 100, "b%s", category);
214 if (TRACE_platform_is_enabled())
215 pajeDefineVariableTypeWithColor(state, "LINK", state, final_color);
216 snprintf(state, 100, "p%s", category);
217 if (TRACE_platform_is_enabled())
218 pajeDefineVariableTypeWithColor(state, "HOST", state, final_color);
220 val_one = xbt_strdup("1");
221 xbt_dict_set(created_categories, category, &val_one, xbt_free);
225 void TRACE_declare_mark(const char *mark_type)
227 if (!TRACE_is_active())
232 pajeDefineEventType(mark_type, "0", mark_type);
235 void TRACE_mark(const char *mark_type, const char *mark_value)
237 if (!TRACE_is_active())
239 if (!mark_type || !mark_value)
242 pajeNewEvent(MSG_get_clock(), mark_type, "0", mark_value);
245 #endif /* HAVE_TRACING */