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"
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;
16 static void instr_event(double now, double delta, simgrid::instr::Type* variable, container_t resource, double value)
18 /* To trace resource utilization, we use AddVariableEvent and SubVariableEvent only. This implies to add a
19 * SetVariableEvent first to set the initial value of all variables for subsequent adds/subs. If we don't do so,
20 * the first AddVariableEvent would be added to a non-determined value, hence causing analysis problems.
23 // create a key considering the resource and variable
24 std::string key = resource->getName() + variable->getName();
26 // check if key exists: if it doesn't, set the variable to zero and mark this in the global map.
27 if (platform_variables.find(key) == platform_variables.end()) {
28 new simgrid::instr::SetVariableEvent(now, resource, variable, 0);
29 platform_variables[key] = std::string("");
32 new simgrid::instr::AddVariableEvent(now, resource, variable, value);
33 new simgrid::instr::SubVariableEvent(now + delta, resource, variable, value);
36 /* TRACE_surf_link_set_utilization: entry point from SimGrid */
37 void TRACE_surf_link_set_utilization(const char *resource, const char *category, double value, double now, double delta)
39 //only trace link utilization if link is known by tracing mechanism
40 container_t container = simgrid::instr::Container::byNameOrNull(resource);
41 if (not container || not value)
44 //trace uncategorized link utilization
45 if (TRACE_uncategorized()){
46 XBT_DEBUG("UNCAT LINK [%f - %f] %s bandwidth_used %f", now, now + delta, resource, value);
47 simgrid::instr::Type* type = container->type_->byName("bandwidth_used");
48 instr_event (now, delta, type, container, value);
51 //trace categorized utilization
52 if (TRACE_categorized()){
55 //variable of this category starts by 'b', because we have a link here
56 std::string category_type = std::string("b") + category;
57 XBT_DEBUG("CAT LINK [%f - %f] %s %s %f", now, now + delta, resource, category_type.c_str(), value);
58 simgrid::instr::Type* type = container->type_->byName(category_type);
59 instr_event (now, delta, type, container, value);
63 /* TRACE_surf_host_set_utilization: entry point from SimGrid */
64 void TRACE_surf_host_set_utilization(const char *resource, const char *category, double value, double now, double delta)
66 //only trace host utilization if host is known by tracing mechanism
67 container_t container = simgrid::instr::Container::byNameOrNull(resource);
68 if (not container || not value)
71 //trace uncategorized host utilization
72 if (TRACE_uncategorized()){
73 XBT_DEBUG("UNCAT HOST [%f - %f] %s power_used %f", now, now+delta, resource, value);
74 simgrid::instr::Type* type = container->type_->byName("power_used");
75 instr_event (now, delta, type, container, value);
78 //trace categorized utilization
79 if (TRACE_categorized()){
82 //variable of this category starts by 'p', because we have a host here
83 std::string category_type = std::string("p") + category;
84 XBT_DEBUG("CAT HOST [%f - %f] %s %s %f", now, now + delta, resource, category_type.c_str(), value);
85 simgrid::instr::Type* type = container->type_->byName(category_type);
86 instr_event (now, delta, type, container, value);