forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVitals.h
50 lines (39 loc) · 1.08 KB
/
Vitals.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once
#include <cstring>
#include <iostream>
#include <sstream>
#include <unordered_map>
namespace at {
namespace vitals {
bool torchVitalEnabled();
struct TorchVitalAttr {
// always initialized to empty
std::string value = "";
template <typename T>
TorchVitalAttr& operator<<(const T& t) {
if (torchVitalEnabled()) {
std::stringstream ss;
ss << t;
value += ss.str();
}
return *this;
}
};
struct TorchVital {
std::string name;
std::unordered_map<std::string, TorchVitalAttr> attrs;
explicit TorchVital(std::string n) : name(std::move(n)) {}
TorchVital() = delete;
TorchVitalAttr& create(const std::string& attr);
~TorchVital() {
for (const auto& m : attrs) {
std::cout << "[TORCH_VITAL] " << name << "." << m.first << "\t\t "
<< m.second.value << "\n";
}
}
};
} // namespace at
} // namespace vitals
#define TORCH_VITAL_DECLARE(name) extern TorchVital TorchVital_##name;
#define TORCH_VITAL_DEFINE(name) TorchVital TorchVital_##name(#name);
#define TORCH_VITAL(name, attr) TorchVital_##name.create(#attr)