4 * Created on: Nov 23, 2009
5 * Author: Lucas Schnorr
6 * License: This program is free software; you can redistribute
7 * it and/or modify it under the terms of the license
8 * (GNU LGPL) which comes with this package.
10 * Copyright (c) 2009 The SimGrid team.
13 #include "instr/private.h"
18 XBT_LOG_NEW_DEFAULT_CATEGORY(tracing,"Tracing Interface");
20 static xbt_dict_t defined_types;
21 static xbt_dict_t created_categories;
26 * \brief Simple initialization of tracing.
28 * \param filename of the file that will contain the traces
29 * \return 0 if everything is ok
31 int TRACE_start (const char *filename)
33 return TRACE_start_with_mask (filename, TRACE_PLATFORM);
37 * \brief Initialization of tracing.
39 * Function to be called at first when tracing a simulation
41 * \param name of the file that will contain the traces
42 * \param mask to take into account during trace
43 * \return 0 if everything is ok
45 int TRACE_start_with_mask(const char *filename, int mask) {
46 if (IS_TRACING) { /* what? trace is already active... ignore.. */
47 THROW0 (tracing_error, TRACE_ERROR_START,
48 "TRACE_start called, but tracing is already active");
53 if (!(mask&TRACE_PLATFORM ||
56 THROW0 (tracing_error, TRACE_ERROR_MASK,
57 "unknown tracing mask");
60 FILE *file = fopen(filename, "w");
62 THROW1 (tracing_error, TRACE_ERROR_START,
63 "Tracefile %s could not be opened for writing.", filename);
65 TRACE_paje_start (file);
67 TRACE_paje_create_header();
69 /* setting the mask */
72 /* define paje hierarchy for tracing */
73 pajeDefineContainerType("PLATFORM", "0", "platform");
74 pajeDefineContainerType("HOST", "PLATFORM", "HOST");
75 pajeDefineContainerType("LINK", "PLATFORM", "LINK");
77 if (IS_TRACING_PLATFORM){
78 pajeDefineVariableType ("power", "HOST", "power");
79 pajeDefineVariableType ("bandwidth", "LINK", "bandwidth");
80 pajeDefineVariableType ("latency", "LINK", "latency");
83 if (IS_TRACING_PROCESSES){
84 //processes grouped by host
85 pajeDefineContainerType("PROCESS", "HOST", "PROCESS");
86 pajeDefineStateType("category", "PROCESS", "category");
87 pajeDefineStateType("presence", "PROCESS", "presence");
90 if (IS_TRACING_TASKS){
91 //tasks grouped by host
92 pajeDefineContainerType("TASK", "HOST", "TASK");
93 pajeDefineStateType("category", "TASK", "category");
94 pajeDefineStateType("presence", "TASK", "presence");
97 /* creating the platform */
98 pajeCreateContainer(MSG_get_clock(), "platform", "PLATFORM", "0", "simgrid-platform");
100 /* other trace initialization */
101 defined_types = xbt_dict_new();
102 created_categories = xbt_dict_new();
105 __TRACE_msg_process_init ();
111 if (!IS_TRACING) return 1;
112 FILE *file = TRACE_paje_end();
117 int TRACE_category (const char *category)
119 if (!IS_TRACING) return 1;
120 static int first_time = 1;
122 TRACE_define_type ("user_type", "0", 1);
125 return TRACE_create_category (category, "user_type", "0");
128 void TRACE_define_type (const char *type,
129 const char *parent_type, int final) {
130 if (!IS_TRACING) return;
132 //check if type is already defined
133 if (xbt_dict_get_or_null (defined_types, type)){
134 THROW1 (tracing_error, TRACE_ERROR_TYPE_ALREADY_DEFINED, "Type %s is already defined", type);
136 //check if parent_type is already defined
137 if (strcmp(parent_type, "0") && !xbt_dict_get_or_null (defined_types, parent_type)) {
138 THROW1 (tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, "Type (used as parent) %s is not defined", parent_type);
141 pajeDefineContainerType(type, parent_type, type);
144 if (IS_TRACING_PROCESSES) pajeDefineContainerType ("process", type, "process");
145 if (IS_TRACING_PROCESSES) pajeDefineStateType ("process-state", "process", "process-state");
147 if (IS_TRACING_TASKS) pajeDefineContainerType ("task", type, "task");
148 if (IS_TRACING_TASKS) pajeDefineStateType ("task-state", "task", "task-state");
150 xbt_dict_set (defined_types, type, xbt_strdup("1"), xbt_free);
153 int TRACE_create_category (const char *category,
154 const char *type, const char *parent_category)
156 if (!IS_TRACING) return 1;
158 //check if type is defined
159 if (!xbt_dict_get_or_null (defined_types, type)) {
160 THROW1 (tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, "Type %s is not defined", type);
163 //check if parent_category exists
164 if (strcmp(parent_category, "0") && !xbt_dict_get_or_null (created_categories, parent_category)){
165 THROW1 (tracing_error, TRACE_ERROR_CATEGORY_NOT_DEFINED, "Category (used as parent) %s is not created", parent_category);
168 //check if category is created
169 if (xbt_dict_get_or_null (created_categories, category)){
173 pajeCreateContainer(MSG_get_clock(), category, type, parent_category, category);
175 /* for registering application categories on top of platform */
177 snprintf (state, 100, "b%s", category);
178 if (IS_TRACING_PLATFORM) pajeDefineVariableType (state, "LINK", state);
179 snprintf (state, 100, "p%s", category);
180 if (IS_TRACING_PLATFORM) pajeDefineVariableType (state, "HOST", state);
182 xbt_dict_set (created_categories, category, xbt_strdup("1"), xbt_free);
186 void TRACE_set_mask (int mask)
188 if (mask != TRACE_PLATFORM){
195 #endif /* HAVE_TRACING */