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("power_used", "HOST", "power_used");
55 pajeDefineVariableType("bandwidth", "LINK", "bandwidth");
56 pajeDefineVariableType("bandwidth_used", "LINK", "bandwidth_used");
57 pajeDefineVariableType("latency", "LINK", "latency");
58 pajeDefineEventType("source", "LINK", "source");
59 pajeDefineEventType("destination", "LINK", "destination");
62 if (IS_TRACING_PROCESSES || IS_TRACING_VOLUME) {
63 //processes grouped by host
64 pajeDefineContainerType("PROCESS", "HOST", "PROCESS");
67 if (IS_TRACING_PROCESSES) {
68 pajeDefineStateType("category", "PROCESS", "category");
69 pajeDefineStateType("presence", "PROCESS", "presence");
72 if (IS_TRACING_VOLUME) {
73 pajeDefineLinkType("volume", "0", "PROCESS", "PROCESS", "volume");
76 if (IS_TRACING_TASKS) {
77 //tasks grouped by host
78 pajeDefineContainerType("TASK", "HOST", "TASK");
79 pajeDefineStateType("category", "TASK", "category");
80 pajeDefineStateType("presence", "TASK", "presence");
83 if (IS_TRACING_SMPI) {
84 pajeDefineContainerType("MPI_PROCESS", "HOST", "MPI_PROCESS");
85 pajeDefineStateType("MPI_STATE", "MPI_PROCESS", "MPI_STATE");
86 pajeDefineLinkType("MPI_LINK", "0", "MPI_PROCESS", "MPI_PROCESS",
90 /* creating the platform */
91 pajeCreateContainer(MSG_get_clock(), "platform", "PLATFORM", "0",
94 /* other trace initialization */
95 defined_types = xbt_dict_new();
96 created_categories = xbt_dict_new();
97 TRACE_msg_task_alloc();
98 TRACE_category_alloc();
100 TRACE_msg_process_alloc();
111 file = TRACE_paje_end();
116 int TRACE_category(const char *category)
118 static int first_time = 1;
123 TRACE_define_type("user_type", "0", 1);
126 return TRACE_create_category(category, "user_type", "0");
129 void TRACE_define_type(const char *type,
130 const char *parent_type, int final)
132 char *val_one = NULL;
136 //check if type is already defined
137 if (xbt_dict_get_or_null(defined_types, type)) {
138 THROW1(tracing_error, TRACE_ERROR_TYPE_ALREADY_DEFINED,
139 "Type %s is already defined", type);
141 //check if parent_type is already defined
142 if (strcmp(parent_type, "0")
143 && !xbt_dict_get_or_null(defined_types, parent_type)) {
144 THROW1(tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED,
145 "Type (used as parent) %s is not defined", parent_type);
148 pajeDefineContainerType(type, parent_type, type);
151 if (IS_TRACING_PROCESSES)
152 pajeDefineContainerType("process", type, "process");
153 if (IS_TRACING_PROCESSES)
154 pajeDefineStateType("process-state", "process", "process-state");
156 if (IS_TRACING_TASKS)
157 pajeDefineContainerType("task", type, "task");
158 if (IS_TRACING_TASKS)
159 pajeDefineStateType("task-state", "task", "task-state");
161 val_one = xbt_strdup("1");
162 xbt_dict_set(defined_types, type, &val_one, xbt_free);
165 int TRACE_create_category(const char *category,
166 const char *type, const char *parent_category)
169 char *val_one = NULL;
173 //check if type is defined
174 if (!xbt_dict_get_or_null(defined_types, type)) {
175 THROW1(tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED,
176 "Type %s is not defined", type);
179 //check if parent_category exists
180 if (strcmp(parent_category, "0")
181 && !xbt_dict_get_or_null(created_categories, parent_category)) {
182 THROW1(tracing_error, TRACE_ERROR_CATEGORY_NOT_DEFINED,
183 "Category (used as parent) %s is not created", parent_category);
186 //check if category is created
187 if (xbt_dict_get_or_null(created_categories, category)) {
191 pajeCreateContainer(MSG_get_clock(), category, type, parent_category,
194 /* for registering application categories on top of platform */
196 snprintf(state, 100, "b%s", category);
197 if (IS_TRACING_PLATFORM)
198 pajeDefineVariableType(state, "LINK", state);
199 snprintf(state, 100, "p%s", category);
200 if (IS_TRACING_PLATFORM)
201 pajeDefineVariableType(state, "HOST", state);
203 val_one = xbt_strdup("1");
204 xbt_dict_set(created_categories, category, &val_one, xbt_free);
208 void TRACE_declare_mark(const char *mark_type)
215 pajeDefineEventType(mark_type, "0", mark_type);
218 void TRACE_mark(const char *mark_type, const char *mark_value)
222 if (!mark_type || !mark_value)
225 pajeNewEvent(MSG_get_clock(), mark_type, "0", mark_value);
228 #endif /* HAVE_TRACING */