Skip to content

Commit

Permalink
add trace info to sampling port creation code
Browse files Browse the repository at this point in the history
  • Loading branch information
wucke13 committed Jul 19, 2023
1 parent 2642301 commit 5b3f93f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion partition/src/apex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,23 @@ impl ApexSamplingPortP4 for ApexLinuxPartition {
refresh_period: ApexSystemTime,
) -> Result<SamplingPortId, ErrorReturnCode> {
if refresh_period <= 0 {
trace!("yielding InvalidConfig, because refresh period <= 0");
return Err(ErrorReturnCode::InvalidConfig);
}

let name = Name::new(sampling_port_name);
let name = name.to_str().map_err(|_| ErrorReturnCode::InvalidConfig)?;
let name = name.to_str().map_err(|e| {
trace!("yielding InvalidConfig, because sampling port is not valid UTF-8:\n{e}");
ErrorReturnCode::InvalidConfig
})?;
if let Some((i, s)) = CONSTANTS
.sampling
.iter()
.enumerate()
.find(|(_, s)| s.name.eq(name))
{
if s.dir != port_direction {
trace!("yielding InvalidConfig, because mismatching port direction:\nexpected {:?}, got {port_direction:?}", s.dir);
return Err(ErrorReturnCode::InvalidConfig);
}

Expand All @@ -114,13 +119,18 @@ impl ApexSamplingPortP4 for ApexLinuxPartition {

let mut channels = SAMPLING_PORTS.read().unwrap();
if channels.try_push(ch).is_some() {
trace!(
"yielding InvalidConfig, maximum number of sampling ports already reached: {}",
channels.len()
);
return Err(ErrorReturnCode::InvalidConfig);
}
SAMPLING_PORTS.write(&channels).unwrap();

return Ok(channels.len() as SamplingPortId);
}

trace!("yielding InvalidConfig, configuration does not declare sampling port {name}");
Err(ErrorReturnCode::InvalidConfig)
}

Expand Down

0 comments on commit 5b3f93f

Please sign in to comment.