blob: 4d9b9122344ff2cc82f8224cd57f99b3d59cdf0f [file] [log] [blame]
Austin Schuh5af45eb2019-09-16 20:54:18 -07001#ifndef AOS_IPC_LIB_LATENCY_LIB_H_
2#define AOS_IPC_LIB_LATENCY_LIB_H_
3
4#include <fcntl.h>
5#include <sys/stat.h>
6#include <sys/types.h>
7#include <chrono>
8
9#include "aos/time/time.h"
10#include "glog/logging.h"
11
12namespace aos {
13
14void TimerThread(monotonic_clock::time_point end_time, int timer_priority);
15
16class Tracing {
17 public:
18 Tracing() {
19 SetContentsOrDie("/sys/kernel/debug/tracing/events/enable", "1\n");
20 fd_ = open("/sys/kernel/debug/tracing/tracing_on",
21 O_WRONLY | O_TRUNC | O_CLOEXEC, 0);
22 PCHECK(fd_);
23 }
24
25 ~Tracing() { close(fd_); }
26
27 void Start() { PCHECK(write(fd_, "1\n", 2)); }
28
29 void Stop() { PCHECK(write(fd_, "0\n", 2)); }
30
31 private:
32 void SetContentsOrDie(const char *filename, const char *data) {
33 int fd = open(filename, O_WRONLY | O_TRUNC | O_CLOEXEC);
34 PCHECK(fd);
35 PCHECK(write(fd, data, strlen(data)));
36 PCHECK(close(fd));
37 }
38
39 int fd_;
40};
41
42} // namespace aos
43
44#endif // AOS_IPC_LIB_LATENCY_LIB_H_