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/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 if (!TRACE_is_configured()){
21 THROW0 (tracing_error, TRACE_ERROR_START,
22 "TRACE_start should be called after SimGrid initialization functions.");
26 if (IS_TRACING) { /* what? trace is already active... ignore.. */
27 THROW0 (tracing_error, TRACE_ERROR_START,
28 "TRACE_start called, but tracing is already active.");
32 char *filename = TRACE_get_filename ();
34 THROW0 (tracing_error, TRACE_ERROR_START,
35 "Trace filename is not initialized.");
38 FILE *file = fopen(filename, "w");
40 THROW1 (tracing_error, TRACE_ERROR_START,
41 "Tracefile %s could not be opened for writing.", filename);
43 TRACE_paje_start (file);
45 TRACE_paje_create_header();
47 /* define paje hierarchy for tracing */
48 pajeDefineContainerType("PLATFORM", "0", "platform");
49 pajeDefineContainerType("HOST", "PLATFORM", "HOST");
50 pajeDefineContainerType("LINK", "PLATFORM", "LINK");
52 if (IS_TRACING_PLATFORM){
53 pajeDefineVariableType ("power", "HOST", "power");
54 pajeDefineVariableType ("bandwidth", "LINK", "bandwidth");
55 pajeDefineVariableType ("latency", "LINK", "latency");
56 pajeDefineEventType ("source", "LINK", "source");
57 pajeDefineEventType ("destination", "LINK", "destination");
60 if (IS_TRACING_PROCESSES || IS_TRACING_VOLUME){
61 //processes grouped by host
62 pajeDefineContainerType("PROCESS", "HOST", "PROCESS");
65 if (IS_TRACING_PROCESSES){
66 pajeDefineStateType("category", "PROCESS", "category");
67 pajeDefineStateType("presence", "PROCESS", "presence");
70 if (IS_TRACING_VOLUME){
71 pajeDefineLinkType ("volume", "0", "PROCESS", "PROCESS", "volume");
74 if (IS_TRACING_TASKS){
75 //tasks grouped by host
76 pajeDefineContainerType("TASK", "HOST", "TASK");
77 pajeDefineStateType("category", "TASK", "category");
78 pajeDefineStateType("presence", "TASK", "presence");
82 pajeDefineContainerType ("MPI_PROCESS", "HOST", "MPI_PROCESS");
83 pajeDefineStateType ("MPI_STATE", "MPI_PROCESS", "MPI_STATE");
84 pajeDefineLinkType ("MPI_LINK", "0", "MPI_PROCESS", "MPI_PROCESS", "MPI_LINK");
87 /* creating the platform */
88 pajeCreateContainer(MSG_get_clock(), "platform", "PLATFORM", "0", "simgrid-platform");
90 /* other trace initialization */
91 defined_types = xbt_dict_new();
92 created_categories = xbt_dict_new();
93 TRACE_msg_task_alloc ();
94 TRACE_category_alloc ();
96 TRACE_msg_process_alloc ();
104 if (!IS_TRACING) return 1;
105 file = TRACE_paje_end();
110 int TRACE_category (const char *category)
112 static int first_time = 1;
113 if (!IS_TRACING) return 1;
116 TRACE_define_type ("user_type", "0", 1);
119 return TRACE_create_category (category, "user_type", "0");
122 void TRACE_define_type (const char *type,
123 const char *parent_type, int final) {
124 char *val_one = NULL;
125 if (!IS_TRACING) return;
127 //check if type is already defined
128 if (xbt_dict_get_or_null (defined_types, type)){
129 THROW1 (tracing_error, TRACE_ERROR_TYPE_ALREADY_DEFINED, "Type %s is already defined", type);
131 //check if parent_type is already defined
132 if (strcmp(parent_type, "0") && !xbt_dict_get_or_null (defined_types, parent_type)) {
133 THROW1 (tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, "Type (used as parent) %s is not defined", parent_type);
136 pajeDefineContainerType(type, parent_type, type);
139 if (IS_TRACING_PROCESSES) pajeDefineContainerType ("process", type, "process");
140 if (IS_TRACING_PROCESSES) pajeDefineStateType ("process-state", "process", "process-state");
142 if (IS_TRACING_TASKS) pajeDefineContainerType ("task", type, "task");
143 if (IS_TRACING_TASKS) pajeDefineStateType ("task-state", "task", "task-state");
145 val_one = xbt_strdup ("1");
146 xbt_dict_set (defined_types, type, &val_one, xbt_free);
149 int TRACE_create_category (const char *category,
150 const char *type, const char *parent_category)
153 char *val_one = NULL;
154 if (!IS_TRACING) return 1;
156 //check if type is defined
157 if (!xbt_dict_get_or_null (defined_types, type)) {
158 THROW1 (tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, "Type %s is not defined", type);
161 //check if parent_category exists
162 if (strcmp(parent_category, "0") && !xbt_dict_get_or_null (created_categories, parent_category)){
163 THROW1 (tracing_error, TRACE_ERROR_CATEGORY_NOT_DEFINED, "Category (used as parent) %s is not created", parent_category);
166 //check if category is created
167 if (xbt_dict_get_or_null (created_categories, category)){
171 pajeCreateContainer(MSG_get_clock(), category, type, parent_category, category);
173 /* for registering application categories on top of platform */
175 snprintf (state, 100, "b%s", category);
176 if (IS_TRACING_PLATFORM) pajeDefineVariableType (state, "LINK", state);
177 snprintf (state, 100, "p%s", category);
178 if (IS_TRACING_PLATFORM) pajeDefineVariableType (state, "HOST", state);
180 val_one = xbt_strdup ("1");
181 xbt_dict_set (created_categories, category, &val_one, xbt_free);
185 void TRACE_declare_mark (const char *mark_type)
187 if (!IS_TRACING) return;
188 if (!mark_type) return;
190 pajeDefineEventType (mark_type, "0", mark_type);
193 void TRACE_mark (const char *mark_type, const char *mark_value)
195 if (!IS_TRACING) return;
196 if (!mark_type || !mark_value) return;
198 pajeNewEvent (MSG_get_clock(), mark_type, "0", mark_value);
201 int TRACE_smpi_set_category (const char *category)
203 //if category is NULL, trace of platform is disabled
204 if (!IS_TRACING) return 1;
205 if (category != NULL){
206 int ret = TRACE_category (category);
207 TRACE_category_set (SIMIX_process_self(), category);
210 TRACE_category_unset (SIMIX_process_self());
215 #endif /* HAVE_TRACING */