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,
30 xbt_dynar_free_voidp);
32 xbt_dynar_t array = xbt_dict_get(platform_variables, resource);
36 xbt_dynar_foreach(array, i, cat) {
37 if (strcmp(variable, cat) == 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);
57 static void __TRACE_A_event(smx_action_t action, double now, double delta,
58 const char *variable, const char *resource,
62 snprintf(valuestr, 100, "%f", value);
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);
72 static void instr_event (double now, double delta, type_t variable, container_t resource, double value)
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);
80 * TRACE_surf_link_set_utilization: entry point from SimGrid
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,
87 //only trace link utilization if link is known by tracing mechanism
88 if (!knownContainerWithName(resource))
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);
101 //trace categorized utilization
102 if (TRACE_categorized()){
103 if (!surf_action->category)
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);
117 * TRACE_surf_host_set_utilization: entry point from SimGrid
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,
125 //only trace host utilization if host is known by tracing mechanism
126 if (!knownContainerWithName(resource))
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);
139 //trace categorized utilization
140 if (TRACE_categorized()){
141 if (!surf_action->category)
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);
154 void TRACE_surf_resource_utilization_alloc()
156 platform_variables = xbt_dict_new();
159 void TRACE_surf_resource_utilization_release()
162 #endif /* HAVE_TRACING */