power
zeus.monitor.power
Monitor the power usage of GPUs.
GPUPowerDomain
Bases: Enum
GPU power measurement domains with different update characteristics.
Source code in zeus/monitor/power.py
127 128 129 130 131 132 | |
CPUPowerDomain
Bases: Enum
CPU package and DRAM power measurement domains.
Source code in zeus/monitor/power.py
135 136 137 138 139 | |
GPUPowerSample
dataclass
A single GPU power measurement sample.
Source code in zeus/monitor/power.py
142 143 144 145 146 147 148 | |
CPUPowerSample
dataclass
A single CPU package or DRAM power measurement sample.
Source code in zeus/monitor/power.py
151 152 153 154 155 156 157 | |
PowerMonitor
Enhanced PowerMonitor with multiple power domains and timeline export.
This class provides:
- Multiple power domains:
- GPU: device instant, device average, and memory average
- CPU: package_average and dram_average
- Timeline export with independent deduplication per domain
- Separate processes for each power domain (2-3 processes depending on GPU support)
- Backward compatibility with existing PowerMonitor interface
Note
All GPUs must be homogeneous (i.e., the same model). All selected CPU packages must have matching DRAM energy monitoring support: either all support it or none do. Mixed DRAM support raises ValueError during initialization.
Warning
This monitor uses multiprocessing with the spawn start method to poll power in
background processes. Spawned processes re-import your main module, so keep heavy
initialization (for example, model loading) under if __name__ == "__main__": or
inside functions.
See also the "Safe importing of main module" section in the Python documentation.
Source code in zeus/monitor/power.py
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 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 | |
__init__
__init__(
gpu_indices=None,
update_period=None,
max_samples_per_gpu=None,
gpu_power_domains=None,
*,
cpu_indices=None,
cpu_update_period=0.1,
max_samples_per_cpu=None,
cpu_power_domains=None,
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gpu_indices
|
list[int] | None
|
Indices of the GPUs to monitor. If None, monitor all available GPUs. Pass an empty list to disable GPU monitoring. |
None
|
update_period
|
float | None
|
GPU polling period in seconds. Maintained for backwards compatibility |
None
|
max_samples_per_gpu
|
int | None
|
Maximum number of power samples to keep per GPU per domain in memory. If None (default), unlimited samples are kept. |
None
|
gpu_power_domains
|
list[GPUPowerDomain | Literal['device_instant', 'device_average', 'memory_average']] | None
|
GPU power domains to monitor. If None, monitor all supported GPU domains. |
None
|
cpu_indices
|
list[int] | None
|
Indices of CPU packages to monitor. If None, monitor all available CPU packages. Pass an empty list to disable CPU monitoring. |
None
|
cpu_update_period
|
float
|
CPU polling period in seconds. Defaults to 0.1. Values at or below 0.0001 trigger a warning. |
0.1
|
max_samples_per_cpu
|
int | None
|
Maximum number of power samples to keep per CPU package per domain in memory. If None (default), unlimited samples are kept. |
None
|
cpu_power_domains
|
list[CPUPowerDomain | Literal['package_average', 'dram_average']] | None
|
CPU power domains to monitor. If None, monitor all supported CPU domains. |
None
|
Source code in zeus/monitor/power.py
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 | |
_determine_supported_domains
_determine_supported_domains()
Determine which GPU and CPU power domains are supported.
Source code in zeus/monitor/power.py
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 | |
stop
stop()
Stop all monitoring processes.
Source code in zeus/monitor/power.py
482 483 484 485 | |
_process_queue_data
_process_queue_data(domain)
Process all pending samples from a specific domain's queue.
Source code in zeus/monitor/power.py
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | |
_process_all_queue_data
_process_all_queue_data()
Process all pending samples from all domain queues.
Source code in zeus/monitor/power.py
506 507 508 509 | |
get_power_timeline
get_power_timeline(
gpu_power_domain=None,
gpu_index=None,
start_time=None,
end_time=None,
*,
cpu_power_domain=None,
cpu_index=None,
)
Get power timeline for a specific power domain and device(s).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gpu_power_domain
|
GPUPowerDomain | Literal['device_instant', 'device_average', 'memory_average'] | None
|
GPU power domain to query. Specify exactly one of gpu_power_domain or cpu_power_domain. |
None
|
gpu_index
|
int | None
|
Specific GPU index, or None for all GPUs. Only valid for GPU power domains. |
None
|
start_time
|
float | None
|
Start time filter (unix timestamp from time.time() or similar) |
None
|
end_time
|
float | None
|
End time filter (unix timestamp from time.time() or similar) |
None
|
cpu_power_domain
|
CPUPowerDomain | Literal['package_average', 'dram_average'] | None
|
CPU power domain to query. |
None
|
cpu_index
|
int | None
|
Specific CPU package index, or None for all CPU packages. Only valid for CPU power domains. |
None
|
Returns:
| Type | Description |
|---|---|
dict[int, list[tuple[float, float]]]
|
Dictionary mapping device indices to timeline data with deduplication. |
dict[int, list[tuple[float, float]]]
|
Timeline data is list of (timestamp, power_watts) tuples. |
Source code in zeus/monitor/power.py
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 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 | |
get_all_power_timelines
get_all_power_timelines(
gpu_index=None,
start_time=None,
end_time=None,
*,
cpu_index=None,
)
Get all power timelines organized by power domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gpu_index
|
int | None
|
Specific GPU index, or None for all GPUs |
None
|
start_time
|
float | None
|
Start time filter (unix timestamp from time.time() or similar) |
None
|
end_time
|
float | None
|
End time filter (unix timestamp from time.time() or similar) |
None
|
cpu_index
|
int | None
|
Specific CPU package index, or None for all CPU packages. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, dict[int, list[tuple[float, float]]]]
|
Dictionary with power domain names as keys and each value is a dict |
dict[str, dict[int, list[tuple[float, float]]]]
|
mapping device indices to timeline data. |
Source code in zeus/monitor/power.py
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 | |
get_energy
get_energy(start_time, end_time, power_domain=None)
Get the energy used by the GPUs between two times.
Energy is computed by integrating power samples over time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_time
|
float
|
Start time of the interval, from time.time(). |
required |
end_time
|
float
|
End time of the interval, from time.time(). |
required |
power_domain
|
GPUPowerDomain | Literal['device_instant', 'device_average', 'memory_average'] | None
|
Power domain whose samples are integrated. If None,
|
None
|
Returns:
| Type | Description |
|---|---|
dict[int, float] | None
|
A dictionary mapping GPU indices to the energy used by the GPU between the |
dict[int, float] | None
|
two times. If there are no power readings, return None. |
Source code in zeus/monitor/power.py
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 | |
get_power
get_power(
time=None, power_domain=GPUPowerDomain.DEVICE_INSTANT
)
Get the power usage of the GPUs at a specific time point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
float | None
|
Time point to get the power usage at. If None, get the power usage at the last recorded time point. |
None
|
power_domain
|
GPUPowerDomain | Literal['device_instant', 'device_average', 'memory_average']
|
Power domain to query. On GPUs that do not support instant
power (e.g., some AMD GPUs), pass |
DEVICE_INSTANT
|
Returns:
| Type | Description |
|---|---|
dict[int, float] | None
|
A dictionary mapping GPU indices to the power usage of the GPU at the |
dict[int, float] | None
|
specified time point. If there are no power readings, return None. |
Source code in zeus/monitor/power.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 | |
infer_gpu_counter_update_period
infer_gpu_counter_update_period(gpu_indicies)
Infer the update period of the GPU power counter.
GPU power counters can update as slow as 10 Hz depending on the GPU model, so there's no need to poll them too faster than that. This function infers the update period for each unique GPU model and selects the fastest-updating period detected. Then, it returns half the period to ensure that the counter is polled at least twice per update period.
Source code in zeus/monitor/power.py
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 | |
_infer_gpu_counter_update_period_single
_infer_gpu_counter_update_period_single(gpu_index)
Infer the update period of the GPU power counter for a single GPU.
Source code in zeus/monitor/power.py
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 | |
_cleanup_processes
_cleanup_processes(stop_events, processes)
Idempotent cleanup function for power monitoring processes.
Source code in zeus/monitor/power.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
_gpu_polling_process
_gpu_polling_process(
power_domain,
gpu_indices,
data_queue,
ready_event,
stop_event,
update_period,
)
Polling process for a specific power domain with deduplication.
Source code in zeus/monitor/power.py
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 | |
_cpu_polling_process
_cpu_polling_process(
cpu_indices,
power_domains,
package_data_queue,
dram_data_queue,
ready_event,
stop_event,
update_period,
)
Poll CPU energy counters and emit package and DRAM power samples.
Source code in zeus/monitor/power.py
848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 | |