5 // Created by James McIlree on 4/17/13.
6 // Copyright (c) 2014 Apple. All rights reserved.
9 #ifndef msa_Globals_hpp
10 #define msa_Globals_hpp
13 // These are "global" values that control parsing and printing behavior.
16 enum class kLifecycleFilter : std::uint32_t {
22 enum class kMachMsgFilter : std::uint32_t {
31 // Default/unknown parsing values
34 KernelSize _kernel_size;
35 std::string _live_update_interval;
37 bool _is_cpu_count_set;
38 bool _is_iop_count_set;
39 bool _is_kernel_size_set;
40 bool _is_timebase_set;
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;
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;
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; }
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; }
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; }
72 AbsTime beginning_of_time() const { return _beginning_of_time; }
73 void set_beginning_of_time(AbsTime t) { _beginning_of_time = t; }
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; }
79 int output_fd() const { return _output_fd.is_open() ? (int)_output_fd : STDOUT_FILENO; }
81 // Okay, this method caused enough pain to make the final resolution worth a comment.
83 // http://thbecker.net/articles/rvalue_references/section_05.html
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.
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); }
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; }
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; }
98 bool is_verbose() const { return _is_verbose; }
99 void set_is_verbose(bool value) { _is_verbose = value; }
101 bool should_presort_events() const { return _should_presort_events; }
102 void set_should_presort_events(bool value) { _should_presort_events = value; }
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; }
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; }
110 uint32_t trace_buffer_size() const { return _trace_buffer_size; }
111 void set_trace_buffer_size(uint32_t value) { _trace_buffer_size = value; }
113 AbsTime live_update_interval() const;
114 void set_live_update_interval(const char* value) { _live_update_interval = value; }
116 kLifecycleFilter lifecycle_filter() const { return _lifecycle_filter; }
117 void set_lifecycle_filter(kLifecycleFilter value) { _lifecycle_filter = value; }
119 kMachMsgFilter mach_msg_filter() const { return _mach_msg_filter; }
120 void set_mach_msg_filter(kMachMsgFilter value) { _mach_msg_filter = value; }