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.hpp"
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::set<std::string> platform_variables;
16 static void instr_event(double now, double delta, simgrid::instr::VariableType* variable, container_t resource,
19 /* To trace resource utilization, we use AddEvent and SubEvent only. This implies to add a SetEvent first to set the
20 * initial value of all variables for subsequent adds/subs. If we don't do so, the first AddEvent would be added to a
21 * non-determined value, hence causing analysis problems.
24 // create a key considering the resource and variable
25 std::string key = resource->getName() + variable->getName();
27 // check if key exists: if it doesn't, set the variable to zero and mark this in the global map.
28 if (platform_variables.find(key) == platform_variables.end()) {
29 variable->setEvent(now, 0);
30 platform_variables.insert(key);
33 variable->addEvent(now, value);
34 variable->subEvent(now + delta, value);
37 /* TRACE_surf_link_set_utilization: entry point from SimGrid */
38 void TRACE_surf_link_set_utilization(const char *resource, const char *category, double value, double now, double delta)
40 //only trace link utilization if link is known by tracing mechanism
41 container_t container = simgrid::instr::Container::byNameOrNull(resource);
42 if (not container || not value)
45 //trace uncategorized link utilization
46 if (TRACE_uncategorized()){
47 XBT_DEBUG("UNCAT LINK [%f - %f] %s bandwidth_used %f", now, now + delta, resource, value);
48 simgrid::instr::VariableType* variable = container->getVariable("bandwidth_used");
49 instr_event(now, delta, variable, container, value);
52 //trace categorized utilization
53 if (TRACE_categorized()){
56 //variable of this category starts by 'b', because we have a link here
57 std::string category_type = std::string("b") + category;
58 XBT_DEBUG("CAT LINK [%f - %f] %s %s %f", now, now + delta, resource, category_type.c_str(), value);
59 simgrid::instr::VariableType* variable = container->getVariable(category_type);
60 instr_event(now, delta, variable, container, value);
64 /* TRACE_surf_host_set_utilization: entry point from SimGrid */
65 void TRACE_surf_host_set_utilization(const char *resource, const char *category, double value, double now, double delta)
67 //only trace host utilization if host is known by tracing mechanism
68 container_t container = simgrid::instr::Container::byNameOrNull(resource);
69 if (not container || not value)
72 //trace uncategorized host utilization
73 if (TRACE_uncategorized()){
74 XBT_DEBUG("UNCAT HOST [%f - %f] %s power_used %f", now, now+delta, resource, value);
75 simgrid::instr::VariableType* variable = container->getVariable("power_used");
76 instr_event(now, delta, variable, container, value);
79 //trace categorized utilization
80 if (TRACE_categorized()){
83 //variable of this category starts by 'p', because we have a host here
84 std::string category_type = std::string("p") + category;
85 XBT_DEBUG("CAT HOST [%f - %f] %s %s %f", now, now + delta, resource, category_type.c_str(), value);
86 simgrid::instr::VariableType* variable = container->getVariable(category_type);
87 instr_event(now, delta, variable, container, value);