Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill all aspects related to masks in the tracing interface
[simgrid.git] / src / instr / interface.c
1 /* Copyright (c) 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "instr/private.h"
8
9
10 #ifdef HAVE_TRACING
11
12 XBT_LOG_NEW_DEFAULT_CATEGORY(tracing,"Tracing Interface");
13
14 static xbt_dict_t defined_types;
15 static xbt_dict_t created_categories;
16
17 int TRACE_start ()
18 {
19         FILE *file = NULL;
20   if (IS_TRACING) { /* what? trace is already active... ignore.. */
21         THROW0 (tracing_error, TRACE_ERROR_START,
22                 "TRACE_start called, but tracing is already active");
23     return 0;
24   }
25
26   char *filename = _TRACE_filename ();
27   file = fopen(filename, "w");
28   if (!file) {
29     THROW1 (tracing_error, TRACE_ERROR_START,
30                 "Tracefile %s could not be opened for writing.", filename);
31   } else {
32     TRACE_paje_start (file);
33   }
34   TRACE_paje_create_header();
35
36   /* define paje hierarchy for tracing */
37   pajeDefineContainerType("PLATFORM", "0", "platform");
38   pajeDefineContainerType("HOST", "PLATFORM", "HOST");
39   pajeDefineContainerType("LINK", "PLATFORM", "LINK");
40
41   if (IS_TRACING_PLATFORM){
42     pajeDefineVariableType ("power", "HOST", "power");
43     pajeDefineVariableType ("bandwidth", "LINK", "bandwidth");
44     pajeDefineVariableType ("latency", "LINK", "latency");
45   }
46
47   if (IS_TRACING_PROCESSES || IS_TRACING_VOLUME){
48     //processes grouped by host
49     pajeDefineContainerType("PROCESS", "HOST", "PROCESS");
50   }
51
52   if (IS_TRACING_PROCESSES){
53     pajeDefineStateType("category", "PROCESS", "category");
54     pajeDefineStateType("presence", "PROCESS", "presence");
55   }
56
57   if (IS_TRACING_VOLUME){
58     pajeDefineLinkType ("volume", "0", "PROCESS", "PROCESS", "volume");
59   }
60
61   if (IS_TRACING_TASKS){
62     //tasks grouped by host
63     pajeDefineContainerType("TASK", "HOST", "TASK");
64     pajeDefineStateType("category", "TASK", "category");
65     pajeDefineStateType("presence", "TASK", "presence");
66   }
67
68   /* creating the platform */
69   pajeCreateContainer(MSG_get_clock(), "platform", "PLATFORM", "0", "simgrid-platform");
70
71   /* other trace initialization */
72   defined_types = xbt_dict_new();
73   created_categories = xbt_dict_new();
74   __TRACE_msg_init();
75   __TRACE_surf_init();
76   __TRACE_msg_process_init ();
77
78   return 0;
79 }
80
81 int TRACE_end() {
82         FILE *file = NULL;
83   if (!IS_TRACING) return 1;
84   file = TRACE_paje_end();
85   fclose (file);
86   return 0;
87 }
88
89 int TRACE_category (const char *category)
90 {
91   static int first_time = 1;
92   if (!IS_TRACING) return 1;
93
94   if (first_time){
95           TRACE_define_type ("user_type", "0", 1);
96           first_time = 0;
97   }
98   return TRACE_create_category (category, "user_type", "0");
99 }
100
101 void TRACE_define_type (const char *type,
102                 const char *parent_type, int final) {
103         char *val_one = NULL;
104   if (!IS_TRACING) return;
105
106   //check if type is already defined
107   if (xbt_dict_get_or_null (defined_types, type)){
108     THROW1 (tracing_error, TRACE_ERROR_TYPE_ALREADY_DEFINED, "Type %s is already defined", type);
109   }
110   //check if parent_type is already defined
111   if (strcmp(parent_type, "0") && !xbt_dict_get_or_null (defined_types, parent_type)) {
112     THROW1 (tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, "Type (used as parent) %s is not defined", parent_type);
113   }
114
115   pajeDefineContainerType(type, parent_type, type);
116   if (final) {
117     //for m_process_t
118     if (IS_TRACING_PROCESSES) pajeDefineContainerType ("process", type, "process");
119     if (IS_TRACING_PROCESSES) pajeDefineStateType ("process-state", "process", "process-state");
120
121     if (IS_TRACING_TASKS) pajeDefineContainerType ("task", type, "task");
122     if (IS_TRACING_TASKS) pajeDefineStateType ("task-state", "task", "task-state");
123   }
124   val_one = xbt_strdup ("1");
125   xbt_dict_set (defined_types, type, &val_one, xbt_free);
126 }
127
128 int TRACE_create_category (const char *category,
129                 const char *type, const char *parent_category)
130 {
131   char state[100];
132   char *val_one = NULL;
133   if (!IS_TRACING) return 1;
134
135   //check if type is defined
136   if (!xbt_dict_get_or_null (defined_types, type)) {
137          THROW1 (tracing_error, TRACE_ERROR_TYPE_NOT_DEFINED, "Type %s is not defined", type);
138          return 1;
139   }
140   //check if parent_category exists
141   if (strcmp(parent_category, "0") && !xbt_dict_get_or_null (created_categories, parent_category)){
142      THROW1 (tracing_error, TRACE_ERROR_CATEGORY_NOT_DEFINED, "Category (used as parent) %s is not created", parent_category);
143      return 1;
144   }
145   //check if category is created
146   if (xbt_dict_get_or_null (created_categories, category)){
147      return 1;
148   }
149
150   pajeCreateContainer(MSG_get_clock(), category, type, parent_category, category);
151
152   /* for registering application categories on top of platform */
153
154   snprintf (state, 100, "b%s", category);
155   if (IS_TRACING_PLATFORM) pajeDefineVariableType (state, "LINK", state);
156   snprintf (state, 100, "p%s", category);
157   if (IS_TRACING_PLATFORM) pajeDefineVariableType (state, "HOST", state);
158
159   val_one = xbt_strdup ("1");
160   xbt_dict_set (created_categories, category, &val_one, xbt_free);
161   return 0;
162 }
163
164 void TRACE_declare_mark (const char *mark_type)
165 {
166   if (!IS_TRACING) return;
167   if (!mark_type) return;
168
169   pajeDefineEventType (mark_type, "0", mark_type);
170 }
171
172 void TRACE_mark (const char *mark_type, const char *mark_value)
173 {
174   if (!IS_TRACING) return;
175   if (!mark_type || !mark_value) return;
176
177   pajeNewEvent (MSG_get_clock(), mark_type, "0", mark_value);
178 }
179
180 #endif /* HAVE_TRACING */