Commit 367c8b2
feat(common): add current thread id API (#1569)
# What does this PR do?
Adds a new public helper API, `libdd_common::threading::get_current_thread_id() -> i64`,
with platform-specific implementations for Linux, macOS, and Windows.
It updates `libdd-profiling`'s `add_samples` benchmark to always include a numeric `"thread id"`
label in both `try_add_sample` and `try_add_sample2` paths.
# Motivation
This PR improves the `add_samples` benchmark because in the future I want to modify the
internals of our implementation, and I want labels to be represented in the benchmark.
@gyuheon0h asked for it to be in common so it could be used in other places as well. This is fine with me, as long as we keep the i64 representation for profiling.
# Additional Notes
Supported implementations:
- Linux: `syscall(SYS_gettid)`, since `gettid()` does not exist on older glibc versions.
- macOS: `pthread_threadid_np`
- Windows: `GetCurrentThreadId` via `windows-sys`
Unsupported platforms fail at compile time via `compile_error!`.
# How to test the change?
1. Check out branch `pr1/add-samples-benchmark`.
2. Run compile checks:
- `cargo check -p libdd-common`
- `cargo check -p libdd-profiling`
- `cargo check -p libdd-profiling --benches`
3. Run benchmark:
- `cargo bench -p libdd-profiling --bench main -- add_sample --noplot`
4. Confirm:
- benchmark runs successfully
- `add_samples` includes `"thread id"` labels for both legacy and api2 benchmark loops
Co-authored-by: gyuheon.oh <[email protected]>1 parent 8a6d94b commit 367c8b2
File tree
4 files changed
+50
-5
lines changed- libdd-common
- src
- libdd-profiling/benches
4 files changed
+50
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | | - | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
106 | 115 | | |
107 | 116 | | |
108 | 117 | | |
| |||
127 | 136 | | |
128 | 137 | | |
129 | 138 | | |
130 | | - | |
| 139 | + | |
131 | 140 | | |
132 | 141 | | |
133 | 142 | | |
| |||
145 | 154 | | |
146 | 155 | | |
147 | 156 | | |
148 | | - | |
149 | | - | |
| 157 | + | |
150 | 158 | | |
151 | 159 | | |
152 | 160 | | |
| |||
0 commit comments