]> git.saurik.com Git - apple/system_cmds.git/blame - msa/Globals.hpp
system_cmds-643.30.1.tar.gz
[apple/system_cmds.git] / msa / Globals.hpp
CommitLineData
bd6521f0
A
1//
2// Globals.hpp
3// msa
4//
5// Created by James McIlree on 4/17/13.
6// Copyright (c) 2014 Apple. All rights reserved.
7//
8
9#ifndef msa_Globals_hpp
10#define msa_Globals_hpp
11
12//
13// These are "global" values that control parsing and printing behavior.
14//
15
16enum class kLifecycleFilter : std::uint32_t {
17 None = 0,
18 User,
19 All
20};
21
22enum class kMachMsgFilter : std::uint32_t {
23 None = 0,
24 User,
25 Voucher,
26 All
27};
28
29class Globals {
30 protected:
31 // Default/unknown parsing values
32 uint32_t _cpu_count;
33 uint32_t _iop_count;
34 KernelSize _kernel_size;
35 std::string _live_update_interval;
36
37 bool _is_cpu_count_set;
38 bool _is_iop_count_set;
39 bool _is_kernel_size_set;
40 bool _is_timebase_set;
41
42 // Output, printing related.
43 AbsTime _beginning_of_time;
44 mach_timebase_info_data_t _timebase_info;
45 FileDescriptor _output_fd;
46 bool _should_print_mach_absolute_timestamps;
47 bool _should_print_event_index;
48 bool _is_verbose;
49 bool _should_presort_events;
50 bool _should_zero_base_timestamps;
51 bool _should_trace_voucher_contents;
52 uint32_t _trace_buffer_size;
53 kLifecycleFilter _lifecycle_filter;
54 kMachMsgFilter _mach_msg_filter;
55
56
57 public:
58 Globals();
59
60 uint32_t cpu_count() const { return _cpu_count; }
61 void set_cpu_count(uint32_t num) { _cpu_count = num; _is_cpu_count_set = true; }
62 bool is_cpu_count_set() const { return _is_cpu_count_set; }
63
64 uint32_t iop_count() const { return _iop_count; }
65 void set_iop_count(uint32_t num) { _iop_count = num; _is_iop_count_set = true; }
66 bool is_iop_count_set() const { return _is_iop_count_set; }
67
68 KernelSize kernel_size() const { return _kernel_size; }
69 void set_kernel_size(KernelSize size) { _kernel_size = size; _is_kernel_size_set = true; }
70 bool is_kernel_size_set() const { return _is_kernel_size_set; }
71
72 AbsTime beginning_of_time() const { return _beginning_of_time; }
73 void set_beginning_of_time(AbsTime t) { _beginning_of_time = t; }
74
75 mach_timebase_info_data_t timebase() const { return _timebase_info; }
76 void set_timebase(mach_timebase_info_data_t timebase, bool is_user_set) { _timebase_info = timebase; if (is_user_set) _is_timebase_set = true; }
77 bool is_timebase_set() const { return _is_timebase_set; }
78
79 int output_fd() const { return _output_fd.is_open() ? (int)_output_fd : STDOUT_FILENO; }
80
81 // Okay, this method caused enough pain to make the final resolution worth a comment.
82 //
83 // http://thbecker.net/articles/rvalue_references/section_05.html
84 //
85 // Things that are declared as rvalue reference can be lvalues or rvalues.
86 // The distinguishing criterion is: if it has a name, then it is an lvalue. Otherwise, it is an rvalue.
87 //
88 // In this case, you cannot call set_output_fd with an lvalue, but fd is STILL an lvalue.
89 // We must still explicitly use std::move on fd!
90 void set_output_fd(FileDescriptor&& fd) { _output_fd = std::move(fd); }
91
92 bool should_print_mach_absolute_timestamps() const { return _should_print_mach_absolute_timestamps; }
93 void set_should_print_mach_absolute_timestamps(bool value) { _should_print_mach_absolute_timestamps = value; }
94
95 bool should_print_event_index() const { return _should_print_event_index; }
96 void set_should_print_event_index(bool value) { _should_print_event_index = value; }
97
98 bool is_verbose() const { return _is_verbose; }
99 void set_is_verbose(bool value) { _is_verbose = value; }
100
101 bool should_presort_events() const { return _should_presort_events; }
102 void set_should_presort_events(bool value) { _should_presort_events = value; }
103
104 bool should_zero_base_timestamps() const { return _should_zero_base_timestamps; }
105 void set_should_zero_base_timestamps(bool value) { _should_zero_base_timestamps = value; }
106
107 bool should_trace_voucher_contents() const { return _should_trace_voucher_contents; }
108 void set_should_trace_voucher_contents(bool value) { _should_trace_voucher_contents = value; }
109
110 uint32_t trace_buffer_size() const { return _trace_buffer_size; }
111 void set_trace_buffer_size(uint32_t value) { _trace_buffer_size = value; }
112
113 AbsTime live_update_interval() const;
114 void set_live_update_interval(const char* value) { _live_update_interval = value; }
115
116 kLifecycleFilter lifecycle_filter() const { return _lifecycle_filter; }
117 void set_lifecycle_filter(kLifecycleFilter value) { _lifecycle_filter = value; }
118
119 kMachMsgFilter mach_msg_filter() const { return _mach_msg_filter; }
120 void set_mach_msg_filter(kMachMsgFilter value) { _mach_msg_filter = value; }
121};
122
123#endif