| 1 |
|
| 2 | from typing import Callable, Dict, List, Optional, Any, Iterator, Union
|
| 3 |
|
| 4 | def config_get(name: str) -> Optional[str]:
|
| 5 | |
| 6 |
|
| 7 | Args:
|
| 8 | name: The configuration variable name (e.g., 'colors.top').
|
| 9 |
|
| 10 | Returns:
|
| 11 | The configuration value as a string, or None if not set.
|
| 12 |
|
| 13 | ...
|
| 14 |
|
| 15 | def metrics() -> List[Dict[str, Union[str, List[str]]]]:
|
| 16 | |
| 17 |
|
| 18 | Returns:
|
| 19 | A list of dictionaries, each describing a metric.
|
| 20 |
|
| 21 | ...
|
| 22 |
|
| 23 | def syscall_name(id: int, *, elf_machine: Optional[int] = None) -> str:
|
| 24 | |
| 25 |
|
| 26 | Args:
|
| 27 | sc_id: The syscall number.
|
| 28 | elf_machine: Optional ELF machine type.
|
| 29 |
|
| 30 | Returns:
|
| 31 | The name of the syscall.
|
| 32 |
|
| 33 | ...
|
| 34 |
|
| 35 | def syscall_id(name: str, *, elf_machine: Optional[int] = None) -> int:
|
| 36 | |
| 37 |
|
| 38 | Args:
|
| 39 | name: The syscall name.
|
| 40 | elf_machine: Optional ELF machine type.
|
| 41 |
|
| 42 | Returns:
|
| 43 | The number of the syscall.
|
| 44 |
|
| 45 | ...
|
| 46 |
|
| 47 | def parse_events(
|
| 48 | event_string: str,
|
| 49 | cpus: Optional[cpu_map] = None,
|
| 50 | threads: Optional['thread_map'] = None
|
| 51 | ) -> 'evlist':
|
| 52 | |
| 53 |
|
| 54 | Args:
|
| 55 | event_string: The event string (e.g., 'cycles,instructions').
|
| 56 | cpus: Optional CPU map to bind events to.
|
| 57 | threads: Optional thread map to bind events to.
|
| 58 |
|
| 59 | Returns:
|
| 60 | An evlist containing the parsed events.
|
| 61 |
|
| 62 | ...
|
| 63 |
|
| 64 | def parse_metrics(
|
| 65 | metrics_string: str,
|
| 66 | pmu: Optional[str] = None,
|
| 67 | cpus: Optional[cpu_map] = None,
|
| 68 | threads: Optional['thread_map'] = None
|
| 69 | ) -> 'evlist':
|
| 70 |
|
| 71 | ...
|
| 72 |
|
| 73 | def tracepoint(sys: str, name: str) -> int:
|
| 74 |
|
| 75 | ...
|
| 76 |
|
| 77 | def pmus() -> Iterator[Any]:
|
| 78 |
|
| 79 | ...
|
| 80 |
|
| 81 | class data:
|
| 82 |
|
| 83 | def __init__(self, path: str = ..., fd: int = ...) -> None: ...
|
| 84 |
|
| 85 | class thread:
|
| 86 |
|
| 87 | def comm(self) -> str:
|
| 88 |
|
| 89 | ...
|
| 90 | pid: int
|
| 91 | tid: int
|
| 92 | ppid: int
|
| 93 | cpu: int
|
| 94 |
|
| 95 | class counts_values:
|
| 96 |
|
| 97 | id: int
|
| 98 | val: int
|
| 99 | ena: int
|
| 100 | run: int
|
| 101 | lost: int
|
| 102 | values: List[int]
|
| 103 |
|
| 104 | class thread_map:
|
| 105 |
|
| 106 | def __init__(self, pid: int = -1, tid: int = -1) -> None:
|
| 107 | |
| 108 |
|
| 109 | Args:
|
| 110 | pid: Process ID to monitor (-1 for all).
|
| 111 | tid: Thread ID to monitor (-1 for all).
|
| 112 |
|
| 113 | ...
|
| 114 | def __len__(self) -> int: ...
|
| 115 | def __getitem__(self, index: int) -> int: ...
|
| 116 | def __iter__(self) -> Iterator[int]: ...
|
| 117 |
|
| 118 | class evsel:
|
| 119 |
|
| 120 | def __init__(
|
| 121 | self,
|
| 122 | type: int = ...,
|
| 123 | config: int = ...,
|
| 124 | sample_freq: int = ...,
|
| 125 | sample_period: int = ...,
|
| 126 | sample_type: int = ...,
|
| 127 | read_format: int = ...,
|
| 128 | disabled: bool = ...,
|
| 129 | inherit: bool = ...,
|
| 130 | pinned: bool = ...,
|
| 131 | exclusive: bool = ...,
|
| 132 | exclude_user: bool = ...,
|
| 133 | exclude_kernel: bool = ...,
|
| 134 | exclude_hv: bool = ...,
|
| 135 | exclude_idle: bool = ...,
|
| 136 | mmap: bool = ...,
|
| 137 | context_switch: bool = ...,
|
| 138 | comm: bool = ...,
|
| 139 | freq: bool = ...,
|
| 140 | inherit_stat: bool = ...,
|
| 141 | enable_on_exec: bool = ...,
|
| 142 | task: bool = ...,
|
| 143 | watermark: int = ...,
|
| 144 | precise_ip: int = ...,
|
| 145 | mmap_data: bool = ...,
|
| 146 | sample_id_all: bool = ...,
|
| 147 | wakeup_events: int = ...,
|
| 148 | bp_type: int = ...,
|
| 149 | bp_addr: int = ...,
|
| 150 | bp_len: int = ...,
|
| 151 | idx: int = ...,
|
| 152 | ) -> None: ...
|
| 153 | def __str__(self) -> str:
|
| 154 |
|
| 155 | ...
|
| 156 | def open(self) -> None:
|
| 157 |
|
| 158 | ...
|
| 159 | def read(self, cpu: int, thread: int) -> counts_values:
|
| 160 |
|
| 161 | ...
|
| 162 | ids: List[int]
|
| 163 | def cpus(self) -> cpu_map:
|
| 164 |
|
| 165 | ...
|
| 166 | def threads(self) -> thread_map:
|
| 167 |
|
| 168 | ...
|
| 169 | tracking: bool
|
| 170 | config: int
|
| 171 | read_format: int
|
| 172 | sample_period: int
|
| 173 | sample_type: int
|
| 174 | size: int
|
| 175 | type: int
|
| 176 | wakeup_events: int
|
| 177 |
|
| 178 |
|
| 179 | class _sample_members:
|
| 180 | sample_pid: int
|
| 181 | sample_tid: int
|
| 182 | sample_time: int
|
| 183 | sample_id: int
|
| 184 | sample_stream_id: int
|
| 185 | sample_period: int
|
| 186 | sample_cpu: int
|
| 187 |
|
| 188 | class sample_event(_sample_members):
|
| 189 |
|
| 190 | evsel: evsel
|
| 191 | sample_ip: int
|
| 192 | sample_addr: int
|
| 193 | sample_phys_addr: int
|
| 194 | sample_weight: int
|
| 195 | sample_data_src: int
|
| 196 | sample_insn_count: int
|
| 197 | sample_cyc_count: int
|
| 198 | type: int
|
| 199 | raw_buf: bytes
|
| 200 | dso: str
|
| 201 | dso_long_name: str
|
| 202 | dso_bid: Optional[bytes]
|
| 203 | map_start: int
|
| 204 | map_end: int
|
| 205 | map_pgoff: int
|
| 206 | symbol: str
|
| 207 | sym_start: int
|
| 208 | sym_end: int
|
| 209 | brstack: Optional['branch_stack']
|
| 210 | callchain: Optional['callchain']
|
| 211 | def srccode(self) -> str: ...
|
| 212 | def insn(self) -> str: ...
|
| 213 | def __getattr__(self, name: str) -> Any: ...
|
| 214 |
|
| 215 | class mmap_event(_sample_members):
|
| 216 |
|
| 217 | type: int
|
| 218 | misc: int
|
| 219 | pid: int
|
| 220 | tid: int
|
| 221 | start: int
|
| 222 | len: int
|
| 223 | pgoff: int
|
| 224 | filename: str
|
| 225 | evsel: Optional['evsel']
|
| 226 |
|
| 227 | class mmap2_event(_sample_members):
|
| 228 |
|
| 229 | type: int
|
| 230 | misc: int
|
| 231 | pid: int
|
| 232 | tid: int
|
| 233 | start: int
|
| 234 | len: int
|
| 235 | pgoff: int
|
| 236 | prot: int
|
| 237 | flags: int
|
| 238 | filename: str
|
| 239 | maj: Optional[int]
|
| 240 | min: Optional[int]
|
| 241 | ino: Optional[int]
|
| 242 | ino_generation: Optional[int]
|
| 243 | build_id: Optional[bytes]
|
| 244 | evsel: Optional['evsel']
|
| 245 |
|
| 246 | class lost_event(_sample_members):
|
| 247 |
|
| 248 | type: int
|
| 249 | id: int
|
| 250 | lost: int
|
| 251 | evsel: Optional['evsel']
|
| 252 |
|
| 253 | class comm_event(_sample_members):
|
| 254 |
|
| 255 | type: int
|
| 256 | pid: int
|
| 257 | tid: int
|
| 258 | comm: str
|
| 259 | evsel: Optional['evsel']
|
| 260 |
|
| 261 | class task_event(_sample_members):
|
| 262 |
|
| 263 | type: int
|
| 264 | pid: int
|
| 265 | ppid: int
|
| 266 | tid: int
|
| 267 | ptid: int
|
| 268 | time: int
|
| 269 | evsel: Optional['evsel']
|
| 270 |
|
| 271 | class throttle_event(_sample_members):
|
| 272 |
|
| 273 | type: int
|
| 274 | time: int
|
| 275 | id: int
|
| 276 | stream_id: int
|
| 277 | evsel: Optional['evsel']
|
| 278 |
|
| 279 | class read_event(_sample_members):
|
| 280 |
|
| 281 | type: int
|
| 282 | pid: int
|
| 283 | tid: int
|
| 284 | evsel: Optional['evsel']
|
| 285 |
|
| 286 | class switch_event(_sample_members):
|
| 287 |
|
| 288 | type: int
|
| 289 | next_prev_pid: int
|
| 290 | next_prev_tid: int
|
| 291 | evsel: Optional['evsel']
|
| 292 |
|
| 293 | class branch_entry:
|
| 294 | |
| 295 |
|
| 296 | Attributes:
|
| 297 | from_ip: Source address of the branch (corresponds to 'from' keyword in C).
|
| 298 | to_ip: Destination address of the branch.
|
| 299 | mispred: True if the branch was mispredicted.
|
| 300 | predicted: True if the branch was predicted.
|
| 301 | in_tx: True if the branch was in a transaction.
|
| 302 | abort: True if the branch was an abort.
|
| 303 | cycles: Number of cycles since the last branch.
|
| 304 | type: Type of branch.
|
| 305 |
|
| 306 | from_ip: int
|
| 307 | to_ip: int
|
| 308 | mispred: bool
|
| 309 | predicted: bool
|
| 310 | in_tx: bool
|
| 311 | abort: bool
|
| 312 | cycles: int
|
| 313 | type: int
|
| 314 |
|
| 315 | class branch_stack:
|
| 316 |
|
| 317 | def __len__(self) -> int: ...
|
| 318 | def __getitem__(self, index: int) -> branch_entry: ...
|
| 319 |
|
| 320 | class callchain_node:
|
| 321 |
|
| 322 | ip: int
|
| 323 | symbol: Optional[str]
|
| 324 | dso: Optional[str]
|
| 325 |
|
| 326 | class callchain:
|
| 327 |
|
| 328 | def __len__(self) -> int: ...
|
| 329 | def __getitem__(self, index: int) -> callchain_node: ...
|
| 330 |
|
| 331 | class stat_event(_sample_members):
|
| 332 |
|
| 333 | type: int
|
| 334 | id: int
|
| 335 | cpu: int
|
| 336 | thread: int
|
| 337 | val: int
|
| 338 | ena: int
|
| 339 | run: int
|
| 340 | evsel: Optional['evsel']
|
| 341 |
|
| 342 | class stat_round_event(_sample_members):
|
| 343 |
|
| 344 | type: int
|
| 345 | time: int
|
| 346 | stat_round_type: int
|
| 347 | evsel: Optional['evsel']
|
| 348 |
|
| 349 | class cpu_map:
|
| 350 |
|
| 351 | def __init__(self, cpustr: Optional[str] = None) -> None: ...
|
| 352 | def __len__(self) -> int: ...
|
| 353 | def __getitem__(self, index: int) -> int: ...
|
| 354 | def __iter__(self) -> Iterator[int]: ...
|
| 355 |
|
| 356 |
|
| 357 | class evlist:
|
| 358 | def __init__(self, cpus: cpu_map, threads: thread_map) -> None: ...
|
| 359 | def open(self) -> None:
|
| 360 |
|
| 361 | ...
|
| 362 | def close(self) -> None:
|
| 363 |
|
| 364 | ...
|
| 365 | def mmap(self) -> None:
|
| 366 |
|
| 367 | ...
|
| 368 | def poll(self, timeout: int) -> int:
|
| 369 | |
| 370 |
|
| 371 | Args:
|
| 372 | timeout: Timeout in milliseconds.
|
| 373 |
|
| 374 | Returns:
|
| 375 | Number of events ready.
|
| 376 |
|
| 377 | ...
|
| 378 | def read_on_cpu(self, cpu: int) -> Optional[Any]:
|
| 379 | |
| 380 |
|
| 381 | Args:
|
| 382 | cpu: The CPU number.
|
| 383 |
|
| 384 | Returns:
|
| 385 | A sample_event or other event type if available, or None.
|
| 386 |
|
| 387 | ...
|
| 388 | def all_cpus(self) -> cpu_map:
|
| 389 |
|
| 390 | ...
|
| 391 | def metrics(self) -> List[str]:
|
| 392 |
|
| 393 | ...
|
| 394 | def compute_metric(self, metric: str, cpu: int, thread: int) -> float:
|
| 395 | |
| 396 |
|
| 397 | Args:
|
| 398 | metric: The metric name.
|
| 399 | cpu: The CPU number.
|
| 400 | thread: The thread ID.
|
| 401 |
|
| 402 | Returns:
|
| 403 | The computed metric value.
|
| 404 |
|
| 405 | ...
|
| 406 | def config(self) -> None:
|
| 407 |
|
| 408 | ...
|
| 409 | def disable(self) -> None:
|
| 410 |
|
| 411 | ...
|
| 412 | def enable(self) -> None:
|
| 413 |
|
| 414 | ...
|
| 415 | def get_pollfd(self) -> List[int]:
|
| 416 |
|
| 417 | ...
|
| 418 | def add(self, evsel: evsel) -> int:
|
| 419 |
|
| 420 | ...
|
| 421 | def __iter__(self) -> Iterator[evsel]:
|
| 422 |
|
| 423 | ...
|
| 424 |
|
| 425 |
|
| 426 | class session:
|
| 427 | def __init__(
|
| 428 | self,
|
| 429 | data: data,
|
| 430 | sample: Optional[Callable[[sample_event], None]] = None,
|
| 431 | stat: Optional[Callable[[Any, Optional[str]], None]] = None
|
| 432 | ) -> None:
|
| 433 | |
| 434 |
|
| 435 | Args:
|
| 436 | data: The perf data file to read.
|
| 437 | sample: Callback for sample events.
|
| 438 | stat: Callback for stat events.
|
| 439 |
|
| 440 | ...
|
| 441 | def process_events(self) -> None:
|
| 442 |
|
| 443 | ...
|
| 444 | def find_thread(self, pid: int) -> thread:
|
| 445 |
|
| 446 | ...
|
| 447 |
|
| 448 | |
| 449 | TYPE_HARDWARE: int
|
| 450 |
|
| 451 |
|
| 452 | TYPE_SOFTWARE: int
|
| 453 |
|
| 454 |
|
| 455 | TYPE_TRACEPOINT: int
|
| 456 |
|
| 457 |
|
| 458 | TYPE_HW_CACHE: int
|
| 459 |
|
| 460 |
|
| 461 | TYPE_RAW: int
|
| 462 |
|
| 463 |
|
| 464 | TYPE_BREAKPOINT: int
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 | |
| 469 | COUNT_HW_CPU_CYCLES: int
|
| 470 |
|
| 471 |
|
| 472 | COUNT_HW_INSTRUCTIONS: int
|
| 473 | |
| 474 | most notably hardware interrupt counts.
|
| 475 |
|
| 476 | COUNT_HW_CACHE_REFERENCES: int
|
| 477 | |
| 478 | may vary depending on your CPU.
|
| 479 |
|
| 480 | COUNT_HW_CACHE_MISSES: int
|
| 481 |
|
| 482 |
|
| 483 | COUNT_HW_BRANCH_INSTRUCTIONS: int
|
| 484 |
|
| 485 |
|
| 486 | COUNT_HW_BRANCH_MISSES: int
|
| 487 |
|
| 488 |
|
| 489 | COUNT_HW_BUS_CYCLES: int
|
| 490 |
|
| 491 |
|
| 492 | COUNT_HW_STALLED_CYCLES_FRONTEND: int
|
| 493 |
|
| 494 |
|
| 495 | COUNT_HW_STALLED_CYCLES_BACKEND: int
|
| 496 |
|
| 497 |
|
| 498 | COUNT_HW_REF_CPU_CYCLES: int
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 | |
| 503 | COUNT_HW_CACHE_L1D: int
|
| 504 |
|
| 505 |
|
| 506 | COUNT_HW_CACHE_L1I: int
|
| 507 |
|
| 508 |
|
| 509 | COUNT_HW_CACHE_LL: int
|
| 510 |
|
| 511 |
|
| 512 | COUNT_HW_CACHE_DTLB: int
|
| 513 |
|
| 514 |
|
| 515 | COUNT_HW_CACHE_ITLB: int
|
| 516 |
|
| 517 |
|
| 518 | COUNT_HW_CACHE_BPU: int
|
| 519 |
|
| 520 |
|
| 521 | COUNT_HW_CACHE_OP_READ: int
|
| 522 |
|
| 523 |
|
| 524 | COUNT_HW_CACHE_OP_WRITE: int
|
| 525 |
|
| 526 |
|
| 527 | COUNT_HW_CACHE_OP_PREFETCH: int
|
| 528 |
|
| 529 |
|
| 530 | COUNT_HW_CACHE_RESULT_ACCESS: int
|
| 531 |
|
| 532 |
|
| 533 | COUNT_HW_CACHE_RESULT_MISS: int
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 | |
| 538 | COUNT_SW_CPU_CLOCK: int
|
| 539 |
|
| 540 |
|
| 541 | COUNT_SW_TASK_CLOCK: int
|
| 542 |
|
| 543 |
|
| 544 | COUNT_SW_PAGE_FAULTS: int
|
| 545 |
|
| 546 |
|
| 547 | COUNT_SW_CONTEXT_SWITCHES: int
|
| 548 |
|
| 549 |
|
| 550 | COUNT_SW_CPU_MIGRATIONS: int
|
| 551 |
|
| 552 |
|
| 553 | COUNT_SW_PAGE_FAULTS_MIN: int
|
| 554 |
|
| 555 |
|
| 556 | COUNT_SW_PAGE_FAULTS_MAJ: int
|
| 557 |
|
| 558 |
|
| 559 | COUNT_SW_ALIGNMENT_FAULTS: int
|
| 560 |
|
| 561 |
|
| 562 | COUNT_SW_EMULATION_FAULTS: int
|
| 563 |
|
| 564 |
|
| 565 | COUNT_SW_DUMMY: int
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 | |
| 570 | SAMPLE_IP: int
|
| 571 |
|
| 572 |
|
| 573 | SAMPLE_TID: int
|
| 574 |
|
| 575 |
|
| 576 | SAMPLE_TIME: int
|
| 577 |
|
| 578 |
|
| 579 | SAMPLE_ADDR: int
|
| 580 |
|
| 581 |
|
| 582 | SAMPLE_READ: int
|
| 583 |
|
| 584 |
|
| 585 | SAMPLE_CALLCHAIN: int
|
| 586 |
|
| 587 |
|
| 588 | SAMPLE_ID: int
|
| 589 |
|
| 590 |
|
| 591 | SAMPLE_CPU: int
|
| 592 |
|
| 593 |
|
| 594 | SAMPLE_PERIOD: int
|
| 595 |
|
| 596 |
|
| 597 | SAMPLE_STREAM_ID: int
|
| 598 |
|
| 599 |
|
| 600 | SAMPLE_RAW: int
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 | |
| 605 | FORMAT_TOTAL_TIME_ENABLED: int
|
| 606 |
|
| 607 |
|
| 608 | FORMAT_TOTAL_TIME_RUNNING: int
|
| 609 |
|
| 610 |
|
| 611 | FORMAT_ID: int
|
| 612 |
|
| 613 |
|
| 614 | FORMAT_GROUP: int
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 | |
| 619 | RECORD_MMAP: int
|
| 620 |
|
| 621 |
|
| 622 | RECORD_LOST: int
|
| 623 |
|
| 624 |
|
| 625 | RECORD_COMM: int
|
| 626 |
|
| 627 |
|
| 628 | RECORD_EXIT: int
|
| 629 |
|
| 630 |
|
| 631 | RECORD_THROTTLE: int
|
| 632 |
|
| 633 |
|
| 634 | RECORD_UNTHROTTLE: int
|
| 635 |
|
| 636 |
|
| 637 | RECORD_FORK: int
|
| 638 |
|
| 639 |
|
| 640 | RECORD_READ: int
|
| 641 |
|
| 642 |
|
| 643 | RECORD_SAMPLE: int
|
| 644 |
|
| 645 |
|
| 646 | RECORD_MMAP2: int
|
| 647 | |
| 648 | ino_generation, prot, flags, filename, and sample_id.
|
| 649 |
|
| 650 | RECORD_AUX: int
|
| 651 |
|
| 652 |
|
| 653 | RECORD_ITRACE_START: int
|
| 654 |
|
| 655 |
|
| 656 | RECORD_LOST_SAMPLES: int
|
| 657 |
|
| 658 |
|
| 659 | RECORD_SWITCH: int
|
| 660 |
|
| 661 |
|
| 662 | RECORD_SWITCH_CPU_WIDE: int
|
| 663 |
|
| 664 |
|
| 665 | RECORD_STAT: int
|
| 666 |
|
| 667 |
|
| 668 | RECORD_STAT_ROUND: int
|
| 669 |
|
| 670 |
|
| 671 | RECORD_MISC_SWITCH_OUT: int
|
| 672 |
|