Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'add_missing_comm_python_bindings' into 'master'
[simgrid.git] / src / instr / instr_resource_utilization.cpp
1 /* Copyright (c) 2010-2022. 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 "xbt/log.h"
9 #include <string>
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_resource, instr, "tracing (un)-categorized resource utilization");
12
13 namespace simgrid {
14 namespace instr {
15 void resource_set_utilization(const char* type, const char* name, const char* resource, const std::string& category,
16                               double value, double now, double delta)
17 {
18   // only trace resource utilization if resource is known by tracing mechanism
19   Container* container = Container::by_name_or_null(resource);
20   if (container == nullptr || value == 0.0)
21     return;
22
23   // trace uncategorized resource utilization
24   if (TRACE_uncategorized()){
25     XBT_VERB("UNCAT %s [%f - %f] %s %s %f", type, now, now + delta, resource, name, value);
26     container->get_variable(name)->instr_event(now, delta, resource, value);
27   }
28
29   // trace categorized resource utilization
30   if (TRACE_categorized() && not category.empty()) {
31     std::string category_type = name[0] + category;
32     XBT_DEBUG("CAT %s [%f - %f] %s %s %f", type, now, now + delta, resource, category_type.c_str(), value);
33     container->get_variable(name)->instr_event(now, delta, resource, value);
34   }
35 }
36 } // namespace instr
37 } // namespace simgrid