Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions crates/op/host-op-perf/src/convert/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ use std::io;
use perf_event_rs::{
EventScope as RawEvScope, config,
config::{Cpu as RawCpu, Process as RawProcess},
counting::{Config as RawConfig, Counter, CounterStat, ExtraConfig as RawExtraConfig},
counting::{Config as RawConfig, Counter, CounterStat, ExtraConfig as CountExtraConfig},
event::Event as RawEv,
sampling::ExtraConfig as SampleExtraConfig,
};

use crate::convert::{Error, Wrap};
use crate::{
convert::{Error, Wrap},
profiling::perf::config::OverflowBy,
};

type FromT = crate::profiling::perf::config::Config;
type IntoT = perf_event_rs::counting::Config;
Expand All @@ -36,8 +40,38 @@ impl TryFrom<&FromT> for Wrap<IntoT> {
.map(|it| Wrap::<RawEvScope>::from(it).into_inner())
.collect();
let event = Wrap::<RawEv>::try_from(&value.event)?.into_inner();
let extra_config = Wrap::<RawExtraConfig>::try_from(&value.extra_config)?.into_inner();
let extra_config = Wrap::<CountExtraConfig>::try_from(&value.extra_config)?.into_inner();

Ok(Self(RawConfig::extra_new(&event, &scopes, &extra_config)))
}
}

impl TryInto<perf_event_rs::sampling::Config> for crate::profiling::perf::config::SamplingConfig {
type Error = Error;

fn try_into(self) -> Result<perf_event_rs::sampling::Config, Self::Error> {
let scopes: Vec<_> = self
.scopes
.iter()
.map(|it| Wrap::<RawEvScope>::from(it).into_inner())
.collect();
let event = Wrap::<RawEv>::try_from(&self.event)?.into_inner();
Ok(perf_event_rs::sampling::Config::extra_new(
&event,
&scopes,
&self.overflow_by.into(),
&self.extra_config.into(),
))
}
}

type HostOverflowBy = perf_event_rs::sampling::OverflowBy;

impl From<OverflowBy> for HostOverflowBy {
fn from(val: OverflowBy) -> Self {
match val {
OverflowBy::Period(p) => Self::Period(p),
OverflowBy::Freq(f) => Self::Freq(f),
}
}
}
131 changes: 131 additions & 0 deletions crates/op/host-op-perf/src/convert/extra_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
// see <https://www.gnu.org/licenses/>.

use crate::convert::Wrap;
use crate::profiling::perf;
use crate::profiling::perf::config::{
ClockId, SampleIpSkid, SampleRecordFields, Wakeup, WeightRepr,
};

type FromT = crate::profiling::perf::config::ExtraConfig;
type IntoT = perf_event_rs::counting::ExtraConfig;
Expand Down Expand Up @@ -42,3 +46,130 @@ impl TryFrom<&FromT> for Wrap<IntoT> {
Ok(Self(val))
}
}

impl From<crate::profiling::perf::config::SamplingExtraConfig>
for perf_event_rs::sampling::ExtraConfig
{
fn from(val: crate::profiling::perf::config::SamplingExtraConfig) -> Self {
Self {
pinned: val.pinned,
exclusive: val.exclusive,
mmap_data: val.mmap_data,
comm: val.comm,
comm_exec: val.comm_exec,
inherit: val.inherit,
inherit_stat: val.inherit_stat,
inherit_thread: val.inherit_thread,
build_id: val.build_id,
enable_on_exec: val.enable_on_exec,
remove_on_exec: val.remove_on_exec,
include_callchain_kernel: val.include_callchain_kernel,
include_callchain_user: val.include_callchain_user,
clockid: val.clockid.map(Into::into),
precise_ip: val.precise_ip.into(),
wakeup: val.wakeup.into(),
sigtrap: val.sigtrap,
sample_record_fields: val.sample_record_fields.into(),
extra_record_types: val.extra_record_types.into_iter().map(Into::into).collect(),
extra_record_with_sample_id: val.extra_record_with_sample_id,
}
}
}

type HostExtraRecord = perf_event_rs::sampling::ExtraRecord;

impl From<crate::profiling::perf::config::ExtraRecord> for HostExtraRecord {
fn from(val: crate::profiling::perf::config::ExtraRecord) -> Self {
match val {
perf::config::ExtraRecord::Mmap => Self::Mmap,
perf::config::ExtraRecord::Mmap2 => Self::Mmap2,
perf::config::ExtraRecord::ContextSwitch => Self::ContextSwitch,
perf::config::ExtraRecord::Namespaces => Self::Namespaces,
perf::config::ExtraRecord::Ksymbol => Self::Ksymbol,
perf::config::ExtraRecord::BpfEvent => Self::BpfEvent,
perf::config::ExtraRecord::Cgroup => Self::Cgroup,
perf::config::ExtraRecord::TextPoke => Self::TextPoke,
perf::config::ExtraRecord::ForkAndExit => Self::ForkAndExit,
}
}
}

type HostWeightRepr = perf_event_rs::sampling::record::sample::WeightRepr;

impl From<WeightRepr> for HostWeightRepr {
fn from(val: WeightRepr) -> Self {
match val {
WeightRepr::Full => Self::Full,
WeightRepr::Vars => Self::Vars,
}
}
}

type HostSampleRecordFields = perf_event_rs::sampling::SampleRecordFields;

impl From<SampleRecordFields> for HostSampleRecordFields {
fn from(val: SampleRecordFields) -> Self {
HostSampleRecordFields {
sample_id: val.sample_id,
ip: val.ip,
pid_and_tid: val.pid_and_tid,
time: val.time,
addr: val.addr,
id: val.id,
stream_id: val.stream_id,
cpu: val.cpu,
period: val.period,
v: val.v,
ips: val.ips,
data_raw: val.data_raw,
abi_and_regs_user: val.abi_and_regs_user,
data_stack_user: val.data_stack_user,
weight: val.weight.map(Into::into),
data_src: val.data_src,
transaction: val.transaction,
abi_and_regs_intr: val.abi_and_regs_intr,
phys_addr: val.phys_addr,
cgroup: val.cgroup,
data_page_size: val.data_page_size,
code_page_size: val.code_page_size,
}
}
}

type HostWakeup = perf_event_rs::sampling::Wakeup;

impl From<Wakeup> for HostWakeup {
fn from(val: Wakeup) -> Self {
match val {
Wakeup::Events(e) => Self::Events(e),
Wakeup::Watermark(w) => Self::Watermark(w),
}
}
}

type HostSampleIpSkid = perf_event_rs::sampling::SampleIpSkid;

impl From<SampleIpSkid> for HostSampleIpSkid {
fn from(val: SampleIpSkid) -> Self {
match val {
SampleIpSkid::Arbitrary => Self::Arbitrary,
SampleIpSkid::Constant => Self::Constant,
SampleIpSkid::TryZero => Self::TryZero,
SampleIpSkid::Zero => Self::Zero,
}
}
}

type HostClockId = perf_event_rs::sampling::ClockId;

impl From<ClockId> for HostClockId {
fn from(val: ClockId) -> Self {
match val {
ClockId::Monotonic => Self::Monotonic,
ClockId::MonotonicRaw => Self::MonotonicRaw,
ClockId::RealTime => Self::RealTime,
ClockId::BootTime => Self::BootTime,
ClockId::Tai => Self::Tai,
}
}
}
1 change: 1 addition & 0 deletions crates/op/host-op-perf/src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod event;
mod event_scope;
mod extra_config;
mod process;
mod sample_record;
mod stat;

pub use config::*;
Expand Down
Loading
Loading