Skip to main content

Measurement

Struct Measurement 

Source
pub struct Measurement {
    pub value: f64,
    pub unit_symbol: String,
    pub unit_type: String,
}
Expand description

Rust representation of a MetricKit measurement value.

Fields§

§value: f64

Stores the numeric component emitted by MetricKit.

§unit_symbol: String

Stores the unit symbol emitted by MetricKit.

§unit_type: String

Stores the unit type emitted by MetricKit.

Implementations§

Source§

impl Measurement

Source

pub fn new( value: f64, unit_symbol: impl Into<String>, unit_type: impl Into<String>, ) -> Self

Builds a MetricKit-style measurement value.

Examples found in repository?
examples/support/mod.rs (line 17)
16pub fn sample_duration_measurement() -> Measurement {
17    Measurement::new(1.25, "s", "UnitDuration")
18}
19
20pub fn sample_ratio_measurement() -> Measurement {
21    Measurement::new(0.2, "", "Unit")
22}
23
24pub fn sample_size_measurement() -> Measurement {
25    Measurement::new(256.0, "MB", "UnitInformationStorage")
26}
27
28pub fn sample_instruction_measurement() -> Measurement {
29    Measurement::new(4096.0, "instructions", "Unit")
30}
31
32pub fn sample_average() -> Average {
33    Average {
34        average_measurement: sample_size_measurement(),
35        sample_count: 4,
36        standard_deviation: 0.5,
37    }
38}
39
40pub fn sample_histogram() -> Histogram {
41    Histogram {
42        total_bucket_count: 2,
43        buckets: vec![
44            HistogramBucket {
45                bucket_start: Measurement::new(0.0, "s", "UnitDuration"),
46                bucket_end: Measurement::new(1.0, "s", "UnitDuration"),
47                bucket_count: 2,
48            },
49            HistogramBucket {
50                bucket_start: Measurement::new(1.0, "s", "UnitDuration"),
51                bucket_end: Measurement::new(2.0, "s", "UnitDuration"),
52                bucket_count: 1,
53            },
54        ],
55    }
56}
57
58pub fn sample_meta_data() -> MetaData {
59    MetaData {
60        region_format: "en_US".into(),
61        os_version: "26.0".into(),
62        device_type: "MacBookPro".into(),
63        application_build_version: "42".into(),
64        platform_architecture: Some("arm64".into()),
65        low_power_mode_enabled: Some(false),
66        is_test_flight_app: Some(false),
67        pid: Some(1234),
68        bundle_identifier: Some("fish.doom.metrickit".into()),
69    }
70}
71
72pub fn sample_call_stack_tree() -> CallStackTree {
73    CallStackTree::new(json!({
74        "callStacks": [
75            {
76                "threadAttributed": true,
77                "callStackRootFrames": [
78                    {
79                        "binaryName": "MetrickitExample",
80                        "binaryUUID": "00000000-0000-0000-0000-000000000000",
81                        "offsetIntoBinaryTextSegment": 16,
82                        "sampleCount": 1
83                    }
84                ]
85            }
86        ]
87    }))
88}
89
90pub fn sample_signpost_record() -> SignpostRecord {
91    SignpostRecord {
92        subsystem: "fish.doom.metrickit".into(),
93        category: "sample".into(),
94        name: "payload-processing".into(),
95        begin_time_stamp: 100.0,
96        end_time_stamp: Some(101.5),
97        duration: Some(Measurement::new(1500.0, "ms", "UnitDuration")),
98        is_interval: true,
99    }
100}
101
102pub fn sample_diagnostic() -> Diagnostic {
103    Diagnostic {
104        meta_data: sample_meta_data(),
105        application_version: "1.2.3".into(),
106        signpost_data: vec![sample_signpost_record()],
107    }
108}
109
110pub fn sample_cpu_metric() -> CpuMetric {
111    CpuMetric {
112        cumulative_cpu_time: sample_duration_measurement(),
113        cumulative_cpu_instructions: Some(sample_instruction_measurement()),
114    }
115}
116
117pub fn sample_memory_metric() -> MemoryMetric {
118    MemoryMetric {
119        peak_memory_usage: sample_size_measurement(),
120        average_suspended_memory: sample_average(),
121    }
122}
123
124pub fn sample_gpu_metric() -> GpuMetric {
125    GpuMetric {
126        cumulative_gpu_time: sample_duration_measurement(),
127    }
128}
129
130pub fn sample_animation_metric() -> AnimationMetric {
131    AnimationMetric {
132        scroll_hitch_time_ratio: sample_ratio_measurement(),
133        hitch_time_ratio: Some(sample_ratio_measurement()),
134    }
135}
136
137pub fn sample_application_launch_metric() -> ApplicationLaunchMetric {
138    ApplicationLaunchMetric {
139        histogrammed_time_to_first_draw: sample_histogram(),
140        histogrammed_application_resume_time: sample_histogram(),
141        histogrammed_optimized_time_to_first_draw: Some(sample_histogram()),
142        histogrammed_extended_launch: Some(sample_histogram()),
143    }
144}
145
146pub fn sample_application_responsiveness_metric() -> ApplicationResponsivenessMetric {
147    ApplicationResponsivenessMetric {
148        histogrammed_application_hang_time: sample_histogram(),
149    }
150}
151
152pub fn sample_application_time_metric() -> ApplicationTimeMetric {
153    ApplicationTimeMetric {
154        cumulative_foreground_time: sample_duration_measurement(),
155        cumulative_background_time: sample_duration_measurement(),
156        cumulative_background_audio_time: sample_duration_measurement(),
157        cumulative_background_location_time: sample_duration_measurement(),
158    }
159}
160
161pub fn sample_location_activity_metric() -> LocationActivityMetric {
162    LocationActivityMetric {
163        cumulative_best_accuracy_time: sample_duration_measurement(),
164        cumulative_best_accuracy_for_navigation_time: sample_duration_measurement(),
165        cumulative_nearest_ten_meters_accuracy_time: sample_duration_measurement(),
166        cumulative_hundred_meters_accuracy_time: sample_duration_measurement(),
167        cumulative_kilometer_accuracy_time: sample_duration_measurement(),
168        cumulative_three_kilometers_accuracy_time: sample_duration_measurement(),
169    }
170}
171
172pub fn sample_network_transfer_metric() -> NetworkTransferMetric {
173    NetworkTransferMetric {
174        cumulative_wifi_upload: sample_size_measurement(),
175        cumulative_wifi_download: sample_size_measurement(),
176        cumulative_cellular_upload: sample_size_measurement(),
177        cumulative_cellular_download: sample_size_measurement(),
178    }
179}
180
181pub fn sample_disk_io_metric() -> DiskIoMetric {
182    DiskIoMetric {
183        cumulative_logical_writes: sample_size_measurement(),
184    }
185}
186
187pub fn sample_display_metric() -> DisplayMetric {
188    DisplayMetric {
189        average_pixel_luminance: Some(Average {
190            average_measurement: Measurement::new(
191                42.0,
192                AVERAGE_PIXEL_LUMINANCE_UNIT_SYMBOL,
193                "MXUnitAveragePixelLuminance",
194            ),
195            sample_count: 8,
196            standard_deviation: 1.5,
197        }),
198    }
199}
200
201pub fn sample_cellular_condition_metric() -> CellularConditionMetric {
202    CellularConditionMetric {
203        histogrammed_cellular_condition_time: Histogram {
204            total_bucket_count: 1,
205            buckets: vec![HistogramBucket {
206                bucket_start: Measurement::new(0.0, SIGNAL_BARS_UNIT_SYMBOL, "MXUnitSignalBars"),
207                bucket_end: Measurement::new(4.0, SIGNAL_BARS_UNIT_SYMBOL, "MXUnitSignalBars"),
208                bucket_count: 6,
209            }],
210        },
211    }
212}
213
214pub fn sample_foreground_exit_data() -> ForegroundExitData {
215    ForegroundExitData {
216        cumulative_normal_app_exit_count: 2,
217        cumulative_memory_resource_limit_exit_count: 1,
218        cumulative_bad_access_exit_count: 0,
219        cumulative_abnormal_exit_count: 1,
220        cumulative_illegal_instruction_exit_count: 0,
221        cumulative_app_watchdog_exit_count: 0,
222    }
223}
224
225pub fn sample_background_exit_data() -> BackgroundExitData {
226    BackgroundExitData {
227        cumulative_normal_app_exit_count: 4,
228        cumulative_memory_resource_limit_exit_count: 1,
229        cumulative_cpu_resource_limit_exit_count: 0,
230        cumulative_memory_pressure_exit_count: 0,
231        cumulative_bad_access_exit_count: 0,
232        cumulative_abnormal_exit_count: 0,
233        cumulative_illegal_instruction_exit_count: 0,
234        cumulative_app_watchdog_exit_count: 0,
235        cumulative_suspended_with_locked_file_exit_count: 0,
236        cumulative_background_task_assertion_timeout_exit_count: 0,
237    }
238}
239
240pub fn sample_application_exit_metric() -> ApplicationExitMetric {
241    ApplicationExitMetric {
242        foreground_exit_data: sample_foreground_exit_data(),
243        background_exit_data: sample_background_exit_data(),
244    }
245}
246
247pub fn sample_disk_space_usage_metric() -> DiskSpaceUsageMetric {
248    DiskSpaceUsageMetric {
249        total_binary_file_size: sample_size_measurement(),
250        total_binary_file_count: 12,
251        total_data_file_size: sample_size_measurement(),
252        total_data_file_count: 24,
253        total_cache_folder_size: sample_size_measurement(),
254        total_clone_size: sample_size_measurement(),
255        total_disk_space_used_size: sample_size_measurement(),
256        total_disk_space_capacity: Measurement::new(1024.0, "GB", "UnitInformationStorage"),
257    }
258}
Source

pub fn is_dimensionless(&self) -> bool

Returns whether this MetricKit measurement is unitless.

Trait Implementations§

Source§

impl Clone for Measurement

Source§

fn clone(&self) -> Measurement

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Measurement

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Measurement

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Measurement

Source§

fn eq(&self, other: &Measurement) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Measurement

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Measurement

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,