Skip to content

Commit

Permalink
simplify resource keys
Browse files Browse the repository at this point in the history
  • Loading branch information
piotmag769 committed Feb 29, 2024
1 parent 6fa3f15 commit 0bbb514
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions crates/profiler/src/trace_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::profile_builder::perftools::profiles::ValueType;
use crate::profile_builder::{ProfilerContext, StringId};
use trace_data::{ContractAddress, EntryPointSelector};

use trace_data::{CallTrace, DeprecatedSyscallSelector, ExecutionResources};
use trace_data::{CallTrace, ExecutionResources};

#[derive(Clone, Hash, Eq, PartialEq)]
pub struct FunctionName(pub String);
Expand Down Expand Up @@ -126,27 +126,17 @@ pub fn collect_samples_from_trace(trace: &CallTrace) -> Vec<Sample> {
}

pub struct ResourcesKeys {
pub builtins: HashSet<String>,
pub syscalls: HashSet<DeprecatedSyscallSelector>,
pub keys: HashSet<String>,
}

impl ResourcesKeys {
pub fn measurement_types(&self, context: &mut ProfilerContext) -> Vec<ValueType> {
let mut value_types = vec![];

for builtin in &self.builtins {
let unit_string = " ".to_string().add(&builtin.replace('_', " "));
for key in &self.keys {
let unit_string = " ".to_string().add(&key.replace('_', " "));
value_types.push(ValueType {
r#type: context.string_id(builtin).into(),
unit: context.string_id(&unit_string).into(),
});
}
for syscall in &self.syscalls {
let type_string = format!("{syscall:?}");
let unit_string = " ".to_string().add(&type_string);

value_types.push(ValueType {
r#type: context.string_id(&type_string).into(),
r#type: context.string_id(key).into(),
unit: context.string_id(&unit_string).into(),
});
}
Expand All @@ -156,20 +146,25 @@ impl ResourcesKeys {
}

pub fn collect_resources_keys(samples: &[Sample]) -> ResourcesKeys {
let mut syscalls = HashSet::new();
let mut builtins = HashSet::new();
let mut keys = HashSet::new();
for sample in samples {
builtins.extend(
keys.extend(
sample
.flat_resources
.vm_resources
.builtin_instance_counter
.keys()
.cloned(),
);
syscalls.extend(sample.flat_resources.syscall_counter.keys());
keys.extend(
sample
.flat_resources
.syscall_counter
.keys()
.map(|x| format!("{x:?}")),
);
}
ResourcesKeys { builtins, syscalls }
ResourcesKeys { keys }
}

fn collect_samples<'a>(
Expand Down

0 comments on commit 0bbb514

Please sign in to comment.