Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use homogeneous dictionaries whenever possible.
[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, NULL);
30   } else {
31     xbt_dynar_t array = xbt_dict_get(platform_variables, resource);
32     unsigned int i;
33     char *cat;
34     int flag = 0;
35     xbt_dynar_foreach(array, i, cat) {
36       if (strcmp(variable, cat) == 0) {
37         flag = 1;
38       }
39     }
40     if (flag == 0) {
41       char *var_cpy = xbt_strdup(variable);
42       xbt_dynar_push(array, &var_cpy);
43       if (TRACE_categorized ()){
44         container_t container = getContainerByName (resource);
45         type_t type = getVariableType (variable, NULL, container->type);
46         new_pajeSetVariable (now, container, type, 0);
47       }
48     }
49   }
50   /* end of check */
51 }
52
53
54
55 /*
56 static void __TRACE_A_event(smx_action_t action, double now, double delta,
57                             const char *variable, const char *resource,
58                             double value)
59 {
60   char valuestr[100];
61   snprintf(valuestr, 100, "%f", value);
62
63   __TRACE_surf_check_variable_set_to_zero(now, variable, resource);
64   container_t container = getContainerByName (resource);
65   type_t type = getVariableType (variable, NULL, container->type);
66   new_pajeAddVariable(now, container, type, value);
67   new_pajeSubVariable(now + delta, container, type, value);
68 }
69 */
70
71 static void instr_event (double now, double delta, type_t variable, container_t resource, double value)
72 {
73   __TRACE_surf_check_variable_set_to_zero(now, variable->name, resource->name);
74   new_pajeAddVariable(now, resource, variable, value);
75   new_pajeSubVariable(now + delta, resource, variable, value);
76 }
77
78 /*
79  * TRACE_surf_link_set_utilization: entry point from SimGrid
80  */
81 void TRACE_surf_link_set_utilization(const char *resource, smx_action_t smx_action,
82                                      surf_action_t surf_action,
83                                      double value, double now,
84                                      double delta)
85 {
86   //only trace link utilization if link is known by tracing mechanism
87   if (!knownContainerWithName(resource))
88     return;
89   if (!value)
90     return;
91
92   //trace uncategorized link utilization
93   if (TRACE_uncategorized()){
94     XBT_DEBUG("UNCAT LINK [%f - %f] %s bandwidth_used %f", now, now+delta, resource, value);
95     container_t container = getContainerByName (resource);
96     type_t type = getVariableType("bandwidth_used", NULL, container->type);
97     instr_event (now, delta, type, container, value);
98   }
99
100   //trace categorized utilization
101   if (TRACE_categorized()){
102     if (!surf_action->category)
103       return;
104     //variable of this category starts by 'b', because we have a link here
105     char category_type[INSTR_DEFAULT_STR_SIZE];
106     snprintf (category_type, INSTR_DEFAULT_STR_SIZE, "b%s", surf_action->category);
107     XBT_DEBUG("CAT LINK [%f - %f] %s %s %f", now, now+delta, resource, category_type, value);
108     container_t container = getContainerByName (resource);
109     type_t type = getVariableType(category_type, NULL, container->type);
110     instr_event (now, delta, type, container, value);
111   }
112   return;
113 }
114
115 /*
116  * TRACE_surf_host_set_utilization: entry point from SimGrid
117  */
118 void TRACE_surf_host_set_utilization(const char *resource,
119                                      smx_action_t smx_action,
120                                      surf_action_t surf_action,
121                                      double value, double now,
122                                      double delta)
123 {
124   //only trace host utilization if host is known by tracing mechanism
125   if (!knownContainerWithName(resource))
126     return;
127   if (!value)
128     return;
129
130   //trace uncategorized host utilization
131   if (TRACE_uncategorized()){
132     XBT_DEBUG("UNCAT HOST [%f - %f] %s power_used %f", now, now+delta, resource, value);
133     container_t container = getContainerByName (resource);
134     type_t type = getVariableType("power_used", NULL, container->type);
135     instr_event (now, delta, type, container, value);
136   }
137
138   //trace categorized utilization
139   if (TRACE_categorized()){
140     if (!surf_action->category)
141       return;
142     //variable of this category starts by 'p', because we have a host here
143     char category_type[INSTR_DEFAULT_STR_SIZE];
144     snprintf (category_type, INSTR_DEFAULT_STR_SIZE, "p%s", surf_action->category);
145     XBT_DEBUG("CAT HOST [%f - %f] %s %s %f", now, now+delta, resource, category_type, value);
146     container_t container = getContainerByName (resource);
147     type_t type = getVariableType(category_type, NULL, container->type);
148     instr_event (now, delta, type, container, value);
149   }
150   return;
151 }
152
153 void TRACE_surf_resource_utilization_alloc()
154 {
155   platform_variables = xbt_dict_new_homogeneous(xbt_dynar_free_voidp);
156 }
157
158 void TRACE_surf_resource_utilization_release()
159 {
160 }
161 #endif /* HAVE_TRACING */