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