Skip to content

Commit

Permalink
keep storing capture stacks in tmp but increment last directory
Browse files Browse the repository at this point in the history
  • Loading branch information
dshulyak committed Sep 5, 2024
1 parent 74a1654 commit 2b381d4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion stacks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plain = "0.2"
tracing = "0.1.40"
tracing-stacks = { path = "../tracing-stacks" }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
clap = { version = "4.5.4", features = ["derive"] }
clap = { version = "4.5.4", features = ["derive", "string"] }
blazesym = { git = "https://github.com/dshulyak/blazesym.git", branch = "v0.2.0-alpha.12-caching" }
humantime = "2.1"
bytemuck = "1.16.1"
Expand Down
26 changes: 24 additions & 2 deletions stacks/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{
cell::RefCell,
collections::HashSet,
fs,
env, fs,
io::Read,
path::{Path, PathBuf},
sync::{
Expand Down Expand Up @@ -41,6 +41,28 @@ mod tests;

const DEFAULT_PROGRAMS: &str = "profile:u:99,rss:u:29,switch:k";

fn default_path() -> PathBuf {
let dir_wo_index = env::temp_dir().join("stacks");
// go over all subdirectories, try to parse them as numbers pick 0 or last + 1
let mut next = 0;
if let Ok(entries) = fs::read_dir(&dir_wo_index) {
for entry in entries {
let entry = entry.expect("unable to read entry");
let path = entry.path();
if path.is_dir() {
if let Some(name) = path.file_name() {
if let Some(name) = name.to_str() {
if let Ok(index) = name.parse::<u32>() {
next = next.max(index + 1);
}
}
}
}
}
}
dir_wo_index.join(next.to_string())
}

#[derive(Debug, Parser)]
struct Opt {
#[clap(
Expand All @@ -49,7 +71,7 @@ struct Opt {
)]
commands: Vec<String>,

#[clap(short, long, default_value = "/tmp/stacks/")]
#[clap(short, long, default_value = default_path().into_os_string())]
dir: PathBuf,

#[clap(long, default_value = "STACKS")]
Expand Down
2 changes: 1 addition & 1 deletion stacksexport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
anyhow = "1.0.86"
clap = { version = "4.5.4", features = ["derive"] }
clap = { version = "4.5.4", features = ["derive", "string"] }
datafusion = "38.0.0"
parquet = "51.0.0"
tokio = { version = "1.35.1", features = ["full", "macros"] }
Expand Down
25 changes: 23 additions & 2 deletions stacksexport/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{path::PathBuf, str};
use std::{env, fs, path::PathBuf, str};

use anyhow::{Context, Result};
use clap::Parser;
Expand All @@ -9,11 +9,32 @@ mod common;
mod pprof;
mod trace;

fn default_register_path() -> PathBuf {
let dir_wo_index = env::temp_dir().join("stacks");
let mut next = 0;
if let Ok(entries) = fs::read_dir(&dir_wo_index) {
for entry in entries {
let entry = entry.expect("unable to read entry");
let path = entry.path();
if path.is_dir() {
if let Some(name) = path.file_name() {
if let Some(name) = name.to_str() {
if let Ok(index) = name.parse::<u32>() {
next = next.max(index);
}
}
}
}
}
}
dir_wo_index.join(next.to_string())
}

#[derive(Parser)]
struct Opt {
#[clap(subcommand)]
cmd: Command,
#[clap(short, long, global = true, default_value = "/tmp/stacks/STACKS-*.parquet")]
#[clap(short, long, global = true, default_value = default_register_path().into_os_string())]
register: String,
#[clap(short, long, global = true, help = "print version and exit")]
version: bool,
Expand Down

0 comments on commit 2b381d4

Please sign in to comment.