Function note_str_multi

Source
pub fn note_str_multi(base_task: &str, key: &str, value: &str)
Expand description

Adds a string key-value note to the last event of a task that was called multiple times.

This function adds a string note to a task created with start_multi(). It must be used with the base task name (without the index suffix).

§Arguments

  • base_task - The base name of the task (same as used in start_multi)
  • key - The key for the metadata entry
  • value - The string value to associate with the key

§Panics

  • Panics if the last event was not started
  • Panics if called from a non-main thread

§Thread Safety

  • This function only works in the main thread

§Examples

use altius_benchtools::profiler;
 
profiler::start_multi("batch_job");
profiler::note_str_multi("batch_job", "status", "processing");
// ... process batch ...
profiler::note_str_multi("batch_job", "status", "completed");
profiler::end_multi("batch_job");
Examples found in repository?
examples/how_to_use_profiler.rs (lines 114-118)
102fn global_task_ignore_thread(output_path: &str) {
103    profiler::clear();
104    let thread_num = 3;
105    let sub_task_num = 5;
106    let mut handles = vec![];
107
108    for thread_id in 0..thread_num {
109        let handle = thread::spawn(move || {
110            for task_id in 0..sub_task_num {
111                let seed = thread_id * sub_task_num + task_id;
112                let task_name = format!("task-in-thread-{}", thread_id);
113                profiler::start_multi(task_name.as_str());
114                profiler::note_str_multi(
115                    task_name.as_str(),
116                    "seed",
117                    format!("The seed for this task is {}", seed).as_str(),
118                );
119                expensive_calculation(seed as u128, 10000);
120                profiler::end_multi(task_name.as_str());
121            }
122        });
123        handles.push(handle);
124    }
125
126    for handle in handles {
127        handle.join().unwrap();
128    }
129    profiler::dump_json(output_path);
130}