[GH-ISSUE #20] [Question] Can nvitop keep a log/record of GPU-Utilization and store in a CSV? #17

Closed
opened 2026-05-05 03:22:05 -06:00 by gitea-mirror · 4 comments
Owner

Originally created by @FelixMildon on GitHub (Jun 17, 2022).
Original GitHub issue: https://github.com/XuehaiPan/nvitop/issues/20

I'm trying to record GPU-utilization, and the users., and what programs are running.
Is there a way to log and save this information? Like into a CSV or database?

Sorry if I missed something from the readme

Originally created by @FelixMildon on GitHub (Jun 17, 2022). Original GitHub issue: https://github.com/XuehaiPan/nvitop/issues/20 I'm trying to record GPU-utilization, and the users., and what programs are running. Is there a way to log and save this information? Like into a CSV or database? Sorry if I missed something from the readme
gitea-mirror 2026-05-05 03:22:05 -06:00
Author
Owner

@XuehaiPan commented on GitHub (Jun 17, 2022):

@FelixMildon Hi, nvitop provides APIs to query the device and process status, see https://github.com/XuehaiPan/nvitop#device.

from nvitop import Device, GpuProcess

all_devices = Device.all()
all_gpu_processes = []
for device in all_devices:
    all_gpu_processes.extend(device.processes().values())

all_device_snapshots = [device.as_snapshot() for device in all_devices]
all_gpu_process_snapshots = [process.as_snapshot() for process in all_processes]

I'm going to add tensorboard integration this weekend (see https://github.com/XuehaiPan/nvitop/issues/18#issuecomment-1140715085), which will introduce more user-friendly interfaces.

<!-- gh-comment-id:1158678472 --> @XuehaiPan commented on GitHub (Jun 17, 2022): @FelixMildon Hi, `nvitop` provides APIs to query the device and process status, see https://github.com/XuehaiPan/nvitop#device. ```python from nvitop import Device, GpuProcess all_devices = Device.all() all_gpu_processes = [] for device in all_devices: all_gpu_processes.extend(device.processes().values()) all_device_snapshots = [device.as_snapshot() for device in all_devices] all_gpu_process_snapshots = [process.as_snapshot() for process in all_processes] ``` I'm going to add `tensorboard` integration this weekend (see https://github.com/XuehaiPan/nvitop/issues/18#issuecomment-1140715085), which will introduce more user-friendly interfaces.
Author
Owner

@FelixMildon commented on GitHub (Jun 22, 2022):

@XuehaiPan I'm really unsure how to use NVItop to log processes and gpu-utalisation (from nvidia-smi). Logging these in intervals into a CSV would be really useful for University of Aucklands GPUs.

<!-- gh-comment-id:1162908032 --> @FelixMildon commented on GitHub (Jun 22, 2022): @XuehaiPan I'm really unsure how to use NVItop to log processes and gpu-utalisation (from nvidia-smi). Logging these in intervals into a CSV would be really useful for University of Aucklands GPUs.
Author
Owner

@XuehaiPan commented on GitHub (Jun 22, 2022):

Hi @FelixMildon, I implement a new metric collector in PR #21, which can collect the resource consumption for GPUs and processes.

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(12):
        # Do something
        time.sleep(5)

        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)
Screen Shot

See also #18.

<!-- gh-comment-id:1163315793 --> @XuehaiPan commented on GitHub (Jun 22, 2022): Hi @FelixMildon, I implement a new metric collector in PR #21, which can collect the resource consumption for GPUs and processes. ```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(12): # Do something time.sleep(5) 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) ``` <img width="1440" alt="Screen Shot" src="https://user-images.githubusercontent.com/16078332/175080657-73dcd0a3-afef-4d5d-98f9-8296ac76623f.png"> See also #18.
Author
Owner

@XuehaiPan commented on GitHub (Jun 26, 2022):

Close as resolved by PR #21.

<!-- gh-comment-id:1166510012 --> @XuehaiPan commented on GitHub (Jun 26, 2022): Close as resolved by PR #21.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/nvitop#17
No description provided.