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 static void TRACE_surf_resource_set_utilization(const char* type, const char* name, const char* resource,
38 const char* category, double value, double now, double delta)
40 // only trace resource utilization if resource is known by tracing mechanism
41 container_t container = simgrid::instr::Container::byNameOrNull(resource);
42 if (not container || not value)
45 // trace uncategorized resource utilization
46 if (TRACE_uncategorized()){
47 XBT_DEBUG("UNCAT %s [%f - %f] %s %s %f", type, now, now + delta, resource, name, value);
48 simgrid::instr::VariableType* variable = container->getVariable(name);
49 instr_event(now, delta, variable, container, value);
52 // trace categorized resource utilization
53 if (TRACE_categorized()){
56 std::string category_type = name[0] + std::string(category);
57 XBT_DEBUG("CAT %s [%f - %f] %s %s %f", type, now, now + delta, resource, category_type.c_str(), value);
58 simgrid::instr::VariableType* variable = container->getVariable(category_type);
59 instr_event(now, delta, variable, container, value);
63 /* TRACE_surf_link_set_utilization: entry point from SimGrid */
64 void TRACE_surf_link_set_utilization(const char* resource, const char* category, double value, double now, double delta)
66 TRACE_surf_resource_set_utilization("LINK", "bandwidth_used", resource, category, value, now, delta);
69 /* TRACE_surf_host_set_utilization: entry point from SimGrid */
70 void TRACE_surf_host_set_utilization(const char* resource, const char* category, double value, double now, double delta)
72 TRACE_surf_resource_set_utilization("HOST", "power_used", resource, category, value, now, delta);