8 #include <condition_variable> 13 #include <unordered_set> 23 std::atomic<int64_t> _time;
24 std::atomic<int64_t> _count;
31 const std::string &name()
const {
return _name; }
32 inline void add(int64_t time) {
41 std::chrono::steady_clock::time_point _start;
45 : _track(track), _start(std::chrono::steady_clock::now()) {}
47 _track.add(std::chrono::duration_cast<std::chrono::microseconds, int64_t>(
48 std::chrono::steady_clock::now() - _start)
56 mutable std::mutex _mutex;
57 mutable std::vector<std::weak_ptr<ProfilerTrack>> _tracks;
60 static std::shared_ptr<Profiler> instance();
61 std::shared_ptr<ProfilerTrack>
62 track(
const std::shared_ptr<ProfilerTrack> &track);
63 std::vector<std::shared_ptr<ProfilerTrack>> tracks()
const;
70 std::condition_variable _condition;
74 const std::shared_ptr<Profiler> &profiler = Profiler::instance());
78 #define PROFILER(...) \ 79 static std::shared_ptr<ProfilerTrack> profiler_track = \ 80 Profiler::instance()->track(std::make_shared<ProfilerTrack>( \ 81 std::string() + __PRETTY_FUNCTION__ + " " __VA_ARGS__)); \ 82 ProfilerScope profiler_scope(*profiler_track);