跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

monitor_timing.go

55 行 · 1.7 KB历史下载
1package workbench
2
3import (
4 "fmt"
5 "strings"
6 "time"
7
8 "github.com/sylvinus/agent-vm/internal/diagnostics"
9)
10
11// Keep stage measurements in memory until the round ends so log writes do not
12// consume the time available to the next probe or the lease renewal.
13type monitorTiming struct {
14 started, checkpoint time.Time
15 until, verified time.Time
16 result string
17 stages []string
18}
19
20func (s *Server) startMonitorTiming() *monitorTiming {
21 now := time.Now()
22 timing := &monitorTiming{started: now, checkpoint: now, result: "completed"}
23 s.mu.Lock()
24 timing.verified = s.safety.VerifiedAt
25 if s.safety.Gate != nil {
26 timing.until = s.safety.Gate.Until
27 }
28 s.mu.Unlock()
29 return timing
30}
31
32func (t *monitorTiming) stage(name string) {
33 now := time.Now()
34 t.stages = append(t.stages, fmt.Sprintf("%s_ms=%d", name, now.Sub(t.checkpoint).Milliseconds()))
35 t.checkpoint = now
36}
37
38func (s *Server) recordMonitorTiming(kind string, timing *monitorTiming) {
39 if s.profile == "" {
40 return
41 }
42 finished := time.Now()
43 age, remainingStart, remainingEnd := int64(-1), int64(-1), int64(-1)
44 if !timing.verified.IsZero() {
45 age = timing.started.Sub(timing.verified).Milliseconds()
46 }
47 if !timing.until.IsZero() {
48 remainingStart = timing.until.Sub(timing.started).Milliseconds()
49 remainingEnd = timing.until.Sub(finished).Milliseconds()
50 }
51 _ = diagnostics.New(s.profile).Record("info", "network-monitor", fmt.Sprintf(
52 "monitor=%s started=%s duration_ms=%d result=%s verified_age_ms=%d lease_known=%t lease_remaining_start_ms=%d lease_remaining_end_ms=%d %s",
53 kind, timing.started.UTC().Format(time.RFC3339Nano), finished.Sub(timing.started).Milliseconds(),
54 timing.result, age, !timing.until.IsZero(), remainingStart, remainingEnd, strings.Join(timing.stages, " ")))
55}