|
8 | 8 | #include <chrono> |
9 | 9 | #include <thread> |
10 | 10 |
|
| 11 | +static void simulate_work(int ms) |
| 12 | +{ |
| 13 | + std::this_thread::sleep_for(std::chrono::milliseconds(ms)); |
| 14 | +} |
| 15 | + |
11 | 16 | int main() |
12 | 17 | { |
| 18 | + // Thread naming |
13 | 19 | ittapi::set_thread_name("main"); |
14 | | - ittapi::Domain domain{"example.task"}; |
| 20 | + |
| 21 | + // Domain and string handle creation |
| 22 | + ittapi::Domain domain{"example.app"}; |
15 | 23 | ittapi::StringHandle task_name{"process"}; |
16 | 24 |
|
| 25 | + // Collection control — pause/resume |
17 | 26 | ittapi::pause(); |
18 | 27 | ittapi::resume(); |
19 | 28 |
|
20 | | - |
| 29 | + // Scoped task with pre-created StringHandle (zero-overhead path) |
21 | 30 | { |
22 | 31 | auto task = domain.task(task_name); |
23 | | - std::this_thread::sleep_for(std::chrono::milliseconds(10)); |
| 32 | + simulate_work(10); |
24 | 33 | } |
25 | 34 |
|
26 | | - |
| 35 | + // Scoped task with inline string (convenience path) |
27 | 36 | { |
28 | 37 | auto task = domain.task("startup"); |
29 | | - std::this_thread::sleep_for(std::chrono::milliseconds(10)); |
| 38 | + simulate_work(10); |
| 39 | + } |
| 40 | + |
| 41 | + // Scoped task with early end |
| 42 | + { |
| 43 | + auto task = domain.task("partial_work"); |
| 44 | + simulate_work(5); |
| 45 | + task.end(); // end early, destructor is a no-op |
| 46 | + } |
| 47 | + |
| 48 | + // Scoped task with IDs for parent-child relationships |
| 49 | + { |
| 50 | + __itt_id parent_id = __itt_id_make(nullptr, 1); |
| 51 | + auto parent = domain.task("parent_task", parent_id, __itt_null); |
| 52 | + |
| 53 | + __itt_id child_id = __itt_id_make(nullptr, 2); |
| 54 | + auto child = domain.task("child_task", child_id, parent_id); |
| 55 | + simulate_work(5); |
| 56 | + } |
| 57 | + |
| 58 | + // Manual task begin/end (non-RAII) |
| 59 | + domain.task_begin("manual_work"); |
| 60 | + simulate_work(5); |
| 61 | + domain.task_end(); |
| 62 | + |
| 63 | + // Scoped region |
| 64 | + { |
| 65 | + auto region = domain.region("init_phase"); |
| 66 | + simulate_work(10); |
| 67 | + } |
| 68 | + |
| 69 | + // Scoped frame |
| 70 | + { |
| 71 | + auto frame = domain.frame(); |
| 72 | + simulate_work(10); |
| 73 | + } |
| 74 | + |
| 75 | + // Frame submit with explicit timestamps |
| 76 | + { |
| 77 | + __itt_timestamp begin = __itt_get_timestamp(); |
| 78 | + simulate_work(10); |
| 79 | + __itt_timestamp end = __itt_get_timestamp(); |
| 80 | + ittapi::ScopedFrame::submit(domain.get(), begin, end); |
| 81 | + } |
| 82 | + |
| 83 | + // Scoped pause — collection paused within scope |
| 84 | + { |
| 85 | + ittapi::ScopedPause sp; |
| 86 | + simulate_work(10); // not collected |
| 87 | + sp.resume_now(); // resume early |
| 88 | + simulate_work(10); // collected |
30 | 89 | } |
31 | 90 |
|
32 | 91 | return 0; |
|
0 commit comments