Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
56cfd6a0eba2b62fb58625b8906a23ab6dd2159e
[simgrid.git] / src / instr / 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 "simgrid_config.h"
8
9 #ifdef HAVE_TRACING
10
11 #include "instr/instr_private.h"
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_api, instr, "API");
14
15 xbt_dict_t defined_types;
16 xbt_dict_t created_categories;
17
18 extern xbt_dict_t hosts_types;
19 extern xbt_dict_t links_types;
20
21 void TRACE_category(const char *category)
22 {
23   TRACE_category_with_color (category, NULL);
24 }
25
26 void TRACE_category_with_color (const char *category, const char *color)
27 {
28   if (!TRACE_is_active())
29     return;
30
31   //check if category is already created
32   char *created = xbt_dict_get_or_null(created_categories, category);
33   if (created) return;
34   xbt_dict_set (created_categories, category, xbt_strdup("1"), xbt_free);
35
36   //define final_color
37   char final_color[INSTR_DEFAULT_STR_SIZE];
38   if (!color){
39     //generate a random color
40     double red = drand48();
41     double green = drand48();
42     double blue = drand48();
43     snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
44   }else{
45     snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
46   }
47
48   DEBUG2("CAT,declare %s, %s", category, final_color);
49
50 //FIXME
51 //  -  if (final) {
52 //  -    //for m_process_t
53 //  -    if (TRACE_msg_process_is_enabled())
54 //  -      pajeDefineContainerType("process", type, "process");
55 //  -    if (TRACE_msg_process_is_enabled())
56 //  -      pajeDefineStateType("process-state", "process", "process-state");
57 //  -
58 //  -    if (TRACE_msg_task_is_enabled())
59 //  -      pajeDefineContainerType("task", type, "task");
60 //  -    if (TRACE_msg_task_is_enabled())
61 //  -      pajeDefineStateType("task-state", "task", "task-state");
62 //  -  }
63
64   //define the type of this category on top of hosts and links
65   if (TRACE_categorized ()){
66     char new_type[INSTR_DEFAULT_STR_SIZE];
67     xbt_dict_cursor_t cursor = NULL;
68     char *type;
69     void *data;
70     xbt_dict_foreach(links_types, cursor, type, data) {
71       snprintf (new_type, INSTR_DEFAULT_STR_SIZE, "%s-%s", category, type);
72       pajeDefineVariableTypeWithColor(new_type, type, category, final_color);
73     }
74     cursor = NULL;
75     xbt_dict_foreach(hosts_types, cursor, type, data) {
76       snprintf (new_type, INSTR_DEFAULT_STR_SIZE, "%s-%s", category, type);
77       pajeDefineVariableTypeWithColor(new_type, type, category, final_color);
78     }
79   }
80 }
81
82 void TRACE_declare_mark(const char *mark_type)
83 {
84   if (!TRACE_is_active())
85     return;
86   if (!mark_type)
87     return;
88
89   DEBUG1("MARK,declare %s", mark_type);
90   pajeDefineEventType(mark_type, "0", mark_type);
91 }
92
93 void TRACE_mark(const char *mark_type, const char *mark_value)
94 {
95   if (!TRACE_is_active())
96     return;
97   if (!mark_type || !mark_value)
98     return;
99
100   DEBUG2("MARK %s %s", mark_type, mark_value);
101   pajeNewEvent(MSG_get_clock(), mark_type, "0", mark_value);
102 }
103
104 #endif /* HAVE_TRACING */