5 // Created by James McIlree on 4/17/13.
6 // Copyright (c) 2013 Apple. All rights reserved.
11 template <typename SIZE
>
12 static void execute_arch_specific(Globals
& globals
, KDState
& state
) {
13 // Collect all data first, printing takes time...
14 auto threadmap
= KDBG::threadmap
<SIZE
>(state
);
15 auto cpumap
= KDBG::cpumap();
17 MemoryBuffer
<KDEvent
<SIZE
>> events(state
.capacity());
18 int count
= KDBG::read(events
.data(), events
.capacity() * sizeof(KDEvent
<SIZE
>));
20 // Now handle any verbose printing.
21 /*if (globals.is_verbose()) {
22 printf("\n%lu threadmap entries:\n", threadmap.size());
23 for (auto& entry : threadmap) {
24 printf("\t0x%08llX %8u %20s\n", (uint64_t)entry.tid(), entry.pid(), entry.name());
27 printf("\n%lu cpumap entries:\n", cpumap.size());
28 for (auto& entry : cpumap) {
29 printf("\t%3u %8s\n", entry.cpu_id(), entry.name());
32 printf("\n%d events:\n", count);
35 if (globals
.should_presort_events()) {
36 std::sort(events
.data(), events
.data() + count
, [](KDEvent
<SIZE
> const& p0
, KDEvent
<SIZE
> const& p1
) -> bool {
37 return p0
.timestamp() < p1
.timestamp();
40 Machine
<SIZE
> machine((KDCPUMapEntry
*)cpumap
.data(), (uint32_t)cpumap
.size(), (KDThreadMapEntry
<SIZE
>*)threadmap
.data(), (uint32_t)threadmap
.size(), (KDEvent
<SIZE
>*)events
.data(), (uintptr_t)count
);
42 if (!machine
.lost_events()) {
43 if (globals
.should_zero_base_timestamps() && count
) {
44 globals
.set_beginning_of_time((events
.data())->timestamp());
46 globals
.set_beginning_of_time(AbsTime(0));
49 if (!globals
.is_timebase_set()) {
50 mach_timebase_info_data_t timebase
;
51 mach_timebase_info(&timebase
);
52 globals
.set_timebase(timebase
, false);
55 if (globals
.is_verbose()) {
56 dprintf(globals
.output_fd(), "\nLIVE DATA\n");
57 print_verbose_machine_info(globals
, machine
, (uint32_t)threadmap
.size(), (uint32_t)cpumap
.size());
60 if (globals
.should_print_events()) {
61 // print_machine(globals, machine);
62 // print_machine_parallel(globals, machine);
63 print_machine_events(globals
, machine
);
66 if (globals
.should_print_summary()) {
67 print_machine_summary(globals
, machine
);
70 if (globals
.should_print_csv_summary()) {
71 print_machine_csv_summary(globals
, machine
);
74 if (globals
.should_print_process_start_stop_timestamps()) {
75 print_process_start_stop_timestamps(globals
, machine
);
78 log_msg(ASL_LEVEL_WARNING
, "The trace data indicates that events were lost, the file cannot be processed\n");
82 void CollectAction::execute(Globals
& globals
) {
83 KDState state
= KDBG::state();
84 if (state
.is_lp64()) {
85 execute_arch_specific
<Kernel64
>(globals
, state
);
87 execute_arch_specific
<Kernel32
>(globals
, state
);