import useSWR from "swr"; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from "../ui/dialog"; import ActivityIndicator from "../indicators/activity-indicator"; import { GpuInfo, Nvinfo, Vainfo } from "@/types/stats"; import { Button } from "../ui/button"; import copy from "copy-to-clipboard"; import { toast } from "sonner"; type GPUInfoDialogProps = { showGpuInfo: boolean; gpuType: GpuInfo; setShowGpuInfo: (show: boolean) => void; }; export default function GPUInfoDialog({ showGpuInfo, gpuType, setShowGpuInfo, }: GPUInfoDialogProps) { const { data: vainfo } = useSWR( showGpuInfo && gpuType == "vainfo" ? "vainfo" : null, ); const { data: nvinfo } = useSWR( showGpuInfo && gpuType == "nvinfo" ? "nvinfo" : null, ); const onCopyInfo = async () => { copy( JSON.stringify(gpuType == "vainfo" ? vainfo : nvinfo) .replace(/\\t/g, "\t") .replace(/\\n/g, "\n"), ); toast.success("Copied GPU info to clipboard."); }; if (gpuType == "vainfo") { return ( Vainfo Output {vainfo ? (
Return Code: {vainfo.return_code}

Process {vainfo.return_code == 0 ? "Output" : "Error"}:

{vainfo.return_code == 0 ? vainfo.stdout : vainfo.stderr}
) : ( )}
); } else { return ( Nvidia SMI Output {nvinfo ? (
Name: {nvinfo["0"].name}

Driver: {nvinfo["0"].driver}

Cuda Compute Capability: {nvinfo["0"].cuda_compute}

VBios Info: {nvinfo["0"].vbios}
) : ( )}
); } }