Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use SG_{BEGIN,END}_DECL() for what it's designed to serve.
[simgrid.git] / src / instr / instr_private.h
1 /* Copyright (c) 2010-2013. 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 #ifndef INSTR_PRIVATE_H_
8 #define INSTR_PRIVATE_H_
9
10 #include "instr/instr.h"
11 #include "instr/instr_interface.h"
12 #include "internal_config.h"
13 #include "simgrid_config.h"
14
15 #ifdef HAVE_TRACING
16
17 SG_BEGIN_DECL()
18
19 /* Need to define function drand48 for Windows */
20 #ifdef _WIN32
21 #  define drand48() (rand()/(RAND_MAX + 1.0))
22 #endif
23
24 #define INSTR_DEFAULT_STR_SIZE 500
25
26 #include "xbt/graph.h"
27 #include "xbt/dict.h"
28 #include "simgrid/platf.h"
29
30 typedef enum {
31   PAJE_DefineContainerType,
32   PAJE_DefineVariableType,
33   PAJE_DefineStateType,
34   PAJE_DefineEventType,
35   PAJE_DefineLinkType,
36   PAJE_DefineEntityValue,
37   PAJE_CreateContainer,
38   PAJE_DestroyContainer,
39   PAJE_SetVariable,
40   PAJE_AddVariable,
41   PAJE_SubVariable,
42   PAJE_SetState,
43   PAJE_PushState,
44   PAJE_PopState,
45   PAJE_ResetState,
46   PAJE_StartLink,
47   PAJE_EndLink,
48   PAJE_NewEvent
49 } e_event_type;
50
51 typedef enum {
52   TYPE_VARIABLE,
53   TYPE_LINK,
54   TYPE_CONTAINER,
55   TYPE_STATE,
56   TYPE_EVENT
57 } e_entity_types;
58
59 typedef struct s_type *type_t;
60 typedef struct s_type {
61   char *id;
62   char *name;
63   char *color;
64   e_entity_types kind;
65   struct s_type *father;
66   xbt_dict_t children;
67   xbt_dict_t values; //valid for all types except variable and container
68 }s_type_t;
69
70 typedef struct s_val *val_t;
71 typedef struct s_val {
72   char *id;
73   char *name;
74   char *color;
75   type_t father;
76 }s_val_t;
77
78 typedef enum {
79   INSTR_HOST,
80   INSTR_LINK,
81   INSTR_ROUTER,
82   INSTR_AS,
83   INSTR_SMPI,
84   INSTR_MSG_VM,
85   INSTR_MSG_PROCESS,
86   INSTR_MSG_TASK
87 } e_container_types;
88
89 typedef struct s_container *container_t;
90 typedef struct s_container {
91   sg_routing_edge_t net_elm;
92   char *name;     /* Unique name of this container */
93   char *id;       /* Unique id of this container */
94   type_t type;    /* Type of this container */
95   int level;      /* Level in the hierarchy, root level is 0 */
96   e_container_types kind; /* This container is of what kind */
97   struct s_container *father;
98   xbt_dict_t children;
99 }s_container_t;
100
101 typedef struct paje_event *paje_event_t;
102 typedef struct paje_event {
103   double timestamp;
104   e_event_type event_type;
105   void (*print) (paje_event_t event);
106   void (*free) (paje_event_t event);
107   void *data;
108 } s_paje_event_t;
109
110 typedef struct s_defineContainerType *defineContainerType_t;
111 typedef struct s_defineContainerType {
112   type_t type;
113 }s_defineContainerType_t;
114
115 typedef struct s_defineVariableType *defineVariableType_t;
116 typedef struct s_defineVariableType {
117   type_t type;
118 }s_defineVariableType_t;
119
120 typedef struct s_defineStateType *defineStateType_t;
121 typedef struct s_defineStateType {
122   type_t type;
123 }s_defineStateType_t;
124
125 typedef struct s_defineEventType *defineEventType_t;
126 typedef struct s_defineEventType {
127   type_t type;
128 }s_defineEventType_t;
129
130 typedef struct s_defineLinkType *defineLinkType_t;
131 typedef struct s_defineLinkType {
132   type_t type;
133   type_t source;
134   type_t dest;
135 }s_defineLinkType_t;
136
137 typedef struct s_defineEntityValue *defineEntityValue_t;
138 typedef struct s_defineEntityValue {
139   val_t value;
140 }s_defineEntityValue_t;
141
142 typedef struct s_createContainer *createContainer_t;
143 typedef struct s_createContainer {
144   container_t container;
145 }s_createContainer_t;
146
147 typedef struct s_destroyContainer *destroyContainer_t;
148 typedef struct s_destroyContainer {
149   container_t container;
150 }s_destroyContainer_t;
151
152 typedef struct s_setVariable *setVariable_t;
153 typedef struct s_setVariable {
154   container_t container;
155   type_t type;
156   double value;
157 }s_setVariable_t;
158
159 typedef struct s_addVariable *addVariable_t;
160 typedef struct s_addVariable {
161   container_t container;
162   type_t type;
163   double value;
164 }s_addVariable_t;
165
166 typedef struct s_subVariable *subVariable_t;
167 typedef struct s_subVariable {
168   container_t container;
169   type_t type;
170   double value;
171 }s_subVariable_t;
172
173 typedef struct s_setState *setState_t;
174 typedef struct s_setState {
175   container_t container;
176   type_t type;
177   val_t value;
178 }s_setState_t;
179
180 typedef struct s_pushState *pushState_t;
181 typedef struct s_pushState {
182   container_t container;
183   type_t type;
184   val_t value;
185   int size;
186   void* extra;
187 }s_pushState_t;
188
189 typedef struct s_popState *popState_t;
190 typedef struct s_popState {
191   container_t container;
192   type_t type;
193   xbt_dynar_t extra;
194 }s_popState_t;
195
196 typedef struct s_resetState *resetState_t;
197 typedef struct s_resetState {
198   container_t container;
199   type_t type;
200 }s_resetState_t;
201
202 typedef struct s_startLink *startLink_t;
203 typedef struct s_startLink {
204   container_t container;
205   type_t type;
206   container_t sourceContainer;
207   char *value;
208   char *key;
209   int size;
210 }s_startLink_t;
211
212 typedef struct s_endLink *endLink_t;
213 typedef struct s_endLink {
214   container_t container;
215   type_t type;
216   container_t destContainer;
217   char *value;
218   char *key;
219 }s_endLink_t;
220
221 typedef struct s_newEvent *newEvent_t;
222 typedef struct s_newEvent {
223   container_t container;
224   type_t type;
225   val_t value;
226 }s_newEvent_t;
227
228 extern xbt_dict_t created_categories;
229 extern xbt_dict_t declared_marks;
230 extern xbt_dict_t user_host_variables;
231 extern xbt_dict_t user_vm_variables;
232 extern xbt_dict_t user_link_variables;
233 extern double TRACE_last_timestamp_to_dump;
234
235 /* instr_paje_header.c */
236 void TRACE_header(int basic, int size);
237
238 /* from paje.c */
239 void TRACE_init(void);
240 void TRACE_finalize(void);
241 void TRACE_paje_init(void);
242 void TRACE_paje_start(void);
243 void TRACE_paje_end(void);
244 void TRACE_paje_dump_buffer (int force);
245 XBT_PUBLIC(void) new_pajeDefineContainerType(type_t type);
246 XBT_PUBLIC(void) new_pajeDefineVariableType(type_t type);
247 XBT_PUBLIC(void) new_pajeDefineStateType(type_t type);
248 XBT_PUBLIC(void) new_pajeDefineEventType(type_t type);
249 XBT_PUBLIC(void) new_pajeDefineLinkType(type_t type, type_t source, type_t dest);
250 XBT_PUBLIC(void) new_pajeDefineEntityValue (val_t type);
251 XBT_PUBLIC(void) new_pajeCreateContainer (container_t container);
252 XBT_PUBLIC(void) new_pajeDestroyContainer (container_t container);
253 XBT_PUBLIC(void) new_pajeSetVariable (double timestamp, container_t container, type_t type, double value);
254 XBT_PUBLIC(void) new_pajeAddVariable (double timestamp, container_t container, type_t type, double value);
255 XBT_PUBLIC(void) new_pajeSubVariable (double timestamp, container_t container, type_t type, double value);
256 XBT_PUBLIC(void) new_pajeSetState (double timestamp, container_t container, type_t type, val_t value);
257 XBT_PUBLIC(void) new_pajePushState (double timestamp, container_t container, type_t type, val_t value);
258 XBT_PUBLIC(void) new_pajePushStateWithExtra (double timestamp, container_t container, type_t type, val_t value, void* extra);
259 XBT_PUBLIC(void) new_pajePopState (double timestamp, container_t container, type_t type);
260 XBT_PUBLIC(void) new_pajeResetState (double timestamp, container_t container, type_t type);
261 XBT_PUBLIC(void) new_pajeStartLink (double timestamp, container_t container, type_t type, container_t sourceContainer, const char *value, const char *key);
262 XBT_PUBLIC(void) new_pajeStartLinkWithSize (double timestamp, container_t container, type_t type, container_t sourceContainer, const char *value, const char *key, int size);
263 XBT_PUBLIC(void) new_pajeEndLink (double timestamp, container_t container, type_t type, container_t destContainer, const char *value, const char *key);
264 XBT_PUBLIC(void) new_pajeNewEvent (double timestamp, container_t container, type_t type, val_t value);
265
266 //for tracing gtnets
267 void TRACE_surf_gtnets_communicate(void *action, void *src, void *dst);
268
269 /* from instr_config.c */
270 int TRACE_needs_platform (void);
271 int TRACE_is_enabled(void);
272 int TRACE_platform(void);
273 int TRACE_platform_topology(void);
274 int TRACE_is_configured(void);
275 int TRACE_categorized (void);
276 int TRACE_uncategorized (void);
277 int TRACE_msg_process_is_enabled(void);
278 int TRACE_msg_vm_is_enabled(void);
279 int TRACE_buffer (void);
280 int TRACE_disable_link(void);
281 int TRACE_disable_power(void);
282 int TRACE_onelink_only (void);
283 int TRACE_disable_destroy (void);
284 int TRACE_basic (void);
285 int TRACE_display_sizes (void);
286 char *TRACE_get_comment (void);
287 char *TRACE_get_comment_file (void);
288 char *TRACE_get_filename(void);
289 char *TRACE_get_viva_uncat_conf (void);
290 char *TRACE_get_viva_cat_conf (void);
291 void TRACE_generate_viva_uncat_conf (void);
292 void TRACE_generate_viva_cat_conf (void);
293 void instr_pause_tracing (void);
294 void instr_resume_tracing (void);
295
296 /* Public functions used in SMPI */
297 XBT_PUBLIC(int) TRACE_smpi_is_enabled(void);
298 XBT_PUBLIC(int) TRACE_smpi_is_grouped(void);
299 XBT_PUBLIC(int) TRACE_smpi_is_computing(void);
300 XBT_PUBLIC(int) TRACE_smpi_view_internals(void);
301
302 /* from resource_utilization.c */
303 void TRACE_surf_host_set_utilization(const char *resource,
304                                      const char *category,
305                                      double value,
306                                      double now,
307                                      double delta);
308 void TRACE_surf_link_set_utilization(const char *resource,
309                                      const char *category,
310                                      double value,
311                                      double now,
312                                      double delta);
313 void TRACE_surf_resource_utilization_alloc(void);
314
315 /* instr_paje.c */
316 extern xbt_dict_t trivaNodeTypes;
317 extern xbt_dict_t trivaEdgeTypes;
318 long long int instr_new_paje_id (void);
319 void PJ_container_alloc (void);
320 void PJ_container_release (void);
321 XBT_PUBLIC(container_t) PJ_container_new (const char *name, e_container_types kind, container_t father);
322 XBT_PUBLIC(container_t) PJ_container_get (const char *name);
323 XBT_PUBLIC(container_t) PJ_container_get_or_null (const char *name);
324 XBT_PUBLIC(container_t) PJ_container_get_root (void);
325 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
326 XBT_PUBLIC(void) PJ_container_free (container_t container);
327 XBT_PUBLIC(void) PJ_container_free_all (void);
328 XBT_PUBLIC(void) PJ_container_remove_from_parent (container_t container);
329
330 /* instr_paje_types.c */
331 void PJ_type_alloc (void);
332 void PJ_type_release (void);
333 XBT_PUBLIC(type_t)  PJ_type_get_root (void);
334 type_t PJ_type_container_new (const char *name, type_t father);
335 type_t PJ_type_event_new (const char *name, type_t father);
336 type_t PJ_type_variable_new (const char *name, const char *color, type_t father);
337 type_t PJ_type_link_new (const char *name, type_t father, type_t source, type_t dest);
338 type_t PJ_type_state_new (const char *name, type_t father);
339 XBT_PUBLIC(type_t)  PJ_type_get (const char *name, const type_t father);
340 XBT_PUBLIC(type_t)  PJ_type_get_or_null (const char *name, type_t father);
341 void PJ_type_free (type_t type);
342 void PJ_type_free_all (void);
343
344 /* instr_paje_values.c */
345 XBT_PUBLIC(val_t)  PJ_value_new (const char *name, const char *color, type_t father);
346 XBT_PUBLIC(val_t)  PJ_value_get_or_new (const char *name, const char *color, type_t father);
347 XBT_PUBLIC(val_t)  PJ_value_get (const char *name, const type_t father);
348 void PJ_value_free (val_t value);
349
350 void print_pajeDefineContainerType(paje_event_t event);
351 void print_pajeDefineVariableType(paje_event_t event);
352 void print_pajeDefineStateType(paje_event_t event);
353 void print_pajeDefineEventType(paje_event_t event);
354 void print_pajeDefineLinkType(paje_event_t event);
355 void print_pajeDefineEntityValue (paje_event_t event);
356 void print_pajeCreateContainer(paje_event_t event);
357 void print_pajeDestroyContainer(paje_event_t event);
358 void print_pajeSetVariable(paje_event_t event);
359 void print_pajeAddVariable(paje_event_t event);
360 void print_pajeSubVariable(paje_event_t event);
361 void print_pajeSetState(paje_event_t event);
362 void print_pajePushState(paje_event_t event);
363 void print_pajePopState(paje_event_t event);
364 void print_pajeResetState(paje_event_t event);
365 void print_pajeStartLink(paje_event_t event);
366 void print_pajeEndLink(paje_event_t event);
367 void print_pajeNewEvent (paje_event_t event);
368
369 void print_TIPushState(paje_event_t event);
370 void print_TICreateContainer(paje_event_t event);
371 void print_TIDestroyContainer(paje_event_t event);
372 void TRACE_TI_start(void);
373 void TRACE_TI_end(void);
374 void TRACE_TI_init(void);
375
376 void print_NULL (paje_event_t event);
377 void TRACE_paje_dump_buffer (int force);
378 void dump_comment_file (const char *filename);
379 void dump_comment (const char *comment);
380
381
382
383
384 typedef struct instr_trace_writer {
385   void (*print_DefineContainerType) (paje_event_t event);
386   void (*print_DefineVariableType)(paje_event_t event);
387   void (*print_DefineStateType)(paje_event_t event);
388   void (*print_DefineEventType)(paje_event_t event);
389   void (*print_DefineLinkType)(paje_event_t event);
390   void (*print_DefineEntityValue)(paje_event_t event);
391   void (*print_CreateContainer)(paje_event_t event);
392   void (*print_DestroyContainer)(paje_event_t event);
393   void (*print_SetVariable)(paje_event_t event);
394   void (*print_AddVariable)(paje_event_t event);
395   void (*print_SubVariable)(paje_event_t event);
396   void (*print_SetState)(paje_event_t event);
397   void (*print_PushState)(paje_event_t event);
398   void (*print_PopState)(paje_event_t event);
399   void (*print_ResetState)(paje_event_t event);
400   void (*print_StartLink)(paje_event_t event);
401   void (*print_EndLink)(paje_event_t event);
402   void (*print_NewEvent) (paje_event_t event);
403 } s_instr_trace_writer_t;
404
405
406
407 struct s_instr_extra_data;
408 typedef struct s_instr_extra_data *instr_extra_data;
409
410
411 typedef enum{
412   TRACING_INIT,
413   TRACING_FINALIZE,
414   TRACING_COMM_SIZE,
415   TRACING_COMM_SPLIT,
416   TRACING_COMM_DUP,
417   TRACING_SEND,
418   TRACING_ISEND,
419   TRACING_SSEND,
420   TRACING_ISSEND,
421   TRACING_RECV,
422   TRACING_IRECV,
423   TRACING_SENDRECV,
424   TRACING_WAIT,
425   TRACING_WAITALL,
426   TRACING_WAITANY,
427   TRACING_BARRIER,
428   TRACING_BCAST,
429   TRACING_REDUCE,
430   TRACING_ALLREDUCE,
431   TRACING_ALLTOALL,
432   TRACING_ALLTOALLV,
433   TRACING_GATHER,
434   TRACING_GATHERV,
435   TRACING_SCATTER,
436   TRACING_SCATTERV,
437   TRACING_ALLGATHER,
438   TRACING_ALLGATHERV,
439   TRACING_REDUCE_SCATTER,
440   TRACING_COMPUTING,
441   TRACING_SCAN,
442   TRACING_EXSCAN
443 } e_caller_type ;
444
445
446
447 typedef struct s_instr_extra_data {
448   e_caller_type type;
449   int send_size;
450   int recv_size;
451   double comp_size;
452   int src;
453   int dst;
454   int root;
455   const char* datatype1;
456   const char* datatype2;
457   int * sendcounts;
458   int * recvcounts;
459   int num_processes;
460 } s_instr_extra_data_t;
461
462 SG_END_DECL()
463
464 #endif /* HAVE_TRACING */
465
466 #ifdef HAVE_JEDULE
467 #include "instr/jedule/jedule_sd_binding.h"
468 #endif
469
470 #endif /* INSTR_PRIVATE_H_ */