Skip to content

Commit af14e56

Browse files
committed
Add --profile-name to record command
1 parent fc5b14c commit af14e56

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

samply/src/linux/profiler.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub type ConvertRegsNative = crate::linux_shared::ConvertRegsAarch64;
3232
#[allow(clippy::too_many_arguments)]
3333
pub fn start_recording(
3434
output_file: &Path,
35+
profile_name: Option<String>,
3536
command_name: OsString,
3637
command_args: &[OsString],
3738
time_limit: Option<Duration>,
@@ -66,10 +67,9 @@ pub fn start_recording(
6667

6768
// Launch the observer thread. This thread will manage the perf events.
6869
let output_file_copy = output_file.to_owned();
69-
let command_name_copy = command_name.to_string_lossy().to_string();
70+
let product = profile_name.unwrap_or_else(|| command_name.to_string_lossy().to_string());
7071
let conversion_args = conversion_args.clone();
7172
let observer_thread = thread::spawn(move || {
72-
let product = command_name_copy;
7373
let mut converter = make_converter(interval, &product, &conversion_args);
7474

7575
// Wait for the initial pid to profile.
@@ -191,6 +191,7 @@ pub fn start_recording(
191191

192192
pub fn start_profiling_pid(
193193
output_file: &Path,
194+
profile_name: Option<String>,
194195
pid: u32,
195196
time_limit: Option<Duration>,
196197
interval: Duration,
@@ -215,7 +216,7 @@ pub fn start_profiling_pid(
215216
crossbeam_channel::bounded(2);
216217

217218
let output_file_copy = output_file.to_owned();
218-
let product = format!("PID {pid}");
219+
let product = profile_name.unwrap_or_else(|| format!("PID {pid}"));
219220
let conversion_args = conversion_args.clone();
220221
let observer_thread = thread::spawn({
221222
let stop = stop.clone();

samply/src/mac/profiler.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::ConversionArgs;
2222

2323
pub fn start_profiling_pid(
2424
_output_file: &Path,
25+
_profile_name: Option<String>,
2526
_pid: u32,
2627
_time_limit: Option<Duration>,
2728
_interval: Duration,
@@ -36,6 +37,7 @@ pub fn start_profiling_pid(
3637
#[allow(clippy::too_many_arguments)]
3738
pub fn start_recording(
3839
output_file: &Path,
40+
profile_name: Option<String>,
3941
command_name: OsString,
4042
command_args: &[OsString],
4143
time_limit: Option<Duration>,
@@ -47,9 +49,11 @@ pub fn start_recording(
4749
let (task_sender, task_receiver) = unbounded();
4850
let command_name_copy = command_name.to_string_lossy().to_string();
4951
let conversion_args = conversion_args.clone();
52+
let product_name = profile_name.unwrap_or_else(|| command_name_copy.clone());
5053
let sampler_thread = thread::spawn(move || {
5154
let sampler = Sampler::new(
5255
command_name_copy,
56+
product_name,
5357
task_receiver,
5458
interval,
5559
time_limit,

samply/src/mac/sampler.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub struct TaskInit {
2626
}
2727

2828
pub struct Sampler {
29+
product_name: String,
2930
command_name: String,
3031
task_receiver: Receiver<TaskInit>,
3132
interval: Duration,
@@ -37,6 +38,7 @@ pub struct Sampler {
3738
impl Sampler {
3839
pub fn new(
3940
command: String,
41+
product_name: String,
4042
task_receiver: Receiver<TaskInit>,
4143
interval: Duration,
4244
time_limit: Option<Duration>,

samply/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ struct RecordArgs {
9898
#[arg(short, long, default_value = "profile.json")]
9999
output: PathBuf,
100100

101+
/// Overwrite the name shown at the top of the profiler results
102+
/// By default it is either the command that was run or the process pid.
103+
#[arg(long)]
104+
profile_name: Option<String>,
105+
101106
/// How many times to run the profiled command.
102107
#[arg(long, default_value = "1")]
103108
iteration_count: u32,
@@ -191,6 +196,7 @@ fn main() {
191196
if let Some(pid) = record_args.pid {
192197
profiler::start_profiling_pid(
193198
&record_args.output,
199+
record_args.profile_name,
194200
pid,
195201
time_limit,
196202
interval,
@@ -200,6 +206,7 @@ fn main() {
200206
} else {
201207
let exit_status = match profiler::start_recording(
202208
&record_args.output,
209+
record_args.profile_name,
203210
record_args.command[0].clone(),
204211
&record_args.command[1..],
205212
time_limit,

0 commit comments

Comments
 (0)