Logo AND Algorithmique Numérique Distribuée

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