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, resource, 0);
30 platform_variables.insert(key);
33 variable->addEvent(now, resource, value);
34 variable->subEvent(now + delta, resource, 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 =
49 static_cast<simgrid::instr::VariableType*>(container->type_->byName("bandwidth_used"));
50 instr_event(now, delta, variable, container, value);
53 //trace categorized utilization
54 if (TRACE_categorized()){
57 //variable of this category starts by 'b', because we have a link here
58 std::string category_type = std::string("b") + category;
59 XBT_DEBUG("CAT LINK [%f - %f] %s %s %f", now, now + delta, resource, category_type.c_str(), value);
60 simgrid::instr::VariableType* variable =
61 static_cast<simgrid::instr::VariableType*>(container->type_->byName(category_type));
62 instr_event(now, delta, variable, container, value);
66 /* TRACE_surf_host_set_utilization: entry point from SimGrid */
67 void TRACE_surf_host_set_utilization(const char *resource, const char *category, double value, double now, double delta)
69 //only trace host utilization if host is known by tracing mechanism
70 container_t container = simgrid::instr::Container::byNameOrNull(resource);
71 if (not container || not value)
74 //trace uncategorized host utilization
75 if (TRACE_uncategorized()){
76 XBT_DEBUG("UNCAT HOST [%f - %f] %s power_used %f", now, now+delta, resource, value);
77 simgrid::instr::VariableType* variable =
78 static_cast<simgrid::instr::VariableType*>(container->type_->byName("power_used"));
79 instr_event(now, delta, variable, container, value);
82 //trace categorized utilization
83 if (TRACE_categorized()){
86 //variable of this category starts by 'p', because we have a host here
87 std::string category_type = std::string("p") + category;
88 XBT_DEBUG("CAT HOST [%f - %f] %s %s %f", now, now + delta, resource, category_type.c_str(), value);
89 simgrid::instr::VariableType* variable =
90 static_cast<simgrid::instr::VariableType*>(container->type_->byName(category_type));
91 instr_event(now, delta, variable, container, value);