Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

resourceTelemetry.ts

568 lines21.6 KB

1import * as Schema from "effect/Schema";
2​
3import { NonNegativeInt, PositiveInt, TrimmedNonEmptyString } from "./baseSchemas.ts";
4import { HostPowerSnapshot } from "./background.ts";
5import { DesktopUpdateChannelSchema, DesktopUpdateStateSchema } from "./ipc.ts";
6​
7export const RESOURCE_MONITOR_PROTOCOL_VERSION = 3 as const;
8​
9export const HostResourcesSnapshot = Schema.Struct({
10 sampledAt: NonNegativeInt,
11 cpuUtilization: Schema.NullOr(Schema.Number.check(Schema.isBetween({ minimum: 0, maximum: 1 }))),
12 cpuCount: NonNegativeInt,
13 availableMemoryBytes: NonNegativeInt,
14 totalMemoryBytes: NonNegativeInt,
15});
16export type HostResourcesSnapshot = typeof HostResourcesSnapshot.Type;
17​
18export const ResourceTelemetryIoSemantics = Schema.Literals([
19 "storage",
20 "logical",
21 "all-io",
22 "unavailable",
23]);
24export type ResourceTelemetryIoSemantics = typeof ResourceTelemetryIoSemantics.Type;
25​
26export const ResourceTelemetryProcessCategory = Schema.Literals([
27 "server",
28 "server-child",
29 "provider-root",
30 "terminal-root",
31 "electron-main",
32 "electron-renderer",
33 "electron-gpu",
34 "electron-utility",
35 "resource-monitor",
36 "unknown-t3",
37]);
38export type ResourceTelemetryProcessCategory = typeof ResourceTelemetryProcessCategory.Type;
39​
40export const ResourceTelemetrySourceStatus = Schema.Literals([
41 "starting",
42 "healthy",
43 "degraded",
44 "unavailable",
45 "stopped",
46]);
47export type ResourceTelemetrySourceStatus = typeof ResourceTelemetrySourceStatus.Type;
48​
49export const ResourceTelemetryProcessIdentity = Schema.Struct({
50 pid: PositiveInt,
51 startTimeMs: NonNegativeInt,
52});
53export type ResourceTelemetryProcessIdentity = typeof ResourceTelemetryProcessIdentity.Type;
54​
55export const ResourceMonitorExternalProcess = Schema.Struct({
56 pid: PositiveInt,
57 startTimeMs: Schema.optionalKey(NonNegativeInt),
58});
59export type ResourceMonitorExternalProcess = typeof ResourceMonitorExternalProcess.Type;
60​
61export const ResourceMonitorCapabilities = Schema.Struct({
62 cumulativeCpuTime: Schema.Boolean,
63 currentCpuPercent: Schema.Boolean,
64 residentMemory: Schema.Boolean,
65 virtualMemory: Schema.Boolean,
66 ioBytes: Schema.Boolean,
67 processStartTime: Schema.Boolean,
68 processTree: Schema.Boolean,
69 processIdentities: Schema.optionalKey(Schema.Boolean),
70});
71export type ResourceMonitorCapabilities = typeof ResourceMonitorCapabilities.Type;
72​
73export const ResourceMonitorProcessSample = Schema.Struct({
74 pid: PositiveInt,
75 ppid: NonNegativeInt,
76 startTimeMs: NonNegativeInt,
77 runTimeMs: NonNegativeInt,
78 name: Schema.String,
79 command: Schema.String,
80 status: Schema.String,
81 cpuPercent: Schema.Number,
82 cpuTimeMs: NonNegativeInt,
83 residentBytes: NonNegativeInt,
84 virtualBytes: NonNegativeInt,
85 ioReadBytes: NonNegativeInt,
86 ioWriteBytes: NonNegativeInt,
87 ioSemantics: Schema.Literals(["storage", "all-io"]),
88});
89export type ResourceMonitorProcessSample = typeof ResourceMonitorProcessSample.Type;
90​
91export const ResourceMonitorConfigureCommand = Schema.Struct({
92 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
93 type: Schema.Literal("configure"),
94 rootPid: PositiveInt,
95 sampleIntervalMs: NonNegativeInt,
96 externalProcesses: Schema.Array(ResourceMonitorExternalProcess),
97});
98export type ResourceMonitorConfigureCommand = typeof ResourceMonitorConfigureCommand.Type;
99​
100export const ResourceMonitorSetExternalProcessesCommand = Schema.Struct({
101 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
102 type: Schema.Literal("setExternalProcesses"),
103 processes: Schema.Array(ResourceMonitorExternalProcess),
104});
105export type ResourceMonitorSetExternalProcessesCommand =
106 typeof ResourceMonitorSetExternalProcessesCommand.Type;
107​
108export const ResourceMonitorSampleNowCommand = Schema.Struct({
109 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
110 type: Schema.Literal("sampleNow"),
111 requestId: TrimmedNonEmptyString,
112});
113export type ResourceMonitorSampleNowCommand = typeof ResourceMonitorSampleNowCommand.Type;
114​
115export const ResourceMonitorProcessTableCommand = Schema.Struct({
116 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
117 type: Schema.Literal("processTable"),
118 identities: Schema.optionalKey(Schema.Boolean),
119 requestId: TrimmedNonEmptyString,
120});
121export type ResourceMonitorProcessTableCommand = typeof ResourceMonitorProcessTableCommand.Type;
122​
123export const ResourceMonitorSetSampleIntervalCommand = Schema.Struct({
124 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
125 type: Schema.Literal("setSampleInterval"),
126 sampleIntervalMs: NonNegativeInt,
127});
128export type ResourceMonitorSetSampleIntervalCommand =
129 typeof ResourceMonitorSetSampleIntervalCommand.Type;
130​
131export const ResourceMonitorSetStreamingCommand = Schema.Struct({
132 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
133 type: Schema.Literal("setStreaming"),
134 enabled: Schema.Boolean,
135});
136export type ResourceMonitorSetStreamingCommand = typeof ResourceMonitorSetStreamingCommand.Type;
137​
138export const ResourceMonitorReadHistoryCommand = Schema.Struct({
139 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
140 type: Schema.Literal("readHistory"),
141 requestId: TrimmedNonEmptyString,
142 windowMs: NonNegativeInt,
143});
144export type ResourceMonitorReadHistoryCommand = typeof ResourceMonitorReadHistoryCommand.Type;
145​
146export const ResourceMonitorShutdownCommand = Schema.Struct({
147 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
148 type: Schema.Literal("shutdown"),
149});
150export type ResourceMonitorShutdownCommand = typeof ResourceMonitorShutdownCommand.Type;
151​
152export const ResourceMonitorCommand = Schema.Union([
153 ResourceMonitorConfigureCommand,
154 ResourceMonitorSetExternalProcessesCommand,
155 ResourceMonitorSetSampleIntervalCommand,
156 ResourceMonitorSetStreamingCommand,
157 ResourceMonitorSampleNowCommand,
158 ResourceMonitorProcessTableCommand,
159 ResourceMonitorReadHistoryCommand,
160 ResourceMonitorShutdownCommand,
161]);
162export type ResourceMonitorCommand = typeof ResourceMonitorCommand.Type;
163​
164export const ResourceMonitorHelloEvent = Schema.Struct({
165 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
166 type: Schema.Literal("hello"),
167 sidecarVersion: TrimmedNonEmptyString,
168 sidecarPid: PositiveInt,
169 platform: TrimmedNonEmptyString,
170 arch: TrimmedNonEmptyString,
171 capabilities: ResourceMonitorCapabilities,
172});
173export type ResourceMonitorHelloEvent = typeof ResourceMonitorHelloEvent.Type;
174​
175export const ResourceMonitorSnapshotEvent = Schema.Struct({
176 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
177 type: Schema.Literal("snapshot"),
178 sequence: NonNegativeInt,
179 sampledAtUnixMs: NonNegativeInt,
180 collectionDurationMicros: NonNegativeInt,
181 scannedProcessCount: NonNegativeInt,
182 retainedProcessCount: NonNegativeInt,
183 inaccessibleProcessCount: NonNegativeInt,
184 requestId: Schema.optionalKey(TrimmedNonEmptyString),
185 externalProcesses: Schema.optionalKey(Schema.Array(ResourceMonitorExternalProcess)),
186 processes: Schema.Array(ResourceMonitorProcessSample),
187});
188export type ResourceMonitorSnapshotEvent = typeof ResourceMonitorSnapshotEvent.Type;
189​
190export const ResourceMonitorProcessTableEntry = Schema.Struct({
191 pgid: Schema.optionalKey(NonNegativeInt),
192 startTimeMicros: Schema.optionalKey(NonNegativeInt),
193 pid: PositiveInt,
194 ppid: NonNegativeInt,
195 name: Schema.String,
196});
197export type ResourceMonitorProcessTableEntry = typeof ResourceMonitorProcessTableEntry.Type;
198​
199export const ResourceMonitorProcessTableEvent = Schema.Struct({
200 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
201 type: Schema.Literal("processTable"),
202 requestId: TrimmedNonEmptyString,
203 processes: Schema.Array(ResourceMonitorProcessTableEntry),
204});
205export type ResourceMonitorProcessTableEvent = typeof ResourceMonitorProcessTableEvent.Type;
206​
207export const ResourceMonitorHistoryChunkEvent = Schema.Struct({
208 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
209 type: Schema.Literal("historyChunk"),
210 requestId: TrimmedNonEmptyString,
211 done: Schema.Boolean,
212 snapshots: Schema.Array(ResourceMonitorSnapshotEvent),
213});
214export type ResourceMonitorHistoryChunkEvent = typeof ResourceMonitorHistoryChunkEvent.Type;
215​
216export const ResourceMonitorErrorEvent = Schema.Struct({
217 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
218 type: Schema.Literal("error"),
219 code: TrimmedNonEmptyString,
220 message: TrimmedNonEmptyString,
221 recoverable: Schema.Boolean,
222});
223export type ResourceMonitorErrorEvent = typeof ResourceMonitorErrorEvent.Type;
224​
225export const ResourceMonitorEvent = Schema.Union([
226 ResourceMonitorHelloEvent,
227 ResourceMonitorSnapshotEvent,
228 ResourceMonitorProcessTableEvent,
229 ResourceMonitorHistoryChunkEvent,
230 ResourceMonitorErrorEvent,
231]);
232export type ResourceMonitorEvent = typeof ResourceMonitorEvent.Type;
233​
234export const DesktopElectronProcessType = Schema.Literals([
235 "Browser",
236 "Tab",
237 "Utility",
238 "Zygote",
239 "Sandbox helper",
240 "GPU",
241 "Pepper Plugin",
242 "Pepper Plugin Broker",
243 "Unknown",
244]);
245export type DesktopElectronProcessType = typeof DesktopElectronProcessType.Type;
246​
247export const DesktopElectronProcessMetric = Schema.Struct({
248 pid: PositiveInt,
249 creationTimeMs: NonNegativeInt,
250 type: DesktopElectronProcessType,
251 name: Schema.optionalKey(Schema.String),
252 serviceName: Schema.optionalKey(Schema.String),
253 cpuPercent: Schema.Number,
254 cumulativeCpuSeconds: Schema.optionalKey(Schema.Number),
255 idleWakeupsPerSecond: Schema.Number,
256 workingSetBytes: NonNegativeInt,
257 peakWorkingSetBytes: NonNegativeInt,
258});
259export type DesktopElectronProcessMetric = typeof DesktopElectronProcessMetric.Type;
260​
261const DesktopHostPowerSnapshot = Schema.Struct({
262 ...HostPowerSnapshot.fields,
263 updatedAt: Schema.DateTimeUtcFromString,
264});
265​
266export const DesktopHostTelemetrySnapshot = Schema.Struct({
267 version: Schema.Literal(1),
268 type: Schema.Literal("desktopTelemetry"),
269 sequence: NonNegativeInt,
270 sampledAtUnixMs: NonNegativeInt,
271 electronPid: PositiveInt,
272 power: DesktopHostPowerSnapshot,
273 speedLimitPercent: Schema.OptionFromNullOr(Schema.Number),
274 electronProcesses: Schema.Array(DesktopElectronProcessMetric),
275});
276export type DesktopHostTelemetrySnapshot = typeof DesktopHostTelemetrySnapshot.Type;
277​
278export const DesktopHostTelemetryHello = Schema.Struct({
279 version: Schema.Literal(1),
280 type: Schema.Literal("desktopTelemetryHello"),
281 electronPid: PositiveInt,
282});
283export type DesktopHostTelemetryHello = typeof DesktopHostTelemetryHello.Type;
284​
285export const DesktopUpdateRemoteOutcome = Schema.Literals([
286 "ready-to-install",
287 "up-to-date",
288 "failed",
289]);
290export type DesktopUpdateRemoteOutcome = typeof DesktopUpdateRemoteOutcome.Type;
291​
292export const DesktopUpdateStatusReport = Schema.Struct({
293 version: Schema.Literal(1),
294 type: Schema.Literal("desktopUpdateStatus"),
295 requestId: Schema.optionalKey(TrimmedNonEmptyString),
296 preparedRequestId: Schema.optionalKey(TrimmedNonEmptyString),
297 outcome: Schema.optionalKey(DesktopUpdateRemoteOutcome),
298 reason: Schema.optionalKey(TrimmedNonEmptyString),
299 state: DesktopUpdateStateSchema,
300});
301export type DesktopUpdateStatusReport = typeof DesktopUpdateStatusReport.Type;
302​
303export const ShellEnvironmentPatch = Schema.Struct({
304 PATH: Schema.optionalKey(Schema.NullOr(Schema.String)),
305 ANDROID_HOME: Schema.optionalKey(Schema.NullOr(Schema.String)),
306 ANDROID_SDK_ROOT: Schema.optionalKey(Schema.NullOr(Schema.String)),
307 DBUS_SESSION_BUS_ADDRESS: Schema.optionalKey(Schema.NullOr(Schema.String)),
308 DISPLAY: Schema.optionalKey(Schema.NullOr(Schema.String)),
309 LANG: Schema.optionalKey(Schema.NullOr(Schema.String)),
310 LC_ALL: Schema.optionalKey(Schema.NullOr(Schema.String)),
311 LC_CTYPE: Schema.optionalKey(Schema.NullOr(Schema.String)),
312 SSH_AUTH_SOCK: Schema.optionalKey(Schema.NullOr(Schema.String)),
313 HOMEBREW_PREFIX: Schema.optionalKey(Schema.NullOr(Schema.String)),
314 HOMEBREW_CELLAR: Schema.optionalKey(Schema.NullOr(Schema.String)),
315 HOMEBREW_REPOSITORY: Schema.optionalKey(Schema.NullOr(Schema.String)),
316 XDG_CONFIG_HOME: Schema.optionalKey(Schema.NullOr(Schema.String)),
317 XDG_CURRENT_DESKTOP: Schema.optionalKey(Schema.NullOr(Schema.String)),
318 XDG_DATA_HOME: Schema.optionalKey(Schema.NullOr(Schema.String)),
319 XDG_RUNTIME_DIR: Schema.optionalKey(Schema.NullOr(Schema.String)),
320 XDG_SESSION_DESKTOP: Schema.optionalKey(Schema.NullOr(Schema.String)),
321 XDG_SESSION_TYPE: Schema.optionalKey(Schema.NullOr(Schema.String)),
322 WAYLAND_DISPLAY: Schema.optionalKey(Schema.NullOr(Schema.String)),
323 SSL_CERT_FILE: Schema.optionalKey(Schema.NullOr(Schema.String)),
324 SSL_CERT_DIR: Schema.optionalKey(Schema.NullOr(Schema.String)),
325 NODE_EXTRA_CA_CERTS: Schema.optionalKey(Schema.NullOr(Schema.String)),
326 T3CODE_TELEMETRY_ENABLED: Schema.optionalKey(Schema.NullOr(Schema.String)),
327 DO_NOT_TRACK: Schema.optionalKey(Schema.NullOr(Schema.String)),
328 T3CODE_FEATURE_FLAGS: Schema.optionalKey(Schema.NullOr(Schema.String)),
329 T3CODE_RELEASE_BASE_URL: Schema.optionalKey(Schema.NullOr(Schema.String)),
330 __MISE_DIFF: Schema.optionalKey(Schema.NullOr(Schema.String)),
331 JAVA_HOME: Schema.optionalKey(Schema.NullOr(Schema.String)),
332 PNPM_HOME: Schema.optionalKey(Schema.NullOr(Schema.String)),
333 FNM_DIR: Schema.optionalKey(Schema.NullOr(Schema.String)),
334 FNM_MULTISHELL_PATH: Schema.optionalKey(Schema.NullOr(Schema.String)),
335});
336export type ShellEnvironmentPatch = typeof ShellEnvironmentPatch.Type;
337​
338export const DesktopShellEnvironmentSnapshot = Schema.Struct({
339 version: Schema.Literal(1),
340 type: Schema.Literal("shellEnvironment"),
341 discovered: Schema.Boolean,
342 platform: Schema.String,
343 environment: ShellEnvironmentPatch,
344});
345export type DesktopShellEnvironmentSnapshot = typeof DesktopShellEnvironmentSnapshot.Type;
346​
347export const DesktopHostTelemetryMessage = Schema.Union([
348 DesktopHostTelemetryHello,
349 DesktopShellEnvironmentSnapshot,
350 DesktopHostTelemetrySnapshot,
351 DesktopUpdateStatusReport,
352]);
353export type DesktopHostTelemetryMessage = typeof DesktopHostTelemetryMessage.Type;
354​
355export const DesktopTelemetrySetDiagnosticsDemand = Schema.Struct({
356 version: Schema.Literal(1),
357 type: Schema.Literal("setDiagnosticsDemand"),
358 enabled: Schema.Boolean,
359});
360export type DesktopTelemetrySetDiagnosticsDemand = typeof DesktopTelemetrySetDiagnosticsDemand.Type;
361​
362export const DesktopTelemetrySetHostPowerIntervals = Schema.Struct({
363 version: Schema.Literal(1),
364 type: Schema.Literal("setHostPowerIntervals"),
365 activeIntervalMs: PositiveInt,
366 idleIntervalMs: PositiveInt,
367});
368export type DesktopTelemetrySetHostPowerIntervals =
369 typeof DesktopTelemetrySetHostPowerIntervals.Type;
370​
371/** Runs check/download/quit-and-install without local confirmation; the remote RPC click supplies consent. */
372export const DesktopTelemetryRequestDesktopUpdate = Schema.Struct({
373 version: Schema.Literal(1),
374 type: Schema.Literal("requestDesktopUpdate"),
375 requestId: TrimmedNonEmptyString,
376 /** A track switch: move to this channel first, and install only `targetVersion`. */
377 channel: Schema.optionalKey(DesktopUpdateChannelSchema),
378 targetVersion: Schema.optionalKey(TrimmedNonEmptyString),
379});
380export type DesktopTelemetryRequestDesktopUpdate = typeof DesktopTelemetryRequestDesktopUpdate.Type;
381​
382export const DesktopTelemetryCommitDesktopUpdate = Schema.Struct({
383 version: Schema.Literal(1),
384 type: Schema.Literal("commitDesktopUpdate"),
385 requestId: TrimmedNonEmptyString,
386});
387export type DesktopTelemetryCommitDesktopUpdate = typeof DesktopTelemetryCommitDesktopUpdate.Type;
388​
389export const DesktopTelemetryCancelDesktopUpdate = Schema.Struct({
390 version: Schema.Literal(1),
391 type: Schema.Literal("cancelDesktopUpdate"),
392 requestId: TrimmedNonEmptyString,
393});
394export type DesktopTelemetryCancelDesktopUpdate = typeof DesktopTelemetryCancelDesktopUpdate.Type;
395​
396/** The server accepts requests; the desktop treats this as backend readiness. */
397export const DesktopTelemetryServerReady = Schema.Struct({
398 version: Schema.Literal(1),
399 type: Schema.Literal("serverReady"),
400});
401export type DesktopTelemetryServerReady = typeof DesktopTelemetryServerReady.Type;
402​
403export const DesktopTelemetryControlMessage = Schema.Union([
404 DesktopTelemetryServerReady,
405 DesktopTelemetrySetDiagnosticsDemand,
406 DesktopTelemetrySetHostPowerIntervals,
407 DesktopTelemetryRequestDesktopUpdate,
408 DesktopTelemetryCommitDesktopUpdate,
409 DesktopTelemetryCancelDesktopUpdate,
410]);
411export type DesktopTelemetryControlMessage = typeof DesktopTelemetryControlMessage.Type;
412​
413export const ResourceTelemetryProcess = Schema.Struct({
414 identity: ResourceTelemetryProcessIdentity,
415 ppid: NonNegativeInt,
416 childPids: Schema.Array(PositiveInt),
417 depth: NonNegativeInt,
418 name: Schema.String,
419 command: Schema.String,
420 status: Schema.String,
421 category: ResourceTelemetryProcessCategory,
422 electronType: Schema.optionalKey(DesktopElectronProcessType),
423 electronServiceName: Schema.optionalKey(Schema.String),
424 cpuPercent: Schema.Number,
425 cpuTimeMs: NonNegativeInt,
426 residentBytes: NonNegativeInt,
427 peakResidentBytes: NonNegativeInt,
428 virtualBytes: NonNegativeInt,
429 ioReadBytes: NonNegativeInt,
430 ioWriteBytes: NonNegativeInt,
431 ioReadBytesPerSecond: Schema.Number,
432 ioWriteBytesPerSecond: Schema.Number,
433 ioSemantics: ResourceTelemetryIoSemantics,
434 idleWakeupsPerSecond: Schema.optionalKey(Schema.Number),
435 runTimeMs: NonNegativeInt,
436 firstSeenAt: Schema.DateTimeUtc,
437 lastSeenAt: Schema.DateTimeUtc,
438});
439export type ResourceTelemetryProcess = typeof ResourceTelemetryProcess.Type;
440​
441export const ResourceTelemetryAggregate = Schema.Struct({
442 processCount: NonNegativeInt,
443 currentCpuPercent: Schema.Number,
444 cpuTimeMs: NonNegativeInt,
445 currentRssBytes: NonNegativeInt,
446 peakRssBytes: NonNegativeInt,
447 ioReadBytes: NonNegativeInt,
448 ioWriteBytes: NonNegativeInt,
449 ioReadBytesPerSecond: Schema.Number,
450 ioWriteBytesPerSecond: Schema.Number,
451 processStarts: NonNegativeInt,
452 processExits: NonNegativeInt,
453});
454export type ResourceTelemetryAggregate = typeof ResourceTelemetryAggregate.Type;
455​
456export const ResourceTelemetryGroups = Schema.Struct({
457 backend: ResourceTelemetryAggregate,
458 electron: ResourceTelemetryAggregate,
459 monitor: ResourceTelemetryAggregate,
460 allT3: ResourceTelemetryAggregate,
461});
462export type ResourceTelemetryGroups = typeof ResourceTelemetryGroups.Type;
463​
464export const ResourceTelemetrySourceHealth = Schema.Struct({
465 status: ResourceTelemetrySourceStatus,
466 lastSampleAt: Schema.Option(Schema.DateTimeUtc),
467 lastError: Schema.Option(TrimmedNonEmptyString),
468});
469export type ResourceTelemetrySourceHealth = typeof ResourceTelemetrySourceHealth.Type;
470​
471export const ResourceTelemetryHealth = Schema.Struct({
472 native: ResourceTelemetrySourceHealth,
473 desktop: ResourceTelemetrySourceHealth,
474 sidecarVersion: Schema.Option(TrimmedNonEmptyString),
475 sidecarPid: Schema.Option(PositiveInt),
476 restartCount: NonNegativeInt,
477 collectionDurationMicros: NonNegativeInt,
478 scannedProcessCount: NonNegativeInt,
479 retainedProcessCount: NonNegativeInt,
480 inaccessibleProcessCount: NonNegativeInt,
481});
482export type ResourceTelemetryHealth = typeof ResourceTelemetryHealth.Type;
483​
484export const ResourceAttributionEntry = Schema.Struct({
485 component: TrimmedNonEmptyString,
486 operation: TrimmedNonEmptyString,
487 logicalReadBytes: NonNegativeInt,
488 logicalWriteBytes: NonNegativeInt,
489 count: NonNegativeInt,
490 durationMs: NonNegativeInt,
491});
492export type ResourceAttributionEntry = typeof ResourceAttributionEntry.Type;
493​
494export const ResourceAttributionSnapshot = Schema.Struct({
495 readAt: Schema.DateTimeUtc,
496 entries: Schema.Array(ResourceAttributionEntry),
497});
498export type ResourceAttributionSnapshot = typeof ResourceAttributionSnapshot.Type;
499​
500export const ResourceTelemetrySnapshot = Schema.Struct({
501 readAt: Schema.DateTimeUtc,
502 sampleIntervalMs: NonNegativeInt,
503 processes: Schema.Array(ResourceTelemetryProcess),
504 groups: ResourceTelemetryGroups,
505 power: HostPowerSnapshot,
506 speedLimitPercent: Schema.Option(Schema.Number),
507 attribution: ResourceAttributionSnapshot,
508 health: ResourceTelemetryHealth,
509});
510export type ResourceTelemetrySnapshot = typeof ResourceTelemetrySnapshot.Type;
511​
512export const ResourceTelemetryHistoryInput = Schema.Struct({
513 windowMs: NonNegativeInt,
514 bucketMs: NonNegativeInt,
515});
516export type ResourceTelemetryHistoryInput = typeof ResourceTelemetryHistoryInput.Type;
517​
518export const ResourceTelemetryHistoryBucket = Schema.Struct({
519 startedAt: Schema.DateTimeUtc,
520 endedAt: Schema.DateTimeUtc,
521 avgCpuPercent: Schema.Number,
522 maxCpuPercent: Schema.Number,
523 maxRssBytes: NonNegativeInt,
524 ioReadBytes: NonNegativeInt,
525 ioWriteBytes: NonNegativeInt,
526 maxProcessCount: NonNegativeInt,
527});
528export type ResourceTelemetryHistoryBucket = typeof ResourceTelemetryHistoryBucket.Type;
529​
530export const ResourceTelemetryProcessSummary = Schema.Struct({
531 identity: ResourceTelemetryProcessIdentity,
532 ppid: NonNegativeInt,
533 depth: NonNegativeInt,
534 name: Schema.String,
535 command: Schema.String,
536 category: ResourceTelemetryProcessCategory,
537 firstSeenAt: Schema.DateTimeUtc,
538 lastSeenAt: Schema.DateTimeUtc,
539 currentCpuPercent: Schema.Number,
540 avgCpuPercent: Schema.Number,
541 maxCpuPercent: Schema.Number,
542 cpuTimeMs: NonNegativeInt,
543 currentRssBytes: NonNegativeInt,
544 peakRssBytes: NonNegativeInt,
545 ioReadBytes: NonNegativeInt,
546 ioWriteBytes: NonNegativeInt,
547 ioSemantics: ResourceTelemetryIoSemantics,
548 sampleCount: NonNegativeInt,
549});
550export type ResourceTelemetryProcessSummary = typeof ResourceTelemetryProcessSummary.Type;
551​
552export const ResourceTelemetryHistory = Schema.Struct({
553 readAt: Schema.DateTimeUtc,
554 windowMs: NonNegativeInt,
555 bucketMs: NonNegativeInt,
556 sampleIntervalMs: NonNegativeInt,
557 retainedSampleCount: NonNegativeInt,
558 buckets: Schema.Array(ResourceTelemetryHistoryBucket),
559 topProcesses: Schema.Array(ResourceTelemetryProcessSummary),
560 health: ResourceTelemetryHealth,
561});
562export type ResourceTelemetryHistory = typeof ResourceTelemetryHistory.Type;
563​
564export const ResourceTelemetryRetryResult = Schema.Struct({
565 accepted: Schema.Boolean,
566 snapshot: ResourceTelemetrySnapshot,
567});
568export type ResourceTelemetryRetryResult = typeof ResourceTelemetryRetryResult.Type;