blob: e4548381f6b6f369add682077d3739744aec05b3 [file] [log] [blame]
Brian Silverman79ec7fc2020-06-08 20:11:22 -05001#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 Silverman79ec7fc2020-06-08 20:11:22 -050011namespace 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.
16class Ftrace {
17 public:
Austin Schuh27237362021-11-06 16:29:02 -070018 Ftrace();
Brian Silverman79ec7fc2020-06-08 20:11:22 -050019 ~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 Schuh99f7c6a2024-06-25 22:07:44 -070034 void TurnOffOrDie();
Brian Silverman79ec7fc2020-06-08 20:11:22 -050035
36 private:
37 int message_fd_, on_fd_;
38};
39
40} // namespace aos
41
42#endif // AOS_FTRACE_H_