Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 1 | #ifndef AOS_FTRACE_H_ |
| 2 | #define AOS_FTRACE_H_ |
| 3 | |
| 4 | #include <fcntl.h> |
| 5 | #include <sys/stat.h> |
| 6 | #include <sys/types.h> |
| 7 | #include <unistd.h> |
| 8 | |
| 9 | #include <string_view> |
| 10 | |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 11 | namespace aos { |
| 12 | |
| 13 | // Manages interacting with ftrace. Silently hides many errors, because they are |
| 14 | // expected to occur when ftrace is not enabled, and we want calling code to |
| 15 | // continue working in that case. |
| 16 | class Ftrace { |
| 17 | public: |
Austin Schuh | 2723736 | 2021-11-06 16:29:02 -0700 | [diff] [blame] | 18 | Ftrace(); |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 19 | ~Ftrace(); |
| 20 | |
| 21 | // Writes a message with a printf-style format. |
| 22 | // |
| 23 | // Silently does nothing if tracing is disabled. |
| 24 | void FormatMessage(const char *format, ...) |
| 25 | __attribute__((format(__printf__, 2, 3))); |
| 26 | |
| 27 | // Writes a preformatted message. |
| 28 | // |
| 29 | // Silently does nothing if tracing is disabled. |
| 30 | void WriteMessage(std::string_view content); |
| 31 | |
| 32 | // Turns tracing off, or CHECK-fails if tracing is inaccessible. Does nothing |
| 33 | // if tracing is currently available but off. |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 34 | void TurnOffOrDie(); |
Brian Silverman | 79ec7fc | 2020-06-08 20:11:22 -0500 | [diff] [blame] | 35 | |
| 36 | private: |
| 37 | int message_fd_, on_fd_; |
| 38 | }; |
| 39 | |
| 40 | } // namespace aos |
| 41 | |
| 42 | #endif // AOS_FTRACE_H_ |