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"
14 #include "instr/config.h"
19 XBT_LOG_NEW_DEFAULT_CATEGORY(tracing,"Tracing Surf");
21 extern xbt_dict_t created_containers; /* declared in general.c */
22 static xbt_dict_t defined_types;
23 static xbt_dict_t created_categories;
28 * \brief Initialization of tracing.
30 * Function to be called at first when tracing a simulation
32 * \param name of the file that will contain the traces
33 * \param mask to take into account during trace
34 * \return 1 if everything is ok, 0 otherwise
36 int TRACE_start_with_mask(const char *filename, int mask) {
37 if (IS_TRACING) { /* what? trace is already active... ignore.. */
41 FILE *file = fopen(filename, "w");
43 THROW1 (tracing_error, TRACE_ERROR_FILE_OPEN,
44 "Tracefile %s could not be opened for writing.", filename);
46 TRACE_paje_start (file);
48 TRACE_paje_create_header();
50 /* default trace is to trace only the platform */
53 //check if options are correct
54 if (IS_TRACING_TASKS){
55 if (!IS_TRACING_PROCESSES){
57 THROW0 (tracing_error, TRACE_ERROR_MASK,
58 "TRACE_PROCESS must be enabled if TRACE_TASK is used");
62 if (IS_TRACING_PROCESSES|IS_TRACING_TASKS){
63 if (!IS_TRACING_PLATFORM){
65 THROW0 (tracing_error, TRACE_ERROR_MASK,
66 "TRACE_PLATFORM must be enabled if TRACE_PROCESS or TRACE_TASK is used");
70 //defining platform hierarchy
71 if (IS_TRACING_PLATFORM) pajeDefineContainerType("PLATFORM", "0", "platform");
72 if (IS_TRACING_PLATFORM) pajeDefineContainerType("HOST", "PLATFORM", "HOST");
73 if (IS_TRACING_PLATFORM) pajeDefineVariableType ("power", "HOST", "power");
74 if (IS_TRACING_PLATFORM) pajeDefineContainerType("LINK", "PLATFORM", "LINK");
75 if (IS_TRACING_PLATFORM) pajeDefineVariableType ("bandwidth", "LINK", "bandwidth");
76 if (IS_TRACING_PLATFORM) pajeDefineVariableType ("latency", "LINK", "latency");
78 if (IS_TRACING_PROCESSES) pajeDefineContainerType("PROCESS", "HOST", "PROCESS");
79 if (IS_TRACING_PROCESSES) pajeDefineStateType("presence", "PROCESS", "presence");
81 if (IS_TRACING_PROCESSES){
82 if (IS_TRACING_TASKS) pajeDefineContainerType("TASK", "PROCESS", "TASK");
84 if (IS_TRACING_TASKS) pajeDefineContainerType("TASK", "HOST", "TASK");
87 if (IS_TRACING_PLATFORM) pajeCreateContainer(MSG_get_clock(), "platform", "PLATFORM", "0", "simgrid-platform");
89 created_containers = xbt_dict_new();
90 defined_types = xbt_dict_new();
91 created_categories = xbt_dict_new();
94 __TRACE_msg_process_init ();
100 if (!IS_TRACING) return 0;
101 __TRACE_surf_finalize();
102 FILE *file = TRACE_paje_end();
107 void TRACE_category (const char *category)
109 if (!IS_TRACING) return;
110 static int first_time = 1;
112 TRACE_define_type ("user_type", "0", 1);
115 TRACE_create_category (category, "user_type", "0");
118 void TRACE_define_type (const char *type,
119 const char *parent_type, int final) {
120 if (!IS_TRACING) return;
122 //check if type is already defined
123 if (xbt_dict_get_or_null (defined_types, type)){
124 THROW1 (tracing_error, TRACE_ERROR_TYPE_ALREADY_DEFINED, "Type %s is already defined", type);
126 //check if parent_type is already defined
127 if (strcmp(parent_type, "0") && !xbt_dict_get_or_null (defined_types, parent_type)) {
128 THROW1 (tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, "Type (used as parent) %s is not defined", parent_type);
131 pajeDefineContainerType(type, parent_type, type);
134 if (IS_TRACING_PROCESSES) pajeDefineContainerType ("process", type, "process");
135 if (IS_TRACING_PROCESSES) pajeDefineStateType ("process-state", "process", "process-state");
137 if (IS_TRACING_TASKS) pajeDefineContainerType ("task", type, "task");
138 if (IS_TRACING_TASKS) pajeDefineStateType ("task-state", "task", "task-state");
140 xbt_dict_set (defined_types, type, xbt_strdup("1"), xbt_free);
143 void TRACE_create_category (const char *category,
144 const char *type, const char *parent_category)
146 if (!IS_TRACING) return;
148 //check if type is defined
149 if (!xbt_dict_get_or_null (defined_types, type)) {
150 THROW1 (tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, "Type %s is not defined", type);
152 //check if parent_category exists
153 if (strcmp(parent_category, "0") && !xbt_dict_get_or_null (created_categories, parent_category)){
154 THROW1 (tracing_error, TRACE_ERROR_CATEGORY_NOT_DEFINED, "Category (used as parent) %s is not created", parent_category);
156 //check if category is created
157 if (xbt_dict_get_or_null (created_categories, category)){
158 THROW1 (tracing_error, TRACE_ERROR_CATEGORY_ALREADY_DEFINED, "Category %s is already created", type);
161 pajeCreateContainer(MSG_get_clock(), category, type, parent_category, category);
163 /* for registering application categories on top of platform */
165 snprintf (state, 100, "b%s", category);
166 if (IS_TRACING_PLATFORM) pajeDefineVariableType (state, "LINK", state);
167 snprintf (state, 100, "p%s", category);
168 if (IS_TRACING_PLATFORM) pajeDefineVariableType (state, "HOST", state);
170 xbt_dict_set (created_categories, category, xbt_strdup("1"), xbt_free);
173 void TRACE_set_mask (int mask)
178 #endif /* HAVE_TRACING */