Skip to content

Commit 5bdf4f2

Browse files
Only use 48 bits for encoding timestamps and 32 bits for encoding thread IDs in RawEvent in order to make it smaller.
1 parent 9476b16 commit 5bdf4f2

File tree

9 files changed

+256
-33
lines changed

9 files changed

+256
-33
lines changed

analyzeme/src/event.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub struct Event<'a> {
88
pub label: Cow<'a, str>,
99
pub additional_data: &'a [Cow<'a, str>],
1010
pub timestamp: Timestamp,
11-
pub thread_id: u64,
11+
pub thread_id: u32,
1212
}
1313

1414
impl<'a> Event<'a> {
@@ -46,12 +46,12 @@ pub enum Timestamp {
4646

4747
impl Timestamp {
4848
pub fn from_raw_event(raw_event: &RawEvent, start_time: SystemTime) -> Timestamp {
49-
if raw_event.end_ns == std::u64::MAX {
50-
let t = start_time + Duration::from_nanos(raw_event.start_ns);
49+
if raw_event.is_instant() {
50+
let t = start_time + Duration::from_nanos(raw_event.start_nanos());
5151
Timestamp::Instant(t)
5252
} else {
53-
let start = start_time + Duration::from_nanos(raw_event.start_ns);
54-
let end = start_time + Duration::from_nanos(raw_event.end_ns);
53+
let start = start_time + Duration::from_nanos(raw_event.start_nanos());
54+
let end = start_time + Duration::from_nanos(raw_event.end_nanos());
5555
Timestamp::Interval { start, end }
5656
}
5757
}

analyzeme/src/profiling_data.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl ProfilingDataBuilder {
204204
&mut self,
205205
event_kind: &str,
206206
event_id: &str,
207-
thread_id: u64,
207+
thread_id: u32,
208208
start_nanos: u64,
209209
end_nanos: u64,
210210
inner: F,
@@ -230,7 +230,7 @@ impl ProfilingDataBuilder {
230230
&mut self,
231231
event_kind: &str,
232232
event_id: &str,
233-
thread_id: u64,
233+
thread_id: u32,
234234
timestamp_nanos: u64,
235235
) -> &mut Self {
236236
let event_kind = self.string_table.alloc(event_kind);
@@ -307,7 +307,7 @@ mod tests {
307307
fn interval(
308308
event_kind: &'static str,
309309
label: &'static str,
310-
thread_id: u64,
310+
thread_id: u32,
311311
start_nanos: u64,
312312
end_nanos: u64,
313313
) -> Event<'static> {
@@ -326,7 +326,7 @@ mod tests {
326326
fn instant(
327327
event_kind: &'static str,
328328
label: &'static str,
329-
thread_id: u64,
329+
thread_id: u32,
330330
timestamp_nanos: u64,
331331
) -> Event<'static> {
332332
Event {

analyzeme/src/testing_common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fn pseudo_invocation<S: SerializationSink>(
121121
return;
122122
}
123123

124-
let thread_id = (random % 3) as u64;
124+
let thread_id = (random % 3) as u32;
125125

126126
let (event_kind, event_id) = event_ids[random % event_ids.len()];
127127

crox/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct Event {
3838
#[serde(rename = "pid")]
3939
process_id: u32,
4040
#[serde(rename = "tid")]
41-
thread_id: u64,
41+
thread_id: u32,
4242
args: Option<FxHashMap<String, String>>,
4343
}
4444

@@ -61,12 +61,12 @@ struct Opt {
6161
fn generate_thread_to_collapsed_thread_mapping(
6262
opt: &Opt,
6363
data: &ProfilingData,
64-
) -> FxHashMap<u64, u64> {
65-
let mut thread_to_collapsed_thread: FxHashMap<u64, u64> = FxHashMap::default();
64+
) -> FxHashMap<u32, u32> {
65+
let mut thread_to_collapsed_thread: FxHashMap<u32, u32> = FxHashMap::default();
6666

6767
if opt.collapse_threads {
6868
// collect start and end times for all threads
69-
let mut thread_start_and_end: FxHashMap<u64, (SystemTime, SystemTime)> =
69+
let mut thread_start_and_end: FxHashMap<u32, (SystemTime, SystemTime)> =
7070
FxHashMap::default();
7171
for event in data.iter() {
7272
thread_start_and_end

measureme/src/file_header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::serialization::SerializationSink;
66
use byteorder::{ByteOrder, LittleEndian};
77
use std::error::Error;
88

9-
pub const CURRENT_FILE_FORMAT_VERSION: u32 = 1;
9+
pub const CURRENT_FILE_FORMAT_VERSION: u32 = 2;
1010
pub const FILE_MAGIC_EVENT_STREAM: &[u8; 4] = b"MMES";
1111
pub const FILE_MAGIC_STRINGTABLE_DATA: &[u8; 4] = b"MMSD";
1212
pub const FILE_MAGIC_STRINGTABLE_INDEX: &[u8; 4] = b"MMSI";

measureme/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub use crate::file_serialization_sink::FileSerializationSink;
5555
#[cfg(not(target_arch = "wasm32"))]
5656
pub use crate::mmap_serialization_sink::MmapSerializationSink;
5757
pub use crate::profiler::{Profiler, ProfilerFiles, TimingGuard};
58-
pub use crate::raw_event::RawEvent;
58+
pub use crate::raw_event::{RawEvent, MAX_INSTANT_TIMESTAMP, MAX_INTERVAL_TIMESTAMP};
5959
pub use crate::serialization::{Addr, ByteVecSink, SerializationSink};
6060
pub use crate::stringtable::{
6161
SerializableString, StringId, StringRef, StringTable, StringTableBuilder,

measureme/src/profiler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<S: SerializationSink> Profiler<S> {
8383

8484
/// Records an event with the given parameters. The event time is computed
8585
/// automatically.
86-
pub fn record_instant_event(&self, event_kind: StringId, event_id: StringId, thread_id: u64) {
86+
pub fn record_instant_event(&self, event_kind: StringId, event_id: StringId, thread_id: u32) {
8787
let raw_event =
8888
RawEvent::new_instant(event_kind, event_id, thread_id, self.nanos_since_start());
8989

@@ -96,7 +96,7 @@ impl<S: SerializationSink> Profiler<S> {
9696
&'a self,
9797
event_kind: StringId,
9898
event_id: StringId,
99-
thread_id: u64,
99+
thread_id: u32,
100100
) -> TimingGuard<'a, S> {
101101
TimingGuard {
102102
profiler: self,
@@ -136,7 +136,7 @@ pub struct TimingGuard<'a, S: SerializationSink> {
136136
profiler: &'a Profiler<S>,
137137
event_id: StringId,
138138
event_kind: StringId,
139-
thread_id: u64,
139+
thread_id: u32,
140140
start_ns: u64,
141141
}
142142

0 commit comments

Comments
 (0)