FreeTensor
Loading...
Searching...
No Matches
profile.h
Go to the documentation of this file.
1#ifndef FREE_TENSOR_PROFILE_H
2#define FREE_TENSOR_PROFILE_H
3
4#include <chrono>
5#include <fstream>
6#include <memory>
7
8namespace freetensor {
9
10#ifdef FT_DEBUG_PROFILE
11
12class Profile {
13 std::ofstream os_;
14
15 static std::unique_ptr<Profile> profile_;
16
17 public:
18 Profile();
19
20 void add(const std::string &name, const std::string &detail, double t);
21
22 static Profile &getInstance();
23};
24
25class ProfileGuard {
26 std::string name_, detail_;
27 std::chrono::time_point<std::chrono::high_resolution_clock> begin_;
28
29 public:
30 ProfileGuard(const std::string &name, const std::string &detail);
31 ~ProfileGuard();
32};
33
34#define DEBUG_PROFILE(name) \
35 ProfileGuard __profGuard(name, __FILE__ ":" + std::to_string(__LINE__))
36
37#define DEBUG_PROFILE_VERBOSE(name, detail) \
38 ProfileGuard __profGuard(name, __FILE__ ":" + std::to_string(__LINE__) + \
39 ": " + detail)
40
41#else // FT_DEBUG_PROFILE
42
43#define DEBUG_PROFILE(name)
44
45#define DEBUG_PROFILE_VERBOSE(name, detail)
46
47#endif // FT_DEBUG_PROFILE
48
49} // namespace freetensor
50
51#endif // FREE_TENSOR_PROFILE_H
Definition: allocator.h:9
UpperBound add(const UpperBound &b1, const UpperBound &b2)
Definition: bounds.cc:193