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