Skip to content

Commit

Permalink
Store vDSO elf in the cache dir
Browse files Browse the repository at this point in the history
Test Plan
=========

```
$ ls /tmp/lightswitch
dumped-vdso  unwind-info
```
  • Loading branch information
javierhonduco committed Jan 16, 2025
1 parent 2f3933f commit bbda75d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::mem::ManuallyDrop;
use std::mem::MaybeUninit;
use std::os::fd::{AsFd, AsRawFd};
use std::os::unix::fs::FileExt;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::thread;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -82,6 +82,7 @@ impl NativeUnwindState {
}

pub struct Profiler {
cache_dir: PathBuf,
// Prevent the links from being removed.
_links: Vec<Link>,
native_unwinder_open_object: ManuallyDrop<Box<MaybeUninit<OpenObject>>>,
Expand Down Expand Up @@ -193,6 +194,7 @@ fn fetch_vdso_info(
start_addr: u64,
end_addr: u64,
offset: u64,
cache_dir: &Path,
) -> Result<(PathBuf, ObjectFile)> {
// Read raw memory
let file = fs::File::open(format!("/proc/{}/mem", pid))?;
Expand All @@ -201,7 +203,7 @@ fn fetch_vdso_info(
file.read_exact_at(&mut buf, start_addr + offset)?;

// Write to a temporary place
let dumped_vdso = PathBuf::from("/tmp/lightswitch-dumped-vdso");
let dumped_vdso = cache_dir.join("dumped-vdso");
fs::write(&dumped_vdso, &buf)?;

// Pass that to the object parser
Expand Down Expand Up @@ -387,6 +389,7 @@ impl Profiler {
let profile_receive = Arc::new(receiver);

Profiler {
cache_dir: profiler_config.cache_dir,
_links: Vec::new(),
native_unwinder_open_object,
native_unwinder,
Expand Down Expand Up @@ -1674,9 +1677,13 @@ impl Profiler {
// be careful, the kernel might be upgraded since last time we ran, and that cache might not be
// valid anymore.

if let Ok((vdso_path, object_file)) =
fetch_vdso_info(pid, map.address.0, map.address.1, map.offset)
{
if let Ok((vdso_path, object_file)) = fetch_vdso_info(
pid,
map.address.0,
map.address.1,
map.offset,
&self.cache_dir,
) {
let mut object_files = object_files_clone.write();
let Ok(executable_id) = object_file.id() else {
debug!("vDSO object file id failed");
Expand Down

0 comments on commit bbda75d

Please sign in to comment.