Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Continue to reorganize instr
[simgrid.git] / src / instr / instr_resource_utilization.cpp
1 /* Copyright (c) 2010-2017. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "src/instr/instr_private.hpp"
8 #include <set>
9 #include <string>
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_resource, instr, "tracing (un)-categorized resource utilization");
12
13 //to check if variables were previously set to 0, otherwise paje won't simulate them
14 static std::set<std::string> platform_variables;
15
16 static void instr_event(double now, double delta, simgrid::instr::VariableType* variable, container_t resource,
17                         double value)
18 {
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.
22    */
23
24   // create a key considering the resource and variable
25   std::string key = resource->getName() + variable->getName();
26
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);
31   }
32
33   variable->addEvent(now, resource, value);
34   variable->subEvent(now + delta, resource, value);
35 }
36
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)
39 {
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)
43     return;
44
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);
51   }
52
53   //trace categorized utilization
54   if (TRACE_categorized()){
55     if (not category)
56       return;
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);
63   }
64 }
65
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)
68 {
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)
72     return;
73
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);
80   }
81
82   //trace categorized utilization
83   if (TRACE_categorized()){
84     if (not category)
85       return;
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);
92   }
93 }