powerlog 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
powerlog/__init__.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import sys
|
|
3
|
+
import time
|
|
4
|
+
import csv
|
|
5
|
+
import argparse
|
|
6
|
+
|
|
7
|
+
NS_IN_S = 1_000_000_000 # Nanoseconds in a second
|
|
8
|
+
|
|
9
|
+
def log(message):
|
|
10
|
+
print(message, file=sys.stdout)
|
|
11
|
+
|
|
12
|
+
def get_power_draw(total_gpu_on_node=1):
|
|
13
|
+
proc = subprocess.run(
|
|
14
|
+
["nvidia-smi", "--query-gpu=power.draw", "--format=csv,noheader,nounits"],
|
|
15
|
+
capture_output=True
|
|
16
|
+
)
|
|
17
|
+
stdout = proc.stdout.decode("utf-8").strip()
|
|
18
|
+
power_values = [float(line.strip()) for line in stdout.splitlines()]
|
|
19
|
+
return sum(power_values[:total_gpu_on_node])
|
|
20
|
+
|
|
21
|
+
def measure_power(cmd_args, resolution=0.1, total_gpu_on_node=1):
|
|
22
|
+
get_power_draw() # warm-up
|
|
23
|
+
energy_j = 0
|
|
24
|
+
power_draw_samples = []
|
|
25
|
+
|
|
26
|
+
proc = subprocess.Popen(cmd_args)
|
|
27
|
+
start_time_ns = time.time_ns()
|
|
28
|
+
time_ns = start_time_ns
|
|
29
|
+
|
|
30
|
+
while True:
|
|
31
|
+
try:
|
|
32
|
+
proc.wait(timeout=resolution)
|
|
33
|
+
except subprocess.TimeoutExpired:
|
|
34
|
+
new_time_ns = time.time_ns()
|
|
35
|
+
draw_w = get_power_draw()
|
|
36
|
+
delay_ns = new_time_ns - time_ns
|
|
37
|
+
energy_j += delay_ns * draw_w / NS_IN_S
|
|
38
|
+
power_draw_samples.append((new_time_ns, draw_w))
|
|
39
|
+
time_ns = new_time_ns
|
|
40
|
+
else:
|
|
41
|
+
break
|
|
42
|
+
|
|
43
|
+
end_time_ns = time_ns
|
|
44
|
+
total_time_s = (end_time_ns - start_time_ns) / NS_IN_S
|
|
45
|
+
sampled_draws = [v[1] for v in power_draw_samples]
|
|
46
|
+
avg_power_sampled = sum(sampled_draws) / len(sampled_draws)
|
|
47
|
+
avg_power_timed = energy_j / total_time_s
|
|
48
|
+
min_draw = min(sampled_draws)
|
|
49
|
+
max_draw = max(sampled_draws)
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
"total_time_s": total_time_s,
|
|
53
|
+
"energy_j": energy_j,
|
|
54
|
+
"avg_power_sampled": avg_power_sampled,
|
|
55
|
+
"avg_power_timed": avg_power_timed,
|
|
56
|
+
"min_draw": min_draw,
|
|
57
|
+
"max_draw": max_draw,
|
|
58
|
+
"samples": power_draw_samples
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
def save_summary_csv(path, result):
|
|
62
|
+
with open(path, 'w', newline='') as csvfile:
|
|
63
|
+
writer = csv.writer(csvfile)
|
|
64
|
+
writer.writerow([
|
|
65
|
+
"Total Time (s)",
|
|
66
|
+
"Total Energy (J)",
|
|
67
|
+
"Avg Power Sampled (W)",
|
|
68
|
+
"Avg Power Timed (W)",
|
|
69
|
+
"Min Power Sampled (W)",
|
|
70
|
+
"Max Power Sampled (W)"
|
|
71
|
+
])
|
|
72
|
+
writer.writerow([
|
|
73
|
+
f"{result['total_time_s']:.4f}",
|
|
74
|
+
f"{result['energy_j']:.4f}",
|
|
75
|
+
f"{result['avg_power_sampled']:.4f}",
|
|
76
|
+
f"{result['avg_power_timed']:.4f}",
|
|
77
|
+
f"{result['min_draw']:.2f}",
|
|
78
|
+
f"{result['max_draw']:.2f}"
|
|
79
|
+
])
|
|
80
|
+
|
|
81
|
+
def save_samples_csv(path, samples):
|
|
82
|
+
with open(path, 'w', newline='') as csvfile:
|
|
83
|
+
writer = csv.writer(csvfile)
|
|
84
|
+
writer.writerow(["Timestamp (ns)", "Power Draw (W)"])
|
|
85
|
+
for t_ns, draw in samples:
|
|
86
|
+
writer.writerow([t_ns, f"{draw:.2f}"])
|
|
87
|
+
|
|
88
|
+
def main():
|
|
89
|
+
parser = argparse.ArgumentParser(description="Measure GPU power during execution.")
|
|
90
|
+
parser.add_argument("cmd", nargs=argparse.REMAINDER, help="Command to run (mandatory)")
|
|
91
|
+
parser.add_argument("--output", type=str, help="Output CSV base name (optional)")
|
|
92
|
+
parser.add_argument("--gpu", type=int, default=1, help="Number of GPUs per node (default 1)")
|
|
93
|
+
|
|
94
|
+
try:
|
|
95
|
+
args = parser.parse_args()
|
|
96
|
+
except:
|
|
97
|
+
parser.print_help()
|
|
98
|
+
sys.exit(0)
|
|
99
|
+
|
|
100
|
+
log(f"Running command: {' '.join(args.cmd)} on {args.gpu} GPU")
|
|
101
|
+
result = measure_power(args.cmd, total_gpu_on_node = args.gpu)
|
|
102
|
+
|
|
103
|
+
# Display to stdout
|
|
104
|
+
log("\n" + "=" * 60)
|
|
105
|
+
log("GPU POWER USAGE SUMMARY")
|
|
106
|
+
log(f"Total Time: {result['total_time_s']:.4f} s")
|
|
107
|
+
log(f"Total Energy: {result['energy_j']:.4f} J")
|
|
108
|
+
log(f"Avg Power (Timed): {result['avg_power_timed']:.4f} W")
|
|
109
|
+
log(f"Avg Power (Sampled): {result['avg_power_sampled']:.4f} W")
|
|
110
|
+
log(f"Min Power (Sampled): {result['min_draw']:.2f} W")
|
|
111
|
+
log(f"Max Power (Sampled): {result['max_draw']:.2f} W")
|
|
112
|
+
log("=" * 60)
|
|
113
|
+
|
|
114
|
+
# Save to CSVs if output requested
|
|
115
|
+
if args.output:
|
|
116
|
+
summary_csv = args.output if args.output.endswith(".csv") else args.output + ".csv"
|
|
117
|
+
samples_csv = summary_csv.replace(".csv", "_samples.csv")
|
|
118
|
+
save_summary_csv(summary_csv, result)
|
|
119
|
+
save_samples_csv(samples_csv, result["samples"])
|
|
120
|
+
log(f"Saved summary to: {summary_csv}")
|
|
121
|
+
log(f"Saved power samples to: {samples_csv}")
|
|
122
|
+
|
|
123
|
+
if __name__ == "__main__":
|
|
124
|
+
main()
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
# python power_time.py --output power_report.csv --gpu 4 ./tc.out data/data_7035.bin 0 0 1
|
|
128
|
+
# python power_time.py --output power_report.csv --gpu 4 ./tc.out data/data_7035.bin 0 0 1
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: powerlog
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: GPU power log
|
|
5
|
+
Project-URL: Homepage, https://github.com/arsho/powerlog
|
|
6
|
+
Project-URL: Issues, https://github.com/arsho/powerlog/issues
|
|
7
|
+
Author-email: Ahmedur Rahman Shovon <shovon.sylhet@gmail.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: energy,gpupower,power analysis,power log,powerlog
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Requires-Python: >=3.8
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# powerlog
|
|
18
|
+
|
|
19
|
+
**Powerlog** is a lightweight command-line tool and Python package to profile GPU power consumption during the execution of a command-line program. It uses `nvidia-smi` to sample power draw at regular intervals and reports total energy usage, average power, and min/max readings.
|
|
20
|
+
|
|
21
|
+
## Features
|
|
22
|
+
|
|
23
|
+
* Measures real-time GPU power draw using `nvidia-smi`
|
|
24
|
+
* Computes:
|
|
25
|
+
|
|
26
|
+
* Total runtime
|
|
27
|
+
* Total energy consumed (in Joules)
|
|
28
|
+
* Average, min, and max power (Watts)
|
|
29
|
+
* Outputs both summary and raw samples as CSV
|
|
30
|
+
* Simple CLI interface
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
Requires Python 3.6+ and NVIDIA's `nvidia-smi` available in your system PATH.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install powerlog
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
powerlog --output power_report.csv --gpu 2 ./my_gpu_program arg1 arg2
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### CLI Options
|
|
47
|
+
|
|
48
|
+
| Argument | Description |
|
|
49
|
+
| ------------ | ------------------------------------------- |
|
|
50
|
+
| `--output` | Base name for the output CSV files |
|
|
51
|
+
| `--gpu` | Number of GPUs to monitor (default: 1) |
|
|
52
|
+
| `cmd` | Command and arguments to run and profile |
|
|
53
|
+
|
|
54
|
+
## Output
|
|
55
|
+
|
|
56
|
+
If `--output power.csv` is specified:
|
|
57
|
+
|
|
58
|
+
* `power.csv`: Summary of runtime, energy, and power stats
|
|
59
|
+
* `power_samples.csv`: Raw timestamped power draw samples
|
|
60
|
+
|
|
61
|
+
## Example
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
powerlog --output matrix_power.csv --gpu 1 ./matrix_multiply data/input.bin
|
|
65
|
+
powerlog --output matrix_power.csv --gpu 1 nvidia-smi
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Dependencies
|
|
69
|
+
|
|
70
|
+
* Python standard library (`subprocess`, `argparse`, `time`, `csv`)
|
|
71
|
+
* NVIDIA GPU with drivers and `nvidia-smi` tool
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT License
|
|
76
|
+
|
|
77
|
+
## Acknowledgments
|
|
78
|
+
|
|
79
|
+
Developed as part of GPU power-efficiency profiling experiments in Datalog-based engines.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
powerlog/__init__.py,sha256=XEcIFzp9V6KSFCNr7SNyJO7a3uiknd7uSSiJ-B61jlA,4487
|
|
2
|
+
powerlog-0.0.1.dist-info/METADATA,sha256=U_CYD-syCwQ3hvBR1ULECfbXKlObbh2VgZ7EbA1PlyE,2252
|
|
3
|
+
powerlog-0.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
4
|
+
powerlog-0.0.1.dist-info/licenses/LICENSE,sha256=kLeD78Ec5plGfyWA4CbOPIwTcp2wOh9Pri4SHKSJGFA,1078
|
|
5
|
+
powerlog-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ahmedur Rahman Shovon
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|