1 /* Copyright (c) 2010. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "instr/instr_private.h"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_resource, instr, "tracing (un)-categorized resource utilization");
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 */
17 static void __TRACE_surf_check_variable_set_to_zero(double now,
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);
31 xbt_dynar_t array = xbt_dict_get(platform_variables, resource);
35 xbt_dynar_foreach(array, i, cat) {
36 if (strcmp(variable, cat) == 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);
56 static void __TRACE_A_event(smx_action_t action, double now, double delta,
57 const char *variable, const char *resource,
61 snprintf(valuestr, 100, "%f", value);
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);
71 static void instr_event (double now, double delta, type_t variable, container_t resource, double value)
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);
79 * TRACE_surf_link_set_utilization: entry point from SimGrid
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,
86 //only trace link utilization if link is known by tracing mechanism
87 if (!knownContainerWithName(resource))
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);
100 //trace categorized utilization
101 if (TRACE_categorized()){
102 if (!surf_action->category)
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);
116 * TRACE_surf_host_set_utilization: entry point from SimGrid
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,
124 //only trace host utilization if host is known by tracing mechanism
125 if (!knownContainerWithName(resource))
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);
138 //trace categorized utilization
139 if (TRACE_categorized()){
140 if (!surf_action->category)
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);
153 void TRACE_surf_resource_utilization_alloc()
155 platform_variables = xbt_dict_new_homogeneous(xbt_dynar_free_voidp);
158 void TRACE_surf_resource_utilization_release()
161 #endif /* HAVE_TRACING */