]> git.saurik.com Git - apple/system_cmds.git/blame - kdprof/CollectAction.cpp
system_cmds-670.1.2.tar.gz
[apple/system_cmds.git] / kdprof / CollectAction.cpp
CommitLineData
bd6521f0
A
1//
2// CollectAction.cpp
3// kdprof
4//
5// Created by James McIlree on 4/17/13.
6// Copyright (c) 2013 Apple. All rights reserved.
7//
8
9#include "global.h"
10
11template <typename SIZE>
12static 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();
16
17 MemoryBuffer<KDEvent<SIZE>> events(state.capacity());
18 int count = KDBG::read(events.data(), events.capacity() * sizeof(KDEvent<SIZE>));
19
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());
25 }
26
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());
30 }
31
32 printf("\n%d events:\n", count);
33 }*/
34
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();
38 });
39 }
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);
41
42 if (!machine.lost_events()) {
43 if (globals.should_zero_base_timestamps() && count) {
44 globals.set_beginning_of_time((events.data())->timestamp());
45 } else {
46 globals.set_beginning_of_time(AbsTime(0));
47 }
48
49 if (!globals.is_timebase_set()) {
50 mach_timebase_info_data_t timebase;
51 mach_timebase_info(&timebase);
52 globals.set_timebase(timebase, false);
53 }
54
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());
58 }
59
60 if (globals.should_print_events()) {
61 // print_machine(globals, machine);
62 // print_machine_parallel(globals, machine);
63 print_machine_events(globals, machine);
64 }
65
66 if (globals.should_print_summary()) {
67 print_machine_summary(globals, machine);
68 }
69
70 if (globals.should_print_csv_summary()) {
71 print_machine_csv_summary(globals, machine);
72 }
73
74 if (globals.should_print_process_start_stop_timestamps()) {
75 print_process_start_stop_timestamps(globals, machine);
76 }
77 } else {
78 log_msg(ASL_LEVEL_WARNING, "The trace data indicates that events were lost, the file cannot be processed\n");
79 }
80}
81
82void CollectAction::execute(Globals& globals) {
83 KDState state = KDBG::state();
84 if (state.is_lp64()) {
85 execute_arch_specific<Kernel64>(globals, state);
86 } else {
87 execute_arch_specific<Kernel32>(globals, state);
88 }
89}