-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperf.cppm
554 lines (466 loc) · 15.6 KB
/
perf.cppm
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
// <!--
//
// Copyright (c) 2024-2025 Kris Jusiak <[email protected]>
//
// | license | namespace | guard |
// |----------------|----------------|------------------|
// | MIT* | `perf::*` | - |
// | Apache2:LLVM** | `perf::mca::*` | `PERF_LLVM == 1` |
//
// The MIT License (MIT)*
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// See https://opensource.org/license/mit for license information.
//
// Apache License v2.0 with LLVM exceptions**
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
module;
#include <perf>
export module perf;
export namespace perf {
using perf::log;
using perf::verify;
using perf::named;
using perf::scoped;
namespace mp {
using perf::mp::overload;
using perf::mp::unroll;
using perf::mp::for_each;
} // namespace mp
namespace info {
/**
* PERF version
*/
using perf::info::version;
namespace compiler {
using perf::info::compiler::name;
using perf::info::compiler::version;
} // namespace compiler
namespace cpu {
using perf::info::cpu::name;
using perf::info::cpu::code_name;
using perf::info::cpu::version;
using perf::info::cpu::dispatch_width;
using perf::info::cpu::features;
} // namespace cpu
namespace memory {
using perf::info::memory::level;
using perf::info::memory::icache;
using perf::info::memory::dcache;
} // namespace memory
namespace sys {
using perf::info::sys::name;
using perf::info::sys::triple;
using perf::info::sys::page_size;
} // namespace sys
namespace proc::inline self {
using perf::info::proc::self::name;
using perf::info::proc::self::base_address;
} // namespace proc::self
namespace bin {
/**
* Converts address into a file name:line number
*/
using perf::info::bin::addr_to_line;
/**
* Converts address into a function name
*/
using perf::info::bin::addr_to_fn_name;
/**
* Converts address into a name
*/
using perf::info::bin::addr_to_name;
} // namespace bin
} // namespace info
inline namespace core {
namespace code {
/**
* gnu version of `[[clang::code_align(alignment)]]`
*/
using perf::code::align;
/**
* compile-time code label
*/
using perf::code::label;
/**
* loads compile-time code labels
*/
using perf::code::labels;
} // namespace code
namespace compiler {
/**
* prevents memory instructions reorder
*/
using perf::compiler::prevent_reorder;
/**
* prevents elision of given value
*/
using perf::compiler::prevent_elision;
/**
* returns true if given function is elided by the compiler, false otherwise
*/
using perf::compiler::is_elided;
} // namespace compiler
namespace cpu::pipeline {
using perf::cpu::pipeline::flush;
} // namespace cpu::pipeline
namespace memory {
/**
* aligns given pointer to specific alignment and offset
*/
using perf::memory::align;
/**
* returns true if given pointer is aligned to specified alignment
*/
using perf::memory::is_aligned;
/**
* hardware memory barrier (x86: fence or lock)
*/
using perf::memory::fence;
/**
* Prefetches memory from address
*/
using perf::memory::operation;
using perf::memory::locality;
using perf::memory::prefetch;
/**
* Sets protection on a region of memory
*/
using perf::memory::prot;
using perf::memory::protect;
namespace cache {
using perf::memory::cache::flush;
} // namespace cache
namespace heap {
/**
* pollutes heap by making n allocations
*/
using perf::memory::heap::pollute;
} // namespace heap
} // namespace memory
} // namespace core
inline namespace backend {
using perf::arch;
using perf::llvm;
namespace mc {
using perf::mc::disassemble;
inline namespace info {
using perf::mc::assembly;
using perf::mc::address;
using perf::mc::encoding;
using perf::mc::size;
using perf::mc::uops;
using perf::mc::latency;
using perf::mc::rthroughput;
using perf::mc::may_load;
using perf::mc::may_store;
using perf::mc::has_side_effects;
namespace branch {
using perf::mc::branch::is_conditional;
using perf::mc::branch::is_unconditional;
using perf::mc::branch::is_indirect;
using perf::mc::branch::is_call;
using perf::mc::branch::is_ret;
} // namespace branch
} // namespace info
/**
* Instruction to source code # line (requires debug symbols `-g`)
*/
using perf::mc::source;
} // namespace mc
namespace mca {
using perf::mca::timeline;
using perf::mca::resource_pressure;
using perf::mca::bottleneck;
} // namespace mca
}
inline namespace prof {
namespace dsl {
using perf::dsl::operator+;
using perf::dsl::operator-;
using perf::dsl::operator*;
using perf::dsl::operator/;
} // namespace dsl
namespace time {
using perf::time::timer;
/// monotonic-time / guranateed to be always increasing
using perf::time::steady_clock;
/// user-time + sys-time
using perf::time::cpu;
/// cpu-time for the current thread
using perf::time::thread;
/// wall-time
using perf::time::real;
/// wall-time / guranateed to be always increasing
using perf::time::monotonic;
/// time-stamp-counter # https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=rdtsc
using perf::time::tsc;
} // namespace tiem
namespace stat {
using perf::stat::config;
/**
* `perf stat -e`
*/
using perf::stat::counter;
/**
* events
*/
using perf::stat::cpu_clock;
using perf::stat::task_clock;
using perf::stat::page_faults;
using perf::stat::faults;
using perf::stat::major_faults;
using perf::stat::minor_faults;
using perf::stat::alignment_faults;
using perf::stat::emulation_faults;
using perf::stat::context_switches;
using perf::stat::bpf_output;
using perf::stat::cgroup_switches;
using perf::stat::cpu_migrations;
using perf::stat::migrations;
using perf::stat::cycles;
using perf::stat::instructions;
using perf::stat::branch_misses;
using perf::stat::bus_cycles;
using perf::stat::cache_misses;
using perf::stat::cache_references;
using perf::stat::branches;
using perf::stat::branch_instructions;
using perf::stat::stalled_cycles_backend;
using perf::stat::idle_cycles_backend;
using perf::stat::stalled_cycles_frontend;
using perf::stat::idle_cycles_frontend;
using perf::stat::llc_misses;
using perf::stat::l1_misses;
using perf::stat::l1_dcache_loads;
using perf::stat::l1_dcache_load_misses;
using perf::stat::l1_icache_loads;
using perf::stat::l1_icache_load_misses;
using perf::stat::dtlb_loads;
using perf::stat::dtlb_load_misses;
using perf::stat::itlb_loads;
using perf::stat::itlb_load_misses;
inline namespace metric {
/// instruction per cycle (ipc)
using perf::stat::ipc;
/// cycles per instruction (cpi, inverse of ipc)
using perf::stat::cpi;
/// branch miss rate (branch misses per branch instruction)
using perf::stat::branch_miss_rate;
/// cache miss rate (cache misses per cache reference)
using perf::stat::cache_miss_rate;
/// llc miss rate
using perf::stat::llc_miss_rate;
/// l1 data cache miss rate
using perf::stat::l1_dcache_miss_rate;
/// l1 instruction cache miss rate
using perf::stat::l1_icache_miss_rate;
/// dtlb miss rate
using perf::stat::dtlb_miss_rate;
/// itlb miss rate
using perf::stat::itlb_miss_rate;
/// stalled cycles rate (frontend)
using perf::stat::frontend_stall_rate;
/// stalled cycles rate (backend)
using perf::stat::backend_stall_rate;
/// memory access rate
using perf::stat::memory_stall_ratio;
/// overall stall rate
using perf::stat::total_stall_rate;
/// cpu migrations per cycles
using perf::stat::cpu_migration_rate;
/// context switches per cycles
using perf::stat::context_switch_rate;
/// page fault rate
using perf::stat::page_fault_rate;
/// page fault rate (major faults per total faults)
using perf::stat::major_fault_rate;
/// page fault rate (minor faults per total faults)
using perf::stat::minor_fault_rate;
} // namespace metric
namespace top_down {
/// level-1
using perf::stat::top_down::retiring;
using perf::stat::top_down::bad_speculation;
using perf::stat::top_down::frontend_bound;
using perf::stat::top_down::backend_bound;
/// level-2.retiring
using perf::stat::top_down::heavy_operations;
using perf::stat::top_down::light_operations;
/// level-2.bad_speculation
using perf::stat::top_down::branch_mispredict;
using perf::stat::top_down::machine_clears;
/// level-2.frontend_bound
using perf::stat::top_down::fetch_latency;
using perf::stat::top_down::fetch_bandwidth;
/// level-2.backend_bound
using perf::stat::top_down::memory_bound;
using perf::stat::top_down::core_bound;
} // namespace top_down
} // namespace stat
namespace record {
using perf::record::config;
/**
* `perf record -e`
* `perf mem`
* `perf record -b` / last branch record (lbr)
*/
using perf::record::sampler;
/**
* events
*/
using perf::record::cpu_clock;
using perf::record::task_clock;
using perf::record::page_faults;
using perf::record::faults;
using perf::record::major_faults;
using perf::record::minor_faults;
using perf::record::alignment_faults;
using perf::record::emulation_faults;
using perf::record::context_switches;
using perf::record::bpf_output;
using perf::record::cgroup_switches;
using perf::record::cpu_migrations;
using perf::record::migrations;
using perf::record::cycles;
using perf::record::instructions;
using perf::record::branch_misses;
using perf::record::bus_cycles;
using perf::record::cache_misses;
using perf::record::cache_references;
using perf::record::branches;
using perf::record::branch_instructions;
using perf::record::stalled_cycles_backend;
using perf::record::idle_cycles_backend;
using perf::record::stalled_cycles_frontend;
using perf::record::idle_cycles_frontend;
using perf::record::llc_misses;
using perf::record::l1_misses;
using perf::record::l1_dcache_loads;
using perf::record::l1_dcache_load_misses;
using perf::record::l1_icache_loads;
using perf::record::l1_icache_load_misses;
using perf::record::dtlb_loads;
using perf::record::dtlb_load_misses;
using perf::record::itlb_loads;
using perf::record::itlb_load_misses;
namespace memory {
using perf::record::memory::loads;
using perf::record::memory::stores;
} // namespace memory
namespace branch {
using perf::record::branch::any;
using perf::record::branch::jmp;
using perf::record::branch::call;
using perf::record::branch::ret;
} // namespace branch
} // namespace record
namespace trace {
using perf::trace::config;
/**
* `perf record -e intel_pt/`
*/
using perf::trace::tracer;
/**
* traces
*/
using perf::trace::cyc; // cycles
using perf::trace::tsc; // time-stamp-counter
/**
* trace function execution
*/
using perf::trace::trace;
} // namespace trace
namespace tool {
/**
* third-party profiling tools # require external command
*/
using namespace perf::tool;
} // namespace tool
} // namespace prof
namespace bench {
namespace data {
using perf::bench::data::repeat;
using perf::bench::data::range;
using perf::bench::data::choice;
using perf::bench::data::uniform;
using perf::bench::data::normal;
using perf::bench::data::take;
} // namespace data
namespace stat {
using perf::bench::stat::min;
using perf::bench::stat::max;
using perf::bench::stat::mean;
using perf::bench::stat::geomean;
using perf::bench::stat::median;
using perf::bench::stat::percentile;
using perf::bench::stat::variance;
using perf::bench::stat::stddev;
using perf::bench::stat::sem;
using perf::bench::stat::mae;
using perf::bench::stat::mad;
using perf::bench::stat::cv;
using perf::bench::stat::z_score;
using perf::bench::stat::t_score;
} // namespace stat
using perf::bench::dataset;
using perf::bench::cold;
using perf::bench::warm;
using perf::bench::latency;
using perf::bench::throughput;
using perf::bench::engine;
using perf::bench::runner;
using perf::bench::iterations;
using perf::bench::samples;
using perf::bench::layout::split;
using perf::bench::report;
using perf::bench::annotate;
using perf::bench::json;
} // namespace bench
using perf::bench::runner;
using enum perf::bench::layout::split;
using perf::bench::report;
using perf::bench::annotate;
using perf::bench::json;
namespace data {
using perf::bench::data::repeat;
using perf::bench::data::range;
using perf::bench::data::choice;
using perf::bench::data::uniform;
using perf::bench::data::normal;
using perf::bench::data::take;
} // namespace data
namespace plot {
using perf::bench::plot::hist;
using perf::bench::plot::bar;
using perf::bench::plot::box;
using perf::bench::plot::ecdf;
using perf::bench::plot::line;
} // namespace plot
namespace test {
/**
* sanity checks
*/
using perf::test::run;
} // namespace test
} // namespace perf
// -*- mode: c++; -*-
// vim: set filetype=cpp: