Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] tracing a 0 instead of 0.000000 in trace file timestamps
[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 created_categories;
16
17 void TRACE_category(const char *category)
18 {
19   TRACE_category_with_color (category, NULL);
20 }
21
22 void TRACE_category_with_color (const char *category, const char *color)
23 {
24   if (!TRACE_is_active())
25     return;
26
27   xbt_assert1 (instr_platform_traced(),
28       "%s must be called after environment creation", __FUNCTION__);
29
30   //check if category is already created
31   char *created = xbt_dict_get_or_null(created_categories, category);
32   if (created) return;
33   xbt_dict_set (created_categories, category, xbt_strdup("1"), xbt_free);
34
35   //define final_color
36   char final_color[INSTR_DEFAULT_STR_SIZE];
37   if (!color){
38     //generate a random color
39     double red = drand48();
40     double green = drand48();
41     double blue = drand48();
42     snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%f %f %f", red, green, blue);
43   }else{
44     snprintf (final_color, INSTR_DEFAULT_STR_SIZE, "%s", color);
45   }
46
47   DEBUG2("CAT,declare %s, %s", category, final_color);
48
49 //FIXME
50 //  -  if (final) {
51 //  -    //for m_process_t
52 //  -    if (TRACE_msg_process_is_enabled())
53 //  -      pajeDefineContainerType("process", type, "process");
54 //  -    if (TRACE_msg_process_is_enabled())
55 //  -      pajeDefineStateType("process-state", "process", "process-state");
56 //  -
57 //  -    if (TRACE_msg_task_is_enabled())
58 //  -      pajeDefineContainerType("task", type, "task");
59 //  -    if (TRACE_msg_task_is_enabled())
60 //  -      pajeDefineStateType("task-state", "task", "task-state");
61 //  -  }
62
63   //define the type of this category on top of hosts and links
64   if (TRACE_categorized ()){
65     instr_new_user_variable_type (category, final_color);
66   }
67 }
68
69 void TRACE_declare_mark(const char *mark_type)
70 {
71   if (!TRACE_is_active())
72     return;
73   if (!mark_type)
74     return;
75
76   DEBUG1("MARK,declare %s", mark_type);
77   pajeDefineEventType(mark_type, "0", mark_type);
78 }
79
80 void TRACE_mark(const char *mark_type, const char *mark_value)
81 {
82   if (!TRACE_is_active())
83     return;
84   if (!mark_type || !mark_value)
85     return;
86
87   DEBUG2("MARK %s %s", mark_type, mark_value);
88   pajeNewEvent(MSG_get_clock(), mark_type, "0", mark_value);
89 }
90
91
92 void TRACE_user_link_variable(double time, const char *resource,
93                               const char *variable,
94                               double value, const char *what)
95 {
96   if (!TRACE_is_active())
97     return;
98
99   xbt_assert1 (instr_platform_traced(),
100       "%s must be called after environment creation", __FUNCTION__);
101
102   char valuestr[100];
103   snprintf(valuestr, 100, "%g", value);
104
105   if (strcmp(what, "declare") == 0) {
106     instr_new_user_link_variable_type (variable, NULL);
107   } else{
108     char *variable_id = instr_variable_type(variable, resource);
109     char *resource_id = instr_resource_type(resource);
110     if (strcmp(what, "set") == 0) {
111       pajeSetVariable(time, variable_id, resource_id, valuestr);
112     } else if (strcmp(what, "add") == 0) {
113       pajeAddVariable(time, variable_id, resource_id, valuestr);
114     } else if (strcmp(what, "sub") == 0) {
115       pajeSubVariable(time, variable_id, resource_id, valuestr);
116     }
117   }
118 }
119
120 void TRACE_user_host_variable(double time, const char *variable,
121                               double value, const char *what)
122 {
123   if (!TRACE_is_active())
124     return;
125
126   xbt_assert1 (instr_platform_traced(),
127       "%s must be called after environment creation", __FUNCTION__);
128
129   char valuestr[100];
130   snprintf(valuestr, 100, "%g", value);
131
132   if (strcmp(what, "declare") == 0) {
133     instr_new_user_host_variable_type (variable, NULL);
134   } else{
135     char *host_name = MSG_host_self()->name;
136     char *variable_id = instr_variable_type(variable, host_name);
137     char *resource_id = instr_resource_type(host_name);
138     if (strcmp(what, "set") == 0) {
139       pajeSetVariable(time, variable_id, resource_id, valuestr);
140     } else if (strcmp(what, "add") == 0) {
141       pajeAddVariable(time, variable_id, resource_id, valuestr);
142     } else if (strcmp(what, "sub") == 0) {
143       pajeSubVariable(time, variable_id, resource_id, valuestr);
144     }
145   }
146 }
147
148
149 #endif /* HAVE_TRACING */