]> git.saurik.com Git - apple/system_cmds.git/blame - msa/ReadTraceFileAction.cpp
system_cmds-643.30.1.tar.gz
[apple/system_cmds.git] / msa / ReadTraceFileAction.cpp
CommitLineData
bd6521f0
A
1//
2// ReadTraceFileAction.cpp
3// msa
4//
5// Created by James McIlree on 4/15/13.
6// Copyright (c) 2014 Apple. All rights reserved.
7//
8
9#include "global.h"
10
11template <typename SIZE>
12static void execute_arch_specific(Globals& globals, TraceFile& file)
13{
14 Machine<SIZE> machine(file);
15
16 if (!machine.lost_events()) {
17 if (globals.should_zero_base_timestamps() && machine.event_count()) {
18 globals.set_beginning_of_time(machine.events()[0].timestamp());
19 } else {
20 globals.set_beginning_of_time(AbsTime(0));
21 }
22
23 if (!globals.is_timebase_set()) {
24 if (machine.is_ios()) {
25 globals.set_timebase({ 125, 3 }, false);
26 } else {
27 globals.set_timebase({ 1, 1 }, false);
28 }
29 }
30
31 char buf[PATH_MAX];
32 char* buf_end = buf + sizeof(buf);
33 print_mach_msg_header(buf, buf_end, globals);
34 dprintf(globals.output_fd(), "%s", buf);
35
36 std::unordered_map<pid_t, bool> task_appnap_state;
37 std::unordered_map<pid_t, TaskRequestedPolicy> task_requested_state;
38 std::unordered_map<typename SIZE::ptr_t, TaskRequestedPolicy> thread_requested_state;
39 std::unordered_map<pid_t, std::pair<TaskEffectivePolicy, uint32_t>> task_effective_state;
40 std::unordered_map<typename SIZE::ptr_t, std::pair<TaskEffectivePolicy, uint32_t>> thread_effective_state;
41 std::unordered_map<pid_t, std::pair<uint32_t, uint32_t>> task_boosts;
42
43 process_events(globals, machine, task_appnap_state, task_requested_state, thread_requested_state, task_effective_state, thread_effective_state, task_boosts);
44 } else {
45 log_msg(ASL_LEVEL_WARNING, "The trace data indicates that events were lost, the file cannot be processed\n");
46 }
47}
48
49void ReadTraceFileAction::execute(Globals& globals) {
50 TraceFile file(_path.c_str(), globals.should_presort_events(), globals.cpu_count(), globals.iop_count());
51 if (globals.is_kernel_size_set()) {
52 try {
53 if (globals.kernel_size() == KernelSize::k32)
54 execute_arch_specific<Kernel32>(globals, file);
55 else
56 execute_arch_specific<Kernel64>(globals, file);
57 } catch (Exception& e) {
58 log_msg(ASL_LEVEL_ERR, "An exception was raised: %s", e.what());
59 log_msg(ASL_LEVEL_ERR, "An explicit kernel size was set, you may want to try not forcing the size to a single value\n");
60 log_msg(ASL_LEVEL_ERR, "You may also want to check the number of cpus and iops configured if the file is from a device and does not have a cpumap\n");
61 }
62 } else {
63 if (file.is_valid()) {
64 if (file.is_64_bit()) {
65 execute_arch_specific<Kernel64>(globals, file);
66 } else {
67 execute_arch_specific<Kernel32>(globals, file);
68 }
69 } else {
70 if (file.mmap_failed()) {
71 log_msg(ASL_LEVEL_ERR, "Unable to mmap %s, it may exceed this devices memory limits\n", _path.c_str());
72 } else {
73 log_msg(ASL_LEVEL_ERR, "%s does not appear to be a valid trace file\n", _path.c_str());
74 }
75 }
76 }
77}