Line data Source code
1 : import { toValue } from 'vue'
2 : import type { MaybeRefOrGetter } from 'vue'
3 :
4 : import {
5 : getColumnDisplayValue,
6 : systemStatsColumns
7 : } from '@/components/common/systemStatsColumns'
8 : import { useCopyToClipboard } from '@/composables/useCopyToClipboard'
9 : import { t } from '@/i18n'
10 : import type { SystemStats } from '@comfyorg/api-client/types'
11 : import { formatSize } from '@/utils/formatUtil'
12 :
13 0 : function formatSystemInfoText(stats: SystemStats): string {
14 0 : const lines: string[] = ['## System Info']
15 :
16 0 : for (const col of systemStatsColumns) {
17 0 : const display = getColumnDisplayValue(stats, col)
18 0 : if (display !== undefined && display !== '') {
19 0 : lines.push(`${t(col.headerKey)}: ${display}`)
20 : }
21 : }
22 :
23 0 : if (stats.devices.length > 0) {
24 0 : lines.push('')
25 0 : lines.push('## Devices')
26 0 : for (const device of stats.devices) {
27 0 : lines.push(`- ${device.name} (${device.type})`)
28 0 : lines.push(` VRAM Total: ${formatSize(device.vram_total)}`)
29 0 : lines.push(` VRAM Free: ${formatSize(device.vram_free)}`)
30 0 : lines.push(` Torch VRAM Total: ${formatSize(device.torch_vram_total)}`)
31 0 : lines.push(` Torch VRAM Free: ${formatSize(device.torch_vram_free)}`)
32 : }
33 : }
34 :
35 0 : return lines.join('\n')
36 : }
37 :
38 5 : export function useCopySystemInfo(stats: MaybeRefOrGetter<SystemStats>) {
39 5 : const { copyToClipboard } = useCopyToClipboard()
40 :
41 0 : function copySystemInfo() {
42 0 : return copyToClipboard(formatSystemInfoText(toValue(stats)))
43 : }
44 :
45 5 : return { copySystemInfo }
46 : }
|