]>
Commit | Line | Data |
---|---|---|
bd6521f0 A |
1 | // |
2 | // MachineGlobals.cpp | |
3 | // msa | |
4 | // | |
5 | // Created by James McIlree on 4/17/13. | |
6 | // Copyright (c) 2014 Apple. All rights reserved. | |
7 | // | |
8 | ||
9 | #include "global.h" | |
10 | ||
11 | Globals::Globals() : | |
12 | _cpu_count(0), | |
13 | _iop_count(0), | |
14 | _kernel_size(Kernel::is_64_bit() ? KernelSize::k64 : KernelSize::k32), | |
15 | _live_update_interval("100ms"), | |
16 | _is_cpu_count_set(false), | |
17 | _is_iop_count_set(false), | |
18 | _is_kernel_size_set(false), | |
19 | _is_timebase_set(false), | |
20 | _beginning_of_time(0), | |
21 | _should_print_mach_absolute_timestamps(false), | |
22 | _should_print_event_index(false), | |
23 | _is_verbose(false), | |
24 | _should_presort_events(false), | |
25 | _should_zero_base_timestamps(true), | |
26 | _should_trace_voucher_contents(true), | |
27 | _lifecycle_filter(kLifecycleFilter::User), | |
28 | _mach_msg_filter(kMachMsgFilter::Voucher) | |
29 | { | |
30 | // Default to the current machine's values | |
31 | mach_timebase_info(&_timebase_info); | |
32 | ||
33 | for (auto& entry : KDBG::cpumap()) { | |
34 | if (entry.is_iop()) | |
35 | _iop_count++; | |
36 | else | |
37 | _cpu_count++; | |
38 | } | |
39 | ||
40 | // If we are unable to get a cpumap, | |
41 | // fallback on the current # of cpus | |
42 | if (_cpu_count == 0) { | |
43 | _cpu_count = Kernel::active_cpu_count(); | |
44 | _iop_count = 0; | |
45 | } | |
46 | ||
47 | // This is only used as is for live tracing or capturing a trace, | |
48 | // so we want to use the current # of cpus. | |
49 | _trace_buffer_size = 250000 * _cpu_count; | |
50 | } | |
51 | ||
52 | static AbsTime parse_time(const char* arg, mach_timebase_info_data_t timebase_info) { | |
53 | ||
54 | char* units; | |
55 | uint64_t value = strtoull(arg, &units, 0); | |
56 | ||
57 | // Unspecified units are treated as seconds | |
58 | if (*units == 0 || strcmp(units, "s") == 0) { | |
59 | return NanoTime(value * NANOSECONDS_PER_SECOND).abs_time(timebase_info); | |
60 | } | |
61 | ||
62 | if (strcmp(units, "ms") == 0) | |
63 | return NanoTime(value * NANOSECONDS_PER_MILLISECOND).abs_time(timebase_info); | |
64 | ||
65 | if (strcmp(units, "us") == 0) | |
66 | return NanoTime(value * NANOSECONDS_PER_MICROSECOND).abs_time(timebase_info); | |
67 | ||
68 | if (strcmp(units, "ns") == 0) | |
69 | return NanoTime(value).abs_time(timebase_info); | |
70 | ||
71 | if (strcmp(units, "mabs") == 0) { | |
72 | return AbsTime(value); | |
73 | } | |
74 | ||
75 | usage("Unable to parse units on time value"); | |
76 | } | |
77 | ||
78 | AbsTime Globals::live_update_interval() const { | |
79 | return parse_time(_live_update_interval.c_str(), _timebase_info); | |
80 | } |