pub fn note_str(task: &str, key: &str, value: &str)Expand description
Adds a string key-value note to the last event of a task.
This is a convenience wrapper around note() that automatically converts
the string value to a JSON string value.
§Arguments
task- The string identifier of the task to annotatekey- The key for the metadata entryvalue- The string value to associate with the key
§Panics
- Panics if the last event was not started
§Examples
use altius_benchtools::profiler;
profiler::start("request");
profiler::note_str("request", "endpoint", "/api/v1/users");
profiler::note_str("request", "method", "GET");
// ... perform request ...
profiler::end("request");Examples found in repository?
examples/how_to_use_profiler.rs (lines 62-66)
50fn different_task_in_different_threads(output_path: &str) {
51 profiler::clear();
52 let thread_num = 3;
53 let sub_task_num = 5;
54 let mut handles = vec![];
55
56 for thread_id in 0..thread_num {
57 let handle = thread::spawn(move || {
58 for task_id in 0..sub_task_num {
59 let seed = thread_id * sub_task_num + task_id;
60 let task_name = format!("task-{}-{}", thread_id, task_id);
61 profiler::start(task_name.as_str());
62 profiler::note_str(
63 task_name.as_str(),
64 "extra-descreption",
65 format!("You can add any extra description here for {}", task_name).as_str(),
66 );
67 expensive_calculation(seed as u128, 10000);
68 profiler::end(task_name.as_str());
69 }
70 });
71 handles.push(handle);
72 }
73
74 for handle in handles {
75 handle.join().unwrap();
76 }
77 profiler::dump_json(output_path);
78}