Skip to content

Commit 8afb60d

Browse files
feat: restore take_profiling_entries for CuBenchmark consumers
1 parent 69a2259 commit 8afb60d

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

light-program-profiler/src/mollusk.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,42 @@ pub fn take_profiling_results() -> Vec<(String, u64, String)> {
270270
})
271271
}
272272

273+
fn parse_profile_id(id: &str) -> (String, String) {
274+
if let Some(pos) = id.find('\n') {
275+
(id[..pos].to_string(), id[pos + 1..].trim().to_string())
276+
} else {
277+
(id.to_string(), String::new())
278+
}
279+
}
280+
281+
/// Take profiling results as `ProfileEntry` structs with total and net CU.
282+
/// Post-processes to compute net CU (total minus children), then clears state.
283+
#[cfg(feature = "report")]
284+
pub fn take_profiling_entries() -> Vec<crate::report::ProfileEntry> {
285+
PROFILING_STATE.with(|state| {
286+
let mut state = state.borrow_mut();
287+
if state.completed_count() == 0 {
288+
return vec![];
289+
}
290+
state.post_process();
291+
let results = state
292+
.get_completed()
293+
.iter()
294+
.map(|entry| {
295+
let (func_name, file_location) = parse_profile_id(&entry.id);
296+
crate::report::ProfileEntry {
297+
func_name,
298+
file_location,
299+
total_cu: entry.total_cu,
300+
net_cu: entry.net_cu,
301+
}
302+
})
303+
.collect();
304+
state.clear();
305+
results
306+
})
307+
}
308+
273309
// ---------------------------------------------------------------------------
274310
// README generation
275311
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)