blob: fe68941687df6e86c4e5919d082ea6d519e031f3 [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>
Stephan Pleines682928d2024-05-31 20:43:48 -07005#include <string.h>
6#include <unistd.h>
Austin Schuh5af45eb2019-09-16 20:54:18 -07007
Austin Schuh99f7c6a2024-06-25 22:07:44 -07008#include "absl/log/check.h"
9#include "absl/log/log.h"
Austin Schuh5af45eb2019-09-16 20:54:18 -070010
Philipp Schrader790cb542023-07-05 21:06:52 -070011#include "aos/time/time.h"
12
Austin Schuh5af45eb2019-09-16 20:54:18 -070013namespace 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_