Skip to content

Commit

Permalink
scxtop: Cleanup event intialization
Browse files Browse the repository at this point in the history
Cleanup initialization of cpu, node and llc data when intializing
events.

Signed-off-by: Daniel Hodges <[email protected]>
  • Loading branch information
hodgesds committed Jan 18, 2025
1 parent 8776d1b commit d4ff4f1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
14 changes: 9 additions & 5 deletions tools/scxtop/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,28 @@ impl<'a> App<'a> {
let mut active_perf_events = BTreeMap::new();
let active_hw_event = PerfEvent::new("hw".to_string(), "cycles".to_string(), 0);
let available_perf_events = available_perf_events()?;
let available_events = PerfEvent::default_events();
let default_events = PerfEvent::default_events();
let default_events_str = default_events
.iter()
.map(|event| event.event.clone())
.collect::<Vec<String>>();
for cpu in topo.all_cpus.values() {
let mut event = PerfEvent::new("hw".to_string(), "cycles".to_string(), cpu.id);
event.attach()?;
active_perf_events.insert(cpu.id, event);
let mut data =
CpuData::new(cpu.id, cpu.core_id, cpu.llc_id, cpu.node_id, max_cpu_events);
data.add_event_data(active_hw_event.event.clone(), 0);
data.initialize_events(&default_events_str);
cpu_data.insert(cpu.id, data);
}
for llc in topo.all_llcs.values() {
let mut data = LlcData::new(llc.id, llc.node_id, max_cpu_events);
data.add_event_data(active_hw_event.event.clone(), 0);
data.initialize_events(&default_events_str);
llc_data.insert(llc.id, data);
}
for node in topo.nodes.values() {
let mut data = NodeData::new(node.id, max_cpu_events);
data.add_event_data(active_hw_event.event.clone(), 0);
data.initialize_events(&default_events_str);
node_data.insert(node.id, data);
}

Expand Down Expand Up @@ -143,7 +147,7 @@ impl<'a> App<'a> {
active_hw_event,
available_perf_events,
active_perf_events,
available_events,
available_events: default_events,
};

Ok(app)
Expand Down
4 changes: 1 addition & 3 deletions tools/scxtop/src/cpu_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ impl CpuData {

/// Initializes events with default values.
pub fn initialize_events(&mut self, events: &Vec<String>) {
for event in events {
self.data.event_data(event.to_string());
}
self.data.initialize_events(&events);
}

/// Returns the data for an event and updates if no entry is present.
Expand Down
4 changes: 1 addition & 3 deletions tools/scxtop/src/llc_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ impl LlcData {

/// Initializes events with default values.
pub fn initialize_events(&mut self, events: &Vec<String>) {
for event in events {
self.data.event_data(event.to_string());
}
self.data.initialize_events(&events);
}

/// Returns the data for an event and updates if no entry is present.
Expand Down
4 changes: 1 addition & 3 deletions tools/scxtop/src/node_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ impl NodeData {

/// Initializes events with default values.
pub fn initialize_events(&mut self, events: &Vec<String>) {
for event in events {
self.data.event_data(event.to_string());
}
self.data.initialize_events(&events);
}

/// Returns the data for an event and updates if no entry is present.
Expand Down

0 comments on commit d4ff4f1

Please sign in to comment.