MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / formatMemoryUsage

Function formatMemoryUsage

console/src/utils/format.ts:78–103  ·  view source on GitHub ↗
(
  memoryStats:
    | {
        size: bigint | number | null;
        memoryPercentage?: number | null;
      }
    | undefined,
)

Source from the content-addressed store, hash-verified

76}
77
78export function formatMemoryUsage(
79 memoryStats:
80 | {
81 size: bigint | number | null;
82 memoryPercentage?: number | null;
83 }
84 | undefined,
85) {
86 if (
87 !memoryStats ||
88 memoryStats.size === null ||
89 memoryStats.memoryPercentage === null
90 )
91 return "-";
92 const { size, memoryPercentage } = memoryStats;
93 const { value, unit } = humanizeBytes(BigInt(size));
94
95 const formattedMemoryUsage = `${value.toFixed(2)} ${unit}`;
96 if (!memoryPercentage) {
97 return formattedMemoryUsage;
98 }
99 const formattedPercentage =
100 memoryPercentage < 0.1 ? "< 0.1%" : `${memoryPercentage.toFixed(1)}%`;
101
102 return `${formattedMemoryUsage} (${formattedPercentage})`;
103}
104
105// For some reason TS doesn't ship with up-to-date type definitions [1]. Do the
106// hacky thing and handjam them in.

Callers 3

IndexTableFunction · 0.90
MaterializedViewTableFunction · 0.90

Calls 1

humanizeBytesFunction · 0.85

Tested by

no test coverage detected