X-Git-Url: https://git.saurik.com/apple/system_cmds.git/blobdiff_plain/1a7e3f61d38d679bba59130891c2031b5a0092b6..bd6521f0fc816ab056bc71376f9706a69b3b52c1:/kdprof/CollectAction.cpp diff --git a/kdprof/CollectAction.cpp b/kdprof/CollectAction.cpp new file mode 100644 index 0000000..9bb6207 --- /dev/null +++ b/kdprof/CollectAction.cpp @@ -0,0 +1,89 @@ +// +// CollectAction.cpp +// kdprof +// +// Created by James McIlree on 4/17/13. +// Copyright (c) 2013 Apple. All rights reserved. +// + +#include "global.h" + +template +static void execute_arch_specific(Globals& globals, KDState& state) { + // Collect all data first, printing takes time... + auto threadmap = KDBG::threadmap(state); + auto cpumap = KDBG::cpumap(); + + MemoryBuffer> events(state.capacity()); + int count = KDBG::read(events.data(), events.capacity() * sizeof(KDEvent)); + + // Now handle any verbose printing. + /*if (globals.is_verbose()) { + printf("\n%lu threadmap entries:\n", threadmap.size()); + for (auto& entry : threadmap) { + printf("\t0x%08llX %8u %20s\n", (uint64_t)entry.tid(), entry.pid(), entry.name()); + } + + printf("\n%lu cpumap entries:\n", cpumap.size()); + for (auto& entry : cpumap) { + printf("\t%3u %8s\n", entry.cpu_id(), entry.name()); + } + + printf("\n%d events:\n", count); + }*/ + + if (globals.should_presort_events()) { + std::sort(events.data(), events.data() + count, [](KDEvent const& p0, KDEvent const& p1) -> bool { + return p0.timestamp() < p1.timestamp(); + }); + } + Machine machine((KDCPUMapEntry*)cpumap.data(), (uint32_t)cpumap.size(), (KDThreadMapEntry*)threadmap.data(), (uint32_t)threadmap.size(), (KDEvent*)events.data(), (uintptr_t)count); + + if (!machine.lost_events()) { + if (globals.should_zero_base_timestamps() && count) { + globals.set_beginning_of_time((events.data())->timestamp()); + } else { + globals.set_beginning_of_time(AbsTime(0)); + } + + if (!globals.is_timebase_set()) { + mach_timebase_info_data_t timebase; + mach_timebase_info(&timebase); + globals.set_timebase(timebase, false); + } + + if (globals.is_verbose()) { + dprintf(globals.output_fd(), "\nLIVE DATA\n"); + print_verbose_machine_info(globals, machine, (uint32_t)threadmap.size(), (uint32_t)cpumap.size()); + } + + if (globals.should_print_events()) { + // print_machine(globals, machine); + // print_machine_parallel(globals, machine); + print_machine_events(globals, machine); + } + + if (globals.should_print_summary()) { + print_machine_summary(globals, machine); + } + + if (globals.should_print_csv_summary()) { + print_machine_csv_summary(globals, machine); + } + + if (globals.should_print_process_start_stop_timestamps()) { + print_process_start_stop_timestamps(globals, machine); + } + } else { + log_msg(ASL_LEVEL_WARNING, "The trace data indicates that events were lost, the file cannot be processed\n"); + } +} + +void CollectAction::execute(Globals& globals) { + KDState state = KDBG::state(); + if (state.is_lp64()) { + execute_arch_specific(globals, state); + } else { + execute_arch_specific(globals, state); + } +}