]>
git.saurik.com Git - apple/system_cmds.git/blob - msa/WriteTraceFileAction.cpp
2 // WriteTraceFileAction.cpp
5 // Created by James McIlree on 4/29/14.
11 static bool shouldProcessEvents
;
12 static uint32_t sigintCount
;
14 static bool start_tracing(Globals
& globals
)
16 if (!KDBG::reset()) return false;
17 if (!KDBG::set_buffer_capacity(globals
.trace_buffer_size())) return false;
18 if (!KDBG::set_nowrap(false)) return false;
19 if (!KDBG::initialize_buffers()) return false;
20 if (!KDBG::set_enabled(KDEBUG_ENABLE_TRACE
)) return false;
25 static void end_tracing(void)
30 static void signal_handler_ctrl_C(int sig
)
32 shouldProcessEvents
= false;
33 if (++sigintCount
>= 5) {
34 // Not responding, nuke it from orbit.
39 void WriteTraceFileAction::execute(Globals
& globals
) {
40 FileDescriptor
fd(open(_path
.c_str(), O_TRUNC
|O_WRONLY
|O_CREAT
, 0777));
42 log_msg(ASL_LEVEL_ERR
, "Unable to write to %s\n", _path
.c_str());
46 shouldProcessEvents
= true;
49 VoucherContentSysctl
contents(globals
.should_trace_voucher_contents());
51 AbsTime t1
= AbsTime::now();
52 if (start_tracing(globals
)) {
53 // We cannot write the "maps" until after tracing has started.
54 if (KDBG::write_maps(fd
)) {
55 signal(SIGINT
, signal_handler_ctrl_C
);
57 while (shouldProcessEvents
) {
58 int events_written
= KDBG::write_events(fd
);
59 AbsTime t2
= AbsTime::now();
60 if (events_written
!= -1) {
61 printf("wrote %d events - elapsed time = %.1f secs\n", events_written
, (double)(t2
- t1
).nano_time().value() / (double)NANOSECONDS_PER_SECOND
);
63 log_msg(ASL_LEVEL_WARNING
, "write events returned -1\n");
69 signal(SIGINT
, SIG_DFL
);