-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscoped_timer.h
More file actions
50 lines (40 loc) · 1.08 KB
/
scoped_timer.h
File metadata and controls
50 lines (40 loc) · 1.08 KB
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
#ifndef SCOPED_TIMER_H_
#define SCOPED_TIMER_H_
/**
* Utility class to dump usecs.
*/
#include <chrono>
#include <string>
#include "directory_container.h"
#include "disallow.h"
/*
system_clock, monotonic_clock and high_resolution_clock are supposed to exist,
we have steady_clock and system_lock.
*/
namespace scoped_timer {
class ScopedTimer {
public:
explicit ScopedTimer(const std::string name)
: name_(name), begin_(std::chrono::steady_clock::now()) {}
~ScopedTimer();
static std::string dump();
private:
const std::string name_;
std::chrono::steady_clock::time_point begin_;
DISALLOW_COPY_AND_ASSIGN(ScopedTimer);
};
class StatusHandler : public directory_container::File {
public:
StatusHandler();
virtual ~StatusHandler();
virtual int Getattr(struct stat *stbuf) override;
virtual ssize_t Read(char *buf, size_t size, off_t offset) override;
virtual int Open() override;
virtual int Release() override;
private:
void RefreshMessage();
std::string message_;
DISALLOW_COPY_AND_ASSIGN(StatusHandler);
};
} // namespace scoped_timer
#endif