blob: 8206f3e3a612960c02bb60f18944ccd5fad1bb19 [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 Schuh5af45eb2019-09-16 20:54:18 -07008#include "glog/logging.h"
9
Philipp Schrader790cb542023-07-05 21:06:52 -070010#include "aos/time/time.h"
11
Austin Schuh5af45eb2019-09-16 20:54:18 -070012namespace 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_