MCPcopy Create free account
hub / github.com/CodSpeedHQ/codspeed / save_module_artifacts

Function save_module_artifacts

src/executor/memory/module_artifacts.rs:42–81  ·  view source on GitHub ↗

Save the native modules memtrack mapped, per-process perf maps, and JIT unwind data needed for offline stack attribution. The keyed native and JIT files and their `memtrack.metadata` land in `profile_folder`; memtrack's event streams are read from `results_folder`.

(
    profile_folder: &Path,
    results_folder: &Path,
    integration: (String, String),
    bench_pids: &HashSet<pid_t>,
)

Source from the content-addressed store, hash-verified

40/// files and their `memtrack.metadata` land in `profile_folder`; memtrack's
41/// event streams are read from `results_folder`.
42pub async fn save_module_artifacts(
43 profile_folder: &Path,
44 results_folder: &Path,
45 integration: (String, String),
46 bench_pids: &HashSet<pid_t>,
47) -> Result<()> {
48 let mappings = read_mappings(results_folder)?;
49 let pids = mappings
50 .iter()
51 .map(|mapping| mapping.pid)
52 .chain(bench_pids.iter().copied())
53 .collect::<HashSet<_>>();
54 if pids.is_empty() {
55 debug!("No processes recorded, skipping memtrack module artifacts");
56 return Ok(());
57 }
58
59 // Python and Node emit perf maps in /tmp; Python JIT dumps also contain
60 // unwind data needed to walk through interpreter trampolines. They only
61 // add interpreter names, so a failed harvest must not drop native artifacts.
62 if let Err(e) = harvest_perf_maps_for_pids(profile_folder, &pids).await {
63 warn!("Failed to harvest perf maps: {e:#}");
64 }
65 let jit_unwind_data = save_symbols_and_harvest_unwind_data_for_pids(profile_folder, &pids)
66 .await
67 .unwrap_or_else(|e| {
68 warn!("Failed to harvest JIT dumps: {e:#}");
69 HashMap::new()
70 });
71
72 let loaded_modules = loaded_modules_from_mappings(&mappings);
73 debug!(
74 "Extracting artifacts for {} modules from {} mappings",
75 loaded_modules.len(),
76 mappings.len()
77 );
78
79 let saved = save_artifacts(profile_folder, &loaded_modules, &jit_unwind_data);
80 MemtrackMetadata::new(integration, saved.artifacts).save_to(profile_folder)
81}
82
83fn read_mappings(results_folder: &Path) -> Result<Vec<ProcessMapping>> {
84 let suffix = format!(".{}.msgpack", MemtrackArtifact::name());

Calls 7

read_mappingsFunction · 0.85
save_artifactsFunction · 0.85
is_emptyMethod · 0.45
save_toMethod · 0.45

Tested by

no test coverage detected