mirror of
https://github.com/XuehaiPan/nvitop.git
synced 2026-05-21 06:45:24 -06:00
docs: update README.md for ResourceMetricCollector
Signed-off-by: Xuehai Pan <XuehaiPan@pku.edu.cn>
This commit is contained in:
parent
2e2701472b
commit
b2990dc93f
1 changed files with 27 additions and 0 deletions
27
README.md
27
README.md
|
|
@ -579,6 +579,33 @@ for epoch in range(num_epoch):
|
|||
global_step=epoch)
|
||||
```
|
||||
|
||||
Another example for logging to CSV file:
|
||||
|
||||
```python
|
||||
import datetime
|
||||
import time
|
||||
|
||||
import pandas as pd
|
||||
|
||||
from nvitop import ResourceMetricCollector
|
||||
|
||||
collector = ResourceMetricCollector(root_pids={1}, interval=2.0) # log all devices and all GPU processes
|
||||
df = pd.DataFrame()
|
||||
|
||||
with collector(tag='resources'):
|
||||
for _ in range(60):
|
||||
# Do something
|
||||
time.sleep(60)
|
||||
|
||||
metrics = collector.collect()
|
||||
df_metrics = pd.DataFrame.from_records(metrics, index=[len(df)])
|
||||
df = pd.concat([df, df_metrics], ignore_index=True)
|
||||
# Flush to CSV file ...
|
||||
|
||||
df.insert(0, 'time', df['resources/timestamp'].map(datetime.datetime.fromtimestamp))
|
||||
df.to_csv('results.csv', index=False)
|
||||
```
|
||||
|
||||
#### Low-level APIs
|
||||
|
||||
##### Device
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue