Austin Schuh | 5af45eb | 2019-09-16 20:54:18 -0700 | [diff] [blame] | 1 | #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 Schuh | 60e7794 | 2022-05-16 17:48:24 -0700 | [diff] [blame] | 7 | |
Austin Schuh | 5af45eb | 2019-09-16 20:54:18 -0700 | [diff] [blame] | 8 | #include <chrono> |
| 9 | |
| 10 | #include "aos/time/time.h" |
| 11 | #include "glog/logging.h" |
| 12 | |
| 13 | namespace aos { |
| 14 | |
| 15 | void TimerThread(monotonic_clock::time_point end_time, int timer_priority); |
| 16 | |
| 17 | class 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_ |