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 if (TRACE_uncategorized()){
55 pajeDefineVariableType("power_used", "HOST", "power_used");
56 pajeDefineVariableType("bandwidth_used", "LINK", "bandwidth_used");
58 pajeDefineVariableType("bandwidth", "LINK", "bandwidth");
59 pajeDefineVariableType("latency", "LINK", "latency");
60 pajeDefineEventType("source", "LINK", "source");
61 pajeDefineEventType("destination", "LINK", "destination");
64 if (IS_TRACING_PROCESSES || IS_TRACING_VOLUME) {
65 //processes grouped by host
66 pajeDefineContainerType("PROCESS", "HOST", "PROCESS");
69 if (IS_TRACING_PROCESSES) {
70 pajeDefineStateType("category", "PROCESS", "category");
71 pajeDefineStateType("presence", "PROCESS", "presence");
74 if (IS_TRACING_VOLUME) {
75 pajeDefineLinkType("volume", "0", "PROCESS", "PROCESS", "volume");
78 if (IS_TRACING_TASKS) {
79 //tasks grouped by host
80 pajeDefineContainerType("TASK", "HOST", "TASK");
81 pajeDefineStateType("category", "TASK", "category");
82 pajeDefineStateType("presence", "TASK", "presence");
85 if (IS_TRACING_SMPI) {
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();
117 file = TRACE_paje_end();
122 int TRACE_category(const char *category)
124 static int first_time = 1;
129 TRACE_define_type("user_type", "0", 1);
132 return TRACE_create_category(category, "user_type", "0");
135 void TRACE_define_type(const char *type,
136 const char *parent_type, int final)
138 char *val_one = NULL;
142 //check if type is already defined
143 if (xbt_dict_get_or_null(defined_types, type)) {
144 THROW1(tracing_error, TRACE_ERROR_TYPE_ALREADY_DEFINED,
145 "Type %s is already defined", type);
147 //check if parent_type is already defined
148 if (strcmp(parent_type, "0")
149 && !xbt_dict_get_or_null(defined_types, parent_type)) {
150 THROW1(tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED,
151 "Type (used as parent) %s is not defined", parent_type);
154 pajeDefineContainerType(type, parent_type, type);
157 if (IS_TRACING_PROCESSES)
158 pajeDefineContainerType("process", type, "process");
159 if (IS_TRACING_PROCESSES)
160 pajeDefineStateType("process-state", "process", "process-state");
162 if (IS_TRACING_TASKS)
163 pajeDefineContainerType("task", type, "task");
164 if (IS_TRACING_TASKS)
165 pajeDefineStateType("task-state", "task", "task-state");
167 val_one = xbt_strdup("1");
168 xbt_dict_set(defined_types, type, &val_one, xbt_free);
171 int TRACE_create_category(const char *category,
172 const char *type, const char *parent_category)
175 char *val_one = NULL;
179 //check if type is defined
180 if (!xbt_dict_get_or_null(defined_types, type)) {
181 THROW1(tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED,
182 "Type %s is not defined", type);
185 //check if parent_category exists
186 if (strcmp(parent_category, "0")
187 && !xbt_dict_get_or_null(created_categories, parent_category)) {
188 THROW1(tracing_error, TRACE_ERROR_CATEGORY_NOT_DEFINED,
189 "Category (used as parent) %s is not created", parent_category);
192 //check if category is created
193 if (xbt_dict_get_or_null(created_categories, category)) {
197 pajeCreateContainer(MSG_get_clock(), category, type, parent_category,
200 /* for registering application categories on top of platform */
202 snprintf(state, 100, "b%s", category);
203 if (IS_TRACING_PLATFORM)
204 pajeDefineVariableType(state, "LINK", state);
205 snprintf(state, 100, "p%s", category);
206 if (IS_TRACING_PLATFORM)
207 pajeDefineVariableType(state, "HOST", state);
209 val_one = xbt_strdup("1");
210 xbt_dict_set(created_categories, category, &val_one, xbt_free);
214 void TRACE_declare_mark(const char *mark_type)
221 pajeDefineEventType(mark_type, "0", mark_type);
224 void TRACE_mark(const char *mark_type, const char *mark_value)
228 if (!mark_type || !mark_value)
231 pajeNewEvent(MSG_get_clock(), mark_type, "0", mark_value);
234 #endif /* HAVE_TRACING */