Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change interface for elements_father, and avoid to allocate a dynar.
[simgrid.git] / src / instr / instr_resource_utilization.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/instr_private.h"
8
9 #ifdef HAVE_TRACING
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_resource, instr, "tracing (un)-categorized resource utilization");
12
13 //to check if variables were previously set to 0, otherwise paje won't simulate them
14 static xbt_dict_t platform_variables;   /* host or link name -> array of categories */
15
16 //used by all methods
17 static void __TRACE_surf_check_variable_set_to_zero(double now,
18                                                     const char *variable,
19                                                     const char *resource)
20 {
21   /* check if we have to set it to 0 */
22   if (!xbt_dict_get_or_null(platform_variables, resource)) {
23     xbt_dynar_t array = xbt_dynar_new(sizeof(char *), xbt_free);
24     char *var_cpy = xbt_strdup(variable);
25     xbt_dynar_push(array, &var_cpy);
26     container_t container = getContainerByName (resource);
27     type_t type = getVariableType (variable, NULL, container->type);
28     new_pajeSetVariable (now, container, type, 0);
29     xbt_dict_set(platform_variables, resource, array,
30                  xbt_dynar_free_voidp);
31   } else {
32     xbt_dynar_t array = xbt_dict_get(platform_variables, resource);
33     unsigned int i;
34     char *cat;
35     int flag = 0;
36     xbt_dynar_foreach(array, i, cat) {
37       if (strcmp(variable, cat) == 0) {
38         flag = 1;
39       }
40     }
41     if (flag == 0) {
42       char *var_cpy = xbt_strdup(variable);
43       xbt_dynar_push(array, &var_cpy);
44       if (TRACE_categorized ()){
45         container_t container = getContainerByName (resource);
46         type_t type = getVariableType (variable, NULL, container->type);
47         new_pajeSetVariable (now, container, type, 0);
48       }
49     }
50   }
51   /* end of check */
52 }
53
54
55
56 /*
57 static void __TRACE_A_event(smx_action_t action, double now, double delta,
58                             const char *variable, const char *resource,
59                             double value)
60 {
61   char valuestr[100];
62   snprintf(valuestr, 100, "%f", value);
63
64   __TRACE_surf_check_variable_set_to_zero(now, variable, resource);
65   container_t container = getContainerByName (resource);
66   type_t type = getVariableType (variable, NULL, container->type);
67   new_pajeAddVariable(now, container, type, value);
68   new_pajeSubVariable(now + delta, container, type, value);
69 }
70 */
71
72 static void instr_event (double now, double delta, type_t variable, container_t resource, double value)
73 {
74   __TRACE_surf_check_variable_set_to_zero(now, variable->name, resource->name);
75   new_pajeAddVariable(now, resource, variable, value);
76   new_pajeSubVariable(now + delta, resource, variable, value);
77 }
78
79 /*
80  * TRACE_surf_link_set_utilization: entry point from SimGrid
81  */
82 void TRACE_surf_link_set_utilization(const char *resource, smx_action_t smx_action,
83                                      surf_action_t surf_action,
84                                      double value, double now,
85                                      double delta)
86 {
87   if (!TRACE_is_active())
88     return;
89   if (!value)
90     return;
91   //only trace link utilization if link is known by tracing mechanism
92   if (!knownContainerWithName(resource))
93     return;
94   if (!value)
95     return;
96
97   //trace uncategorized link utilization
98   if (TRACE_uncategorized()){
99     XBT_DEBUG("UNCAT LINK [%f - %f] %s bandwidth_used %f", now, now+delta, resource, value);
100     container_t container = getContainerByName (resource);
101     type_t type = getVariableType("bandwidth_used", NULL, container->type);
102     instr_event (now, delta, type, container, value);
103   }
104
105   //trace categorized utilization
106   if (TRACE_categorized()){
107     if (!surf_action->category)
108       return;
109     //variable of this category starts by 'b', because we have a link here
110     char category_type[INSTR_DEFAULT_STR_SIZE];
111     snprintf (category_type, INSTR_DEFAULT_STR_SIZE, "b%s", surf_action->category);
112     XBT_DEBUG("CAT LINK [%f - %f] %s %s %f", now, now+delta, resource, category_type, value);
113     container_t container = getContainerByName (resource);
114     type_t type = getVariableType(category_type, NULL, container->type);
115     instr_event (now, delta, type, container, value);
116   }
117   return;
118 }
119
120 /*
121  * TRACE_surf_host_set_utilization: entry point from SimGrid
122  */
123 void TRACE_surf_host_set_utilization(const char *resource,
124                                      smx_action_t smx_action,
125                                      surf_action_t surf_action,
126                                      double value, double now,
127                                      double delta)
128 {
129   if (!TRACE_is_active())
130     return;
131   //only trace host utilization if host is known by tracing mechanism
132   if (!knownContainerWithName(resource))
133     return;
134   if (!value)
135     return;
136
137   //trace uncategorized host utilization
138   if (TRACE_uncategorized()){
139     XBT_DEBUG("UNCAT HOST [%f - %f] %s power_used %f", now, now+delta, resource, value);
140     container_t container = getContainerByName (resource);
141     type_t type = getVariableType("power_used", NULL, container->type);
142     instr_event (now, delta, type, container, value);
143   }
144
145   //trace categorized utilization
146   if (TRACE_categorized()){
147     if (!surf_action->category)
148       return;
149     //variable of this category starts by 'p', because we have a host here
150     char category_type[INSTR_DEFAULT_STR_SIZE];
151     snprintf (category_type, INSTR_DEFAULT_STR_SIZE, "p%s", surf_action->category);
152     XBT_DEBUG("CAT HOST [%f - %f] %s %s %f", now, now+delta, resource, category_type, value);
153     container_t container = getContainerByName (resource);
154     type_t type = getVariableType(category_type, NULL, container->type);
155     instr_event (now, delta, type, container, value);
156   }
157   return;
158 }
159
160 void TRACE_surf_resource_utilization_alloc()
161 {
162   platform_variables = xbt_dict_new();
163 }
164
165 void TRACE_surf_resource_utilization_release()
166 {
167 }
168 #endif /* HAVE_TRACING */