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) {
40 if (IS_TRACING) { /* what? trace is already active... ignore.. */
41 THROW0 (tracing_error, TRACE_ERROR_START,
42 "TRACE_start called, but tracing is already active");
47 if (!(mask&TRACE_PLATFORM ||
51 THROW0 (tracing_error, TRACE_ERROR_MASK,
52 "unknown tracing mask");
55 FILE *file = fopen(filename, "w");
57 THROW1 (tracing_error, TRACE_ERROR_START,
58 "Tracefile %s could not be opened for writing.", filename);
60 TRACE_paje_start (file);
62 TRACE_paje_create_header();
64 /* setting the mask */
67 /* define paje hierarchy for tracing */
68 pajeDefineContainerType("PLATFORM", "0", "platform");
69 pajeDefineContainerType("HOST", "PLATFORM", "HOST");
70 pajeDefineContainerType("LINK", "PLATFORM", "LINK");
72 if (IS_TRACING_PLATFORM){
73 pajeDefineVariableType ("power", "HOST", "power");
74 pajeDefineVariableType ("bandwidth", "LINK", "bandwidth");
75 pajeDefineVariableType ("latency", "LINK", "latency");
78 if (IS_TRACING_PROCESSES || IS_TRACING_VOLUME){
79 //processes grouped by host
80 pajeDefineContainerType("PROCESS", "HOST", "PROCESS");
83 if (IS_TRACING_PROCESSES){
84 pajeDefineStateType("category", "PROCESS", "category");
85 pajeDefineStateType("presence", "PROCESS", "presence");
88 if (IS_TRACING_VOLUME){
89 pajeDefineLinkType ("volume", "0", "PROCESS", "PROCESS", "volume");
92 if (IS_TRACING_TASKS){
93 //tasks grouped by host
94 pajeDefineContainerType("TASK", "HOST", "TASK");
95 pajeDefineStateType("category", "TASK", "category");
96 pajeDefineStateType("presence", "TASK", "presence");
99 /* creating the platform */
100 pajeCreateContainer(MSG_get_clock(), "platform", "PLATFORM", "0", "simgrid-platform");
102 /* other trace initialization */
103 defined_types = xbt_dict_new();
104 created_categories = xbt_dict_new();
107 __TRACE_msg_process_init ();
113 if (!IS_TRACING) return 1;
114 FILE *file = TRACE_paje_end();
119 int TRACE_category (const char *category)
121 if (!IS_TRACING) return 1;
122 static int first_time = 1;
124 TRACE_define_type ("user_type", "0", 1);
127 return TRACE_create_category (category, "user_type", "0");
130 void TRACE_define_type (const char *type,
131 const char *parent_type, int final) {
132 if (!IS_TRACING) return;
134 //check if type is already defined
135 if (xbt_dict_get_or_null (defined_types, type)){
136 THROW1 (tracing_error, TRACE_ERROR_TYPE_ALREADY_DEFINED, "Type %s is already defined", type);
138 //check if parent_type is already defined
139 if (strcmp(parent_type, "0") && !xbt_dict_get_or_null (defined_types, parent_type)) {
140 THROW1 (tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, "Type (used as parent) %s is not defined", parent_type);
143 pajeDefineContainerType(type, parent_type, type);
146 if (IS_TRACING_PROCESSES) pajeDefineContainerType ("process", type, "process");
147 if (IS_TRACING_PROCESSES) pajeDefineStateType ("process-state", "process", "process-state");
149 if (IS_TRACING_TASKS) pajeDefineContainerType ("task", type, "task");
150 if (IS_TRACING_TASKS) pajeDefineStateType ("task-state", "task", "task-state");
152 xbt_dict_set (defined_types, type, xbt_strdup("1"), xbt_free);
155 int TRACE_create_category (const char *category,
156 const char *type, const char *parent_category)
158 if (!IS_TRACING) return 1;
160 //check if type is defined
161 if (!xbt_dict_get_or_null (defined_types, type)) {
162 THROW1 (tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, "Type %s is not defined", type);
165 //check if parent_category exists
166 if (strcmp(parent_category, "0") && !xbt_dict_get_or_null (created_categories, parent_category)){
167 THROW1 (tracing_error, TRACE_ERROR_CATEGORY_NOT_DEFINED, "Category (used as parent) %s is not created", parent_category);
170 //check if category is created
171 if (xbt_dict_get_or_null (created_categories, category)){
175 pajeCreateContainer(MSG_get_clock(), category, type, parent_category, category);
177 /* for registering application categories on top of platform */
179 snprintf (state, 100, "b%s", category);
180 if (IS_TRACING_PLATFORM) pajeDefineVariableType (state, "LINK", state);
181 snprintf (state, 100, "p%s", category);
182 if (IS_TRACING_PLATFORM) pajeDefineVariableType (state, "HOST", state);
184 xbt_dict_set (created_categories, category, xbt_strdup("1"), xbt_free);
188 void TRACE_set_mask (int mask)
190 if (mask != TRACE_PLATFORM){
197 #endif /* HAVE_TRACING */