Skip to content

Commit

Permalink
Merge pull request #181 from michaelwoerister/decodeme-v10
Browse files Browse the repository at this point in the history
Introduce decodeme crate and start supporting old file format versions.
  • Loading branch information
wesleywiser authored Sep 15, 2021
2 parents b9cccd7 + 23ae11d commit 47eb7c8
Show file tree
Hide file tree
Showing 30 changed files with 532 additions and 301 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## [10.0.0] - 2021-09-xx

### Changed
- `analyzeme`: Version-specific parts split out into `decodeme` crate. ([GH-181])
- `analyzeme`: The crate now supports load both v7 and v8 of the file format. ([GH-181])

## [9.2.0] - 2021-09-13
### Changed
- `analyzeme`: Makes a couple of methods in ProfilingData public. ([GH-180])

## [9.1.2] - 2021-05-21
### Added
- `measureme`: Allow recording interval events without using the drop guard ([GH-159])
Expand Down Expand Up @@ -92,6 +102,7 @@

## [0.2.0] - 2019-04-10

[9.2.0]: https://github.com/rust-lang/measureme/releases/tag/9.2.0
[9.1.2]: https://github.com/rust-lang/measureme/releases/tag/9.1.2
[9.1.1]: https://github.com/rust-lang/measureme/releases/tag/9.1.1
[9.1.0]: https://github.com/rust-lang/measureme/releases/tag/9.1.0
Expand Down Expand Up @@ -143,3 +154,5 @@
[GH-155]: https://github.com/rust-lang/measureme/pull/155
[GH-156]: https://github.com/rust-lang/measureme/pull/156
[GH-159]: https://github.com/rust-lang/measureme/pull/159
[GH-180]: https://github.com/rust-lang/measureme/pull/180
[GH-181]: https://github.com/rust-lang/measureme/pull/181
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
members = [
"analyzeme",
"crox",
"decodeme",
"flamegraph",
"measureme",
"mmview",
Expand Down
7 changes: 6 additions & 1 deletion analyzeme/Cargo.toml
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" }
15 changes: 15 additions & 0 deletions analyzeme/src/file_formats/mod.rs
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;
}
78 changes: 78 additions & 0 deletions analyzeme/src/file_formats/v7.rs
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),
}
}
26 changes: 26 additions & 0 deletions analyzeme/src/file_formats/v8.rs
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)
}
}
12 changes: 4 additions & 8 deletions analyzeme/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@
//! To retrieve an `Iterator` of all of the events in the file,
//! call the [`ProfilingData::iter()`] method.

mod event;
mod event_payload;
mod lightweight_event;
mod file_formats;
mod profiling_data;
mod stack_collapse;
mod stringtable;
pub mod testing_common;

pub use crate::event::Event;
pub use crate::event_payload::{EventPayload, Timestamp};
pub use crate::lightweight_event::LightweightEvent;
pub use crate::profiling_data::{ProfilingData, ProfilingDataBuilder};
pub use crate::stack_collapse::collapse_stacks;
pub use crate::stringtable::{StringRef, StringTable};
pub use decodeme::event::Event;
pub use decodeme::event_payload::{EventPayload, Timestamp};
pub use decodeme::lightweight_event::LightweightEvent;
84 changes: 0 additions & 84 deletions analyzeme/src/lightweight_event.rs

This file was deleted.

Loading

0 comments on commit 47eb7c8

Please sign in to comment.