Skip to content

Commit

Permalink
Remove duplicated etw_gecko files, move some additional functionality…
Browse files Browse the repository at this point in the history
… into shared
  • Loading branch information
vvuk committed Apr 23, 2024
1 parent 7be5d11 commit efbebef
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 1,449 deletions.
20 changes: 18 additions & 2 deletions samply/src/shared/marker_file.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use fxprof_processed_profile::Timestamp;
use rangemap::RangeSet;

use std::fs::File;
use std::io::{BufRead, BufReader, Lines};
Expand Down Expand Up @@ -59,12 +60,27 @@ impl Iterator for MarkerFile {

pub fn get_markers(
marker_file: &Path,
marker_name_prefix_for_filtering: Option<&str>,
extra_dir: Option<&Path>,
timestamp_converter: TimestampConverter,
) -> Result<Vec<MarkerSpan>, std::io::Error> {
) -> Result<(Vec<MarkerSpan>, Option<RangeSet<Timestamp>>), std::io::Error> {
let (f, _true_path) = open_file_with_fallback(marker_file, extra_dir)?;
let marker_file = MarkerFile::parse(f, timestamp_converter);
let mut marker_spans: Vec<MarkerSpan> = marker_file.collect();
marker_spans.sort_by_key(|m| m.start_time);
Ok(marker_spans)

let sample_ranges = if let Some(prefix) = marker_name_prefix_for_filtering {
let mut sample_ranges = RangeSet::new();
for marker_span in &marker_spans {
if marker_span.name.starts_with(prefix) && marker_span.end_time > marker_span.start_time
{
sample_ranges.insert(marker_span.start_time..marker_span.end_time);
}
}
Some(sample_ranges)
} else {
None
};

Ok((marker_spans, sample_ranges))
}
46 changes: 45 additions & 1 deletion samply/src/shared/process_sample_data.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use rangemap::RangeSet;
use fxprof_processed_profile::{
CategoryHandle, CategoryPairHandle, LibMappings, MarkerDynamicField, MarkerFieldFormat,
MarkerLocation, MarkerSchema, MarkerSchemaField, MarkerStaticField, MarkerTiming, Profile,
ProfilerMarker, ThreadHandle, Timestamp,
};

use serde_json::json;

use super::{
Expand Down Expand Up @@ -71,6 +73,7 @@ impl ProcessSampleData {
stack_frame_scratch_buf: &mut Vec<StackFrame>,
stacks: &UnresolvedStacks,
event_names: &[String],
sample_range_set: Option<&RangeSet<Timestamp>>,
) {
let ProcessSampleData {
unresolved_samples,
Expand Down Expand Up @@ -99,6 +102,12 @@ impl ProcessSampleData {
..
} = sample;

if sample_range_set.is_some()
&& !sample_range_set.as_ref().unwrap().contains(&timestamp)
{
continue;
}

stack_frame_scratch_buf.clear();
stacks.convert_back(stack, stack_frame_scratch_buf);
let frames = stack_converter.convert_stack(
Expand Down Expand Up @@ -230,12 +239,47 @@ impl ProfilerMarker for OtherEventMarker {
}
}
}
#[derive(Debug, Clone)]
pub struct UserTimingMarker(pub String);

impl ProfilerMarker for UserTimingMarker {
const MARKER_TYPE_NAME: &'static str = "UserTiming";

fn json_marker_data(&self) -> serde_json::Value {
json!({
"type": Self::MARKER_TYPE_NAME,
"name": self.0,
})
}

fn schema() -> MarkerSchema {
MarkerSchema {
type_name: Self::MARKER_TYPE_NAME,
locations: vec![MarkerLocation::MarkerChart, MarkerLocation::MarkerTable],
chart_label: Some("{marker.data.name}"),
tooltip_label: Some("{marker.data.name}"),
table_label: Some("{marker.data.name}"),
fields: vec![
MarkerSchemaField::Dynamic(MarkerDynamicField {
key: "name",
label: "Name",
format: MarkerFieldFormat::String,
searchable: true,
}),
MarkerSchemaField::Static(MarkerStaticField {
label: "Description",
value: "Emitted for performance.mark and performance.measure.",
}),
],
}
}
}

#[derive(Debug, Clone)]
pub struct SimpleMarker(pub String);

impl ProfilerMarker for SimpleMarker {
const MARKER_TYPE_NAME: &'static str = "UserTiming";
const MARKER_TYPE_NAME: &'static str = "SimpleMarker";

fn json_marker_data(&self) -> serde_json::Value {
json!({
Expand Down
6 changes: 6 additions & 0 deletions samply/src/shared/timestamp_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ impl TimestampConverter {
ktime_ns.saturating_sub(self.reference_raw) * self.raw_to_ns_factor,
)
}

pub fn convert_us(&self, time_us: u64) -> Timestamp {
Timestamp::from_nanos_since_reference(
(time_us * 1000).saturating_sub(self.reference_raw * self.raw_to_ns_factor),
)
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,66 +1,27 @@
use std::{collections::{HashMap, HashSet, hash_map::Entry, VecDeque}, convert::TryInto, fs::File, io::BufWriter, path::Path, time::{Duration, Instant, SystemTime}, sync::Arc};
use std::process::ExitStatus;

use context_switch::{OffCpuSampleGroup, ThreadContextSwitchData};
use etw_reader::{GUID, open_trace, parser::{Parser, TryParse, Address}, print_property, schema::SchemaLocator, write_property};
use lib_mappings::{LibMappingOpQueue, LibMappingOp, LibMappingAdd};
use super::context_switch::{OffCpuSampleGroup, ThreadContextSwitchData};
use super::etw_reader::{GUID, open_trace, parser::{Parser, TryParse, Address}, print_property, schema::SchemaLocator, write_property};
use crate::shared::lib_mappings::{LibMappingOpQueue, LibMappingOp, LibMappingAdd};
use serde_json::{Value, json, to_writer};
use fxprof_processed_profile::{debugid, CategoryColor, CategoryHandle, CategoryPairHandle, CounterHandle, CpuDelta, FrameFlags, FrameInfo, LibraryHandle, LibraryInfo, MarkerDynamicField, MarkerFieldFormat, MarkerLocation, MarkerSchema, MarkerSchemaField, MarkerTiming, ProcessHandle, Profile, ProfilerMarker, ReferenceTimestamp, SamplingInterval, Symbol, SymbolTable, ThreadHandle, Timestamp};
use debugid::DebugId;
use bitflags::bitflags;


mod context_switch;
mod jit_category_manager;
mod jit_function_add_marker;
mod lib_mappings;
mod marker_file;
mod process_sample_data;
mod stack_converter;
mod stack_depth_limiting_frame_iter;
mod timestamp_converter;
mod types;
mod unresolved_samples;

use jit_category_manager::JitCategoryManager;
use stack_converter::StackConverter;
use lib_mappings::LibMappingInfo;
use types::{StackFrame, StackMode};
use unresolved_samples::{UnresolvedSamples, UnresolvedStacks};
use uuid::Uuid;
use process_sample_data::ProcessSampleData;

use crate::{context_switch::ContextSwitchHandler, jit_function_add_marker::JitFunctionAddMarker, marker_file::get_markers, process_sample_data::UserTimingMarker, timestamp_converter::TimestampConverter};
use crate::shared::jit_category_manager::JitCategoryManager;
use crate::shared::stack_converter::StackConverter;
use crate::shared::lib_mappings::LibMappingInfo;
use crate::shared::types::{StackFrame, StackMode};
use crate::shared::unresolved_samples::{UnresolvedSamples, UnresolvedStacks};
use crate::shared::process_sample_data::ProcessSampleData;

/// An example marker type with some text content.
#[derive(Debug, Clone)]
pub struct TextMarker(pub String);
use super::{context_switch::ContextSwitchHandler};
use crate::shared::{jit_function_add_marker::JitFunctionAddMarker, marker_file::get_markers, process_sample_data::UserTimingMarker, timestamp_converter::TimestampConverter};

impl ProfilerMarker for TextMarker {
const MARKER_TYPE_NAME: &'static str = "Text";

fn json_marker_data(&self) -> serde_json::Value {
json!({
"type": Self::MARKER_TYPE_NAME,
"name": self.0
})
}

fn schema() -> MarkerSchema {
MarkerSchema {
type_name: Self::MARKER_TYPE_NAME,
locations: vec![MarkerLocation::MarkerChart, MarkerLocation::MarkerTable],
chart_label: Some("{marker.data.name}"),
tooltip_label: Some("{marker.data.name}"),
table_label: Some("{marker.name} - {marker.data.name}"),
fields: vec![MarkerSchemaField::Dynamic(MarkerDynamicField {
key: "name",
label: "Name",
format: MarkerFieldFormat::String,
searchable: true,
})],
}
}
}
use crate::server::{start_server_main, ServerProps};
use crate::shared::recording_props::{ProcessLaunchProps, ProfileCreationProps, RecordingProps};

fn is_kernel_address(ip: u64, pointer_size: u32) -> bool {
if pointer_size == 4 {
Expand Down Expand Up @@ -153,6 +114,12 @@ impl ProcessState {
}
}

pub fn start_recording(
process_launch_props: ProcessLaunchProps,
recording_props: RecordingProps,
profile_creation_props: ProfileCreationProps,
server_props: Option<ServerProps>,
) -> Result<ExitStatus, i32> {
fn main() {
let profile_start_instant = Timestamp::from_nanos_since_reference(0);
let profile_start_system = SystemTime::now();
Expand Down
176 changes: 0 additions & 176 deletions samply/src/windows/etw_gecko/jit_category_manager.rs

This file was deleted.

Loading

0 comments on commit efbebef

Please sign in to comment.