Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add back GPU information to system monitoring bar #3350

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/src/types/events/resource.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ export interface ResourceStatus {
cpu: {
usage: number
}
gpus: GpuInfo[]
}

export interface UsedMemInfo {
total: number
used: number
}

export interface GpuInfo {
name: string | undefined
vram: UsedMemInfo
}
2 changes: 1 addition & 1 deletion electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"request": "^2.88.2",
"request-progress": "^3.0.0",
"@kirillvakalov/nut-tree__nut-js": "4.2.1-2",
"cortexso": "v0.5.0-40"
"cortexso": "v0.5.0-43"
},
"devDependencies": {
"@types/js-yaml": "4.0.9",
Expand Down
21 changes: 15 additions & 6 deletions web/containers/Layout/BottomPanel/SystemMonitor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const SystemMonitor: React.FC = () => {
const [usedRam, setUsedRam] = useAtom(usedRamAtom)
const [totalRam, setTotalRam] = useAtom(totalRamAtom)
const [cpuUsage, setCpuUsage] = useAtom(cpuUsageAtom)
const gpus = useAtomValue(gpusAtom)
const [gpus, setGpus] = useAtom(gpusAtom)

const [showFullScreen, setShowFullScreen] = useState(false)
const [showSystemMonitorPanel, setShowSystemMonitorPanel] = useAtom(
Expand Down Expand Up @@ -63,13 +63,18 @@ const SystemMonitor: React.FC = () => {
setUsedRam(resourceEvent.mem.used)
setTotalRam(resourceEvent.mem.total)
setCpuUsage(resourceEvent.cpu.usage)
setGpus(
resourceEvent.gpus?.filter(
(gpu) => gpu.name && gpu.vram.used && gpu.vram.total
) ?? []
)
} catch (err) {
console.error(err)
}
},
signal: abortControllerRef.current.signal,
})
}, [host, setTotalRam, setUsedRam, setCpuUsage])
}, [host, setTotalRam, setUsedRam, setCpuUsage, setGpus])

const unregister = useCallback(() => {
if (!abortControllerRef.current) return
Expand Down Expand Up @@ -195,8 +200,7 @@ const SystemMonitor: React.FC = () => {
<div className="flex gap-x-2">
<div className="">
<span>
{gpu.memoryTotal - gpu.memoryFree}/
{gpu.memoryTotal}
{gpu.vram.used}/{gpu.vram.total}
</span>
<span> MB</span>
</div>
Expand All @@ -205,12 +209,17 @@ const SystemMonitor: React.FC = () => {

<div className="flex items-center gap-x-4">
<Progress
value={gpu.utilization}
value={Math.round(
(gpu.vram.used / Math.max(gpu.vram.total, 1)) * 100
)}
className="w-full"
size="small"
/>
<span className="flex-shrink-0 ">
{gpu.utilization}%
{Math.round(
(gpu.vram.used / Math.max(gpu.vram.total, 1)) * 100
)}
%
</span>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion web/helpers/atoms/SystemBar.atom.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { GpuInfo } from '@janhq/core/.'
import { atom } from 'jotai'

export const totalRamAtom = atom<number>(0)
export const usedRamAtom = atom<number>(0)

export const cpuUsageAtom = atom<number>(0)

export const gpusAtom = atom<Record<string, never>[]>([])
export const gpusAtom = atom<GpuInfo[]>([])

export const nvidiaTotalVramAtom = atom<number>(0)
export const availableVramAtom = atom<number>(0)
Expand Down
Loading