-
Notifications
You must be signed in to change notification settings - Fork 51
Introduce decodeme crate and start supporting old file format versions. #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
834f5ea
Remove reference to ProfilingData from LightweightEvent.
michaelwoerister c512eeb
Factor encoding-specific parts out of analyzeme into a new crate 'dec…
michaelwoerister 5ff7e7e
Add support for reading file format version 7.
michaelwoerister e8083fb
Address review comments
michaelwoerister 7356989
update changelog
michaelwoerister e819fdb
Fix release date
wesleywiser ac60c6b
Update changelog for 10.0.0-alpha
michaelwoerister 23ae11d
Let file format error message mention that upgrading to newer version
michaelwoerister File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.