-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for reading file format version 7.
- Loading branch information
1 parent
68d0161
commit 14db1f7
Showing
7 changed files
with
216 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use decodeme::{event::Event, lightweight_event::LightweightEvent, Metadata}; | ||
use std::fmt::Debug; | ||
|
||
pub mod v7; | ||
pub mod v8; | ||
|
||
pub use v8 as current; | ||
|
||
/// The [EventDecoder] knows how to decode events for a specific file format. | ||
pub trait EventDecoder: Debug + Send + Sync { | ||
fn num_events(&self) -> usize; | ||
fn metadata(&self) -> &Metadata; | ||
fn decode_full_event<'a>(&'a self, event_index: usize) -> Event<'a>; | ||
fn decode_lightweight_event<'a>(&'a self, event_index: usize) -> LightweightEvent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
//! This module implements file loading for the v7 file format used until | ||
//! crate version 9.2.0 | ||
|
||
use std::{error::Error, path::Path}; | ||
|
||
use analyzeme_9_2_0::ProfilingData; | ||
use decodeme::{ | ||
event::Event, | ||
event_payload::{EventPayload, Timestamp}, | ||
lightweight_event::LightweightEvent, | ||
Metadata, | ||
}; | ||
|
||
pub const FILE_FORMAT: u32 = analyzeme_9_2_0::CURRENT_FILE_FORMAT_VERSION; | ||
|
||
#[derive(Debug)] | ||
pub struct EventDecoder { | ||
legacy_profiling_data: ProfilingData, | ||
metadata: Metadata, | ||
} | ||
|
||
impl EventDecoder { | ||
pub fn new( | ||
entire_file_data: Vec<u8>, | ||
_diagnostic_file_path: Option<&Path>, | ||
) -> Result<EventDecoder, Box<dyn Error + Send + Sync>> { | ||
let legacy_profiling_data = ProfilingData::from_paged_buffer(entire_file_data)?; | ||
|
||
let metadata = Metadata { | ||
start_time: legacy_profiling_data.metadata.start_time, | ||
cmd: legacy_profiling_data.metadata.cmd.clone(), | ||
process_id: legacy_profiling_data.metadata.process_id, | ||
}; | ||
|
||
Ok(EventDecoder { | ||
legacy_profiling_data, | ||
metadata, | ||
}) | ||
} | ||
} | ||
|
||
impl super::EventDecoder for EventDecoder { | ||
fn num_events(&self) -> usize { | ||
self.legacy_profiling_data.num_events() | ||
} | ||
|
||
fn metadata(&self) -> &Metadata { | ||
&self.metadata | ||
} | ||
|
||
fn decode_full_event<'a>(&'a self, event_index: usize) -> Event<'a> { | ||
let legacy_event = self.legacy_profiling_data.decode_full_event(event_index); | ||
let timestamp = convert_timestamp(legacy_event.timestamp); | ||
|
||
Event { | ||
event_kind: legacy_event.event_kind, | ||
label: legacy_event.label, | ||
additional_data: legacy_event.additional_data, | ||
thread_id: legacy_event.thread_id, | ||
payload: EventPayload::Timestamp(timestamp), | ||
} | ||
} | ||
|
||
fn decode_lightweight_event<'a>(&'a self, event_index: usize) -> LightweightEvent { | ||
let legacy_event = self | ||
.legacy_profiling_data | ||
.decode_lightweight_event(event_index); | ||
LightweightEvent { | ||
event_index, | ||
thread_id: legacy_event.thread_id, | ||
payload: EventPayload::Timestamp(convert_timestamp(legacy_event.timestamp)), | ||
} | ||
} | ||
} | ||
|
||
fn convert_timestamp(legacy_timestamp: analyzeme_9_2_0::Timestamp) -> Timestamp { | ||
match legacy_timestamp { | ||
analyzeme_9_2_0::Timestamp::Interval { start, end } => Timestamp::Interval { start, end }, | ||
analyzeme_9_2_0::Timestamp::Instant(t) => Timestamp::Instant(t), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//! This module implements file loading for the v8 file format used until | ||
//! crate version 10.0.0 | ||
|
||
use crate::{Event, LightweightEvent}; | ||
pub use decodeme::EventDecoder; | ||
use decodeme::Metadata; | ||
|
||
pub const FILE_FORMAT: u32 = measureme::file_header::CURRENT_FILE_FORMAT_VERSION; | ||
|
||
impl super::EventDecoder for EventDecoder { | ||
fn num_events(&self) -> usize { | ||
self.num_events() | ||
} | ||
|
||
fn metadata(&self) -> &Metadata { | ||
self.metadata() | ||
} | ||
|
||
fn decode_full_event<'a>(&'a self, event_index: usize) -> Event<'a> { | ||
self.decode_full_event(event_index) | ||
} | ||
|
||
fn decode_lightweight_event<'a>(&'a self, event_index: usize) -> LightweightEvent { | ||
self.decode_lightweight_event(event_index) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters