Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename routing_component to as, since that's just an AS at the end of the day
[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   //only trace link utilization if link is known by tracing mechanism
88   if (!knownContainerWithName(resource))
89     return;
90   if (!value)
91     return;
92
93   //trace uncategorized link utilization
94   if (TRACE_uncategorized()){
95     XBT_DEBUG("UNCAT LINK [%f - %f] %s bandwidth_used %f", now, now+delta, resource, value);
96     container_t container = getContainerByName (resource);
97     type_t type = getVariableType("bandwidth_used", NULL, container->type);
98     instr_event (now, delta, type, container, value);
99   }
100
101   //trace categorized utilization
102   if (TRACE_categorized()){
103     if (!surf_action->category)
104       return;
105     //variable of this category starts by 'b', because we have a link here
106     char category_type[INSTR_DEFAULT_STR_SIZE];
107     snprintf (category_type, INSTR_DEFAULT_STR_SIZE, "b%s", surf_action->category);
108     XBT_DEBUG("CAT LINK [%f - %f] %s %s %f", now, now+delta, resource, category_type, value);
109     container_t container = getContainerByName (resource);
110     type_t type = getVariableType(category_type, NULL, container->type);
111     instr_event (now, delta, type, container, value);
112   }
113   return;
114 }
115
116 /*
117  * TRACE_surf_host_set_utilization: entry point from SimGrid
118  */
119 void TRACE_surf_host_set_utilization(const char *resource,
120                                      smx_action_t smx_action,
121                                      surf_action_t surf_action,
122                                      double value, double now,
123                                      double delta)
124 {
125   //only trace host utilization if host is known by tracing mechanism
126   if (!knownContainerWithName(resource))
127     return;
128   if (!value)
129     return;
130
131   //trace uncategorized host utilization
132   if (TRACE_uncategorized()){
133     XBT_DEBUG("UNCAT HOST [%f - %f] %s power_used %f", now, now+delta, resource, value);
134     container_t container = getContainerByName (resource);
135     type_t type = getVariableType("power_used", NULL, container->type);
136     instr_event (now, delta, type, container, value);
137   }
138
139   //trace categorized utilization
140   if (TRACE_categorized()){
141     if (!surf_action->category)
142       return;
143     //variable of this category starts by 'p', because we have a host here
144     char category_type[INSTR_DEFAULT_STR_SIZE];
145     snprintf (category_type, INSTR_DEFAULT_STR_SIZE, "p%s", surf_action->category);
146     XBT_DEBUG("CAT HOST [%f - %f] %s %s %f", now, now+delta, resource, category_type, value);
147     container_t container = getContainerByName (resource);
148     type_t type = getVariableType(category_type, NULL, container->type);
149     instr_event (now, delta, type, container, value);
150   }
151   return;
152 }
153
154 void TRACE_surf_resource_utilization_alloc()
155 {
156   platform_variables = xbt_dict_new();
157 }
158
159 void TRACE_surf_resource_utilization_release()
160 {
161 }
162 #endif /* HAVE_TRACING */