-
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.
Merge pull request #181 from michaelwoerister/decodeme-v10
Introduce decodeme crate and start supporting old file format versions.
- Loading branch information
Showing
30 changed files
with
532 additions
and
301 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
members = [ | ||
"analyzeme", | ||
"crox", | ||
"decodeme", | ||
"flamegraph", | ||
"measureme", | ||
"mmview", | ||
|
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 |
---|---|---|
@@ -1,14 +1,19 @@ | ||
[package] | ||
name = "analyzeme" | ||
version = "9.1.2" | ||
version = "10.0.0-alpha" | ||
authors = ["Wesley Wiser <wwiser@gmail.com>", "Michael Woerister <michaelwoerister@posteo>"] | ||
edition = "2018" | ||
license = "MIT OR Apache-2.0" | ||
|
||
[dependencies] | ||
byteorder = "1.2.7" | ||
decodeme = { path = "../decodeme" } | ||
memchr = "2" | ||
measureme = { path = "../measureme" } | ||
rustc-hash = "1.0.1" | ||
serde = { version = "1.0", features = [ "derive" ] } | ||
serde_json = "1.0" | ||
|
||
# Depending on older versions of this crate allows us to keep supporting older | ||
# file formats. | ||
analyzeme_9_2_0 = { package = "analyzeme", git = "https://github.com/rust-lang/measureme", tag = "9.2.0" } |
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,78 @@ | ||
//! This module implements file loading for the v7 file format used until | ||
//! crate version 9.2.0 | ||
|
||
use std::error::Error; | ||
|
||
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>) -> 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(&self, event_index: usize) -> Event<'_> { | ||
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(&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 = decodeme::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(&self, event_index: usize) -> Event<'_> { | ||
self.decode_full_event(event_index) | ||
} | ||
|
||
fn decode_lightweight_event(&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 was deleted.
Oops, something went wrong.
Oops, something went wrong.