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 "instr/private.h"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(tracing,"Tracing Interface");
14 static xbt_dict_t defined_types;
15 static xbt_dict_t created_categories;
20 * \brief Simple initialization of tracing.
22 * \param filename of the file that will contain the traces
23 * \return 0 if everything is ok
25 int TRACE_start (const char *filename)
27 return TRACE_start_with_mask (filename, TRACE_PLATFORM);
31 * \brief Initialization of tracing.
33 * Function to be called at first when tracing a simulation
35 * \param name of the file that will contain the traces
36 * \param mask to take into account during trace
37 * \return 0 if everything is ok
39 int TRACE_start_with_mask(const char *filename, int mask) {
41 if (IS_TRACING) { /* what? trace is already active... ignore.. */
42 THROW0 (tracing_error, TRACE_ERROR_START,
43 "TRACE_start called, but tracing is already active");
48 if (!(mask&TRACE_PLATFORM ||
52 THROW0 (tracing_error, TRACE_ERROR_MASK,
53 "unknown tracing mask");
56 file = fopen(filename, "w");
58 THROW1 (tracing_error, TRACE_ERROR_START,
59 "Tracefile %s could not be opened for writing.", filename);
61 TRACE_paje_start (file);
63 TRACE_paje_create_header();
65 /* setting the mask */
68 /* define paje hierarchy for tracing */
69 pajeDefineContainerType("PLATFORM", "0", "platform");
70 pajeDefineContainerType("HOST", "PLATFORM", "HOST");
71 pajeDefineContainerType("LINK", "PLATFORM", "LINK");
73 if (IS_TRACING_PLATFORM){
74 pajeDefineVariableType ("power", "HOST", "power");
75 pajeDefineVariableType ("bandwidth", "LINK", "bandwidth");
76 pajeDefineVariableType ("latency", "LINK", "latency");
79 if (IS_TRACING_PROCESSES || IS_TRACING_VOLUME){
80 //processes grouped by host
81 pajeDefineContainerType("PROCESS", "HOST", "PROCESS");
84 if (IS_TRACING_PROCESSES){
85 pajeDefineStateType("category", "PROCESS", "category");
86 pajeDefineStateType("presence", "PROCESS", "presence");
89 if (IS_TRACING_VOLUME){
90 pajeDefineLinkType ("volume", "0", "PROCESS", "PROCESS", "volume");
93 if (IS_TRACING_TASKS){
94 //tasks grouped by host
95 pajeDefineContainerType("TASK", "HOST", "TASK");
96 pajeDefineStateType("category", "TASK", "category");
97 pajeDefineStateType("presence", "TASK", "presence");
100 /* creating the platform */
101 pajeCreateContainer(MSG_get_clock(), "platform", "PLATFORM", "0", "simgrid-platform");
103 /* other trace initialization */
104 defined_types = xbt_dict_new();
105 created_categories = xbt_dict_new();
108 __TRACE_msg_process_init ();
115 if (!IS_TRACING) return 1;
116 file = TRACE_paje_end();
121 int TRACE_category (const char *category)
123 static int first_time = 1;
124 if (!IS_TRACING) return 1;
127 TRACE_define_type ("user_type", "0", 1);
130 return TRACE_create_category (category, "user_type", "0");
133 void TRACE_define_type (const char *type,
134 const char *parent_type, int final) {
135 char *val_one = NULL;
136 if (!IS_TRACING) return;
138 //check if type is already defined
139 if (xbt_dict_get_or_null (defined_types, type)){
140 THROW1 (tracing_error, TRACE_ERROR_TYPE_ALREADY_DEFINED, "Type %s is already defined", type);
142 //check if parent_type is already defined
143 if (strcmp(parent_type, "0") && !xbt_dict_get_or_null (defined_types, parent_type)) {
144 THROW1 (tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, "Type (used as parent) %s is not defined", parent_type);
147 pajeDefineContainerType(type, parent_type, type);
150 if (IS_TRACING_PROCESSES) pajeDefineContainerType ("process", type, "process");
151 if (IS_TRACING_PROCESSES) pajeDefineStateType ("process-state", "process", "process-state");
153 if (IS_TRACING_TASKS) pajeDefineContainerType ("task", type, "task");
154 if (IS_TRACING_TASKS) pajeDefineStateType ("task-state", "task", "task-state");
156 val_one = xbt_strdup ("1");
157 xbt_dict_set (defined_types, type, &val_one, xbt_free);
160 int TRACE_create_category (const char *category,
161 const char *type, const char *parent_category)
164 char *val_one = NULL;
165 if (!IS_TRACING) return 1;
167 //check if type is defined
168 if (!xbt_dict_get_or_null (defined_types, type)) {
169 THROW1 (tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, "Type %s is not defined", type);
172 //check if parent_category exists
173 if (strcmp(parent_category, "0") && !xbt_dict_get_or_null (created_categories, parent_category)){
174 THROW1 (tracing_error, TRACE_ERROR_CATEGORY_NOT_DEFINED, "Category (used as parent) %s is not created", parent_category);
177 //check if category is created
178 if (xbt_dict_get_or_null (created_categories, category)){
182 pajeCreateContainer(MSG_get_clock(), category, type, parent_category, category);
184 /* for registering application categories on top of platform */
186 snprintf (state, 100, "b%s", category);
187 if (IS_TRACING_PLATFORM) pajeDefineVariableType (state, "LINK", state);
188 snprintf (state, 100, "p%s", category);
189 if (IS_TRACING_PLATFORM) pajeDefineVariableType (state, "HOST", state);
191 val_one = xbt_strdup ("1");
192 xbt_dict_set (created_categories, category, &val_one, xbt_free);
196 void TRACE_set_mask (int mask)
198 if (mask != TRACE_PLATFORM){
205 void TRACE_declare_mark (const char *mark_type)
207 if (!IS_TRACING) return;
208 if (!mark_type) return;
210 pajeDefineEventType (mark_type, "0", mark_type);
213 void TRACE_mark (const char *mark_type, const char *mark_value)
215 if (!IS_TRACING) return;
216 if (!mark_type || !mark_value) return;
218 pajeNewEvent (MSG_get_clock(), mark_type, "0", mark_value);
221 #endif /* HAVE_TRACING */