1 /* Copyright (c) 2010-2017. 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 "src/instr/instr_private.h"
9 #include <unordered_map>
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 std::unordered_map<std::string, std::string> platform_variables;
17 static void __TRACE_surf_check_variable_set_to_zero(double now, const char *variable, const char *resource)
19 /* To trace resource utilization, we use pajeAddVariable and pajeSubVariable only.
20 * The Paje simulator needs a pajeSetVariable in the first place so it knows the initial value of all variables for
21 * subsequent adds/subs. If we don't do so, the first pajeAddVariable is added to a non-determined value within
22 * the Paje simulator, causing analysis problems.
25 // create a key considering the resource and variable
26 std::string key = std::string(resource) + variable;
28 // check if key exists: if it doesn't, set the variable to zero and mark this in the dict
29 if (platform_variables.find(key) == platform_variables.end()) {
30 container_t container = PJ_container_get (resource);
31 simgrid::instr::Type* type = container->type_->getChild(variable);
32 new simgrid::instr::SetVariableEvent(now, container, type, 0);
33 platform_variables[key] = std::string("");
37 static void instr_event(double now, double delta, simgrid::instr::Type* variable, container_t resource, double value)
39 __TRACE_surf_check_variable_set_to_zero(now, variable->name_, resource->name_);
40 new simgrid::instr::AddVariableEvent(now, resource, variable, value);
41 new simgrid::instr::SubVariableEvent(now + delta, resource, variable, value);
44 /* TRACE_surf_link_set_utilization: entry point from SimGrid */
45 void TRACE_surf_link_set_utilization(const char *resource, const char *category, double value, double now, double delta)
47 //only trace link utilization if link is known by tracing mechanism
48 if (not PJ_container_get_or_null(resource))
53 //trace uncategorized link utilization
54 if (TRACE_uncategorized()){
55 XBT_DEBUG("UNCAT LINK [%f - %f] %s bandwidth_used %f", now, now+delta, resource, value);
56 container_t container = PJ_container_get (resource);
57 simgrid::instr::Type* type = container->type_->getChild("bandwidth_used");
58 instr_event (now, delta, type, container, value);
61 //trace categorized utilization
62 if (TRACE_categorized()){
65 //variable of this category starts by 'b', because we have a link here
66 char category_type[INSTR_DEFAULT_STR_SIZE];
67 snprintf (category_type, INSTR_DEFAULT_STR_SIZE, "b%s", category);
68 XBT_DEBUG("CAT LINK [%f - %f] %s %s %f", now, now+delta, resource, category_type, value);
69 container_t container = PJ_container_get (resource);
70 simgrid::instr::Type* type = container->type_->getChild(category_type);
71 instr_event (now, delta, type, container, value);
75 /* TRACE_surf_host_set_utilization: entry point from SimGrid */
76 void TRACE_surf_host_set_utilization(const char *resource, const char *category, double value, double now, double delta)
78 //only trace host utilization if host is known by tracing mechanism
79 container_t container = PJ_container_get_or_null(resource);
80 if (not container || not value)
83 //trace uncategorized host utilization
84 if (TRACE_uncategorized()){
85 XBT_DEBUG("UNCAT HOST [%f - %f] %s power_used %f", now, now+delta, resource, value);
86 simgrid::instr::Type* type = container->type_->getChild("power_used");
87 instr_event (now, delta, type, container, value);
90 //trace categorized utilization
91 if (TRACE_categorized()){
94 //variable of this category starts by 'p', because we have a host here
95 char category_type[INSTR_DEFAULT_STR_SIZE];
96 snprintf (category_type, INSTR_DEFAULT_STR_SIZE, "p%s", category);
97 XBT_DEBUG("CAT HOST [%f - %f] %s %s %f", now, now+delta, resource, category_type, value);
98 simgrid::instr::Type* type = container->type_->getChild(category_type);
99 instr_event (now, delta, type, container, value);