From 2aad4649d83c33966b7cd7b659ae682321e4506a Mon Sep 17 00:00:00 2001 From: Da Shen Date: Mon, 23 Nov 2026 22:16:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[1056]=20tps=20=E8=80=97=E6=97=B6=E6=94=B9?= =?UTF-8?q?=E7=94=A8=20milliseconds-delta=20=E6=9E=84=E5=BB=BA=20time-delt?= =?UTF-8?q?a=20=E5=86=8D=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit agent_end 中用 (liii date-time) 的 milliseconds-delta 从单调时钟 毫秒差值构建 time-delta(h/m/s 分量由 goldfish 负责进位), %format-duration 改为从 time-delta 分量读回并格式化,替代原先 对裸秒数的手工进位。 依赖 goldfish 新增的 milliseconds-delta(MoganLab/goldfish#1767), 需在 goldfish 发版后合并。 --- extensions/tps.scm | 58 +++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/extensions/tps.scm b/extensions/tps.scm index 193637e0..1195ea03 100644 --- a/extensions/tps.scm +++ b/extensions/tps.scm @@ -22,6 +22,7 @@ (import (scheme base) (liii list) + (liii date-time) (liii pi ai time) (liii pi ai message) (liii pi code core extensions) @@ -139,37 +140,35 @@ ) ;cond ) ;define -;; 把耗时(秒)格式化为 human readable 时长: -;; < 60s "29.4s"(秒保留 1 位小数) -;; < 3600s "1m30s"(余秒非零)或 "12m"(整分) -;; >= 3600s "1h5m"(分取整数)。 - -(define (%format-duration s) - (cond ((not (number? s)) "0s") - ((< s 60) (string-append (%fixed-decimals s 1) "s")) - ((< s 3600) - (let* ((m (inexact->exact (truncate (/ s 60.0)))) (rest (- s (* m 60.0)))) - (if (> rest 0) - (string-append (number->string m) "m" (%fixed-decimals rest 0) "s") - (string-append (number->string m) "m") - ) ;if - ) ;let* - ) ; - (else - (let* ((h (inexact->exact (truncate (/ s 3600.0)))) (rest (- s (* h 3600.0)))) - (string-append (number->string h) - "h" - (number->string (inexact->exact (truncate (/ rest 60.0)))) - "m" - ) ;string-append - ) ;let* - ) ;else - ) ;cond +;; 把 time-delta 格式化为 human readable 时长(从分量读回): +;; 无 h 无 m "29.4s"(秒保留 1 位小数) +;; 有 m 无 h "1m30s"(余秒非零)或 "12m"(整分) +;; 有 h "1h5m"(分取整数)。 + +(define (%format-duration dt) + (let ((minutes (time-delta-minutes dt)) (hours (time-delta-hours dt))) + (cond ((and (zero? minutes) (zero? hours)) + (string-append (%fixed-decimals (exact->inexact (time-delta-seconds dt)) 1) "s")) + ((zero? hours) + (let ((rest (time-delta-seconds dt))) + (if (zero? rest) + (string-append (number->string minutes) "m") + (string-append (number->string minutes) + "m" + (%fixed-decimals (exact->inexact rest) 0) + "s" + ) ;string-append + ) ;if + ) ;let + ) ; + (else (string-append (number->string hours) "h" (number->string minutes) "m")) + ) ;cond + ) ;let ) ;define ;; 组装最终的 TPS 行。 -(define (%tps-line tps out in cr cw total elapsed-s) +(define (%tps-line tps out in cr cw total elapsed-dt) (string-append "TPS " (%human-readable tps 1 1) " tok/s. " @@ -187,7 +186,7 @@ "total " (%human-readable total 0 1) ", " - (%format-duration elapsed-s) + (%format-duration elapsed-dt) ) ;string-append ) ;define @@ -222,13 +221,14 @@ (cw (%sum-usage-key assistant-usages 'cacheWrite)) (total (%sum-usage-key assistant-usages 'totalTokens)) (elapsed-ms (- (pi-current-monotonic-millis) start-ms)) + (elapsed-dt (milliseconds-delta elapsed-ms)) (elapsed-s (if (number? elapsed-ms) (/ elapsed-ms 1000.0) 0.0)) (tps (if (> elapsed-s 0) (/ out elapsed-s) 0.0)) ) ; ;; 仅在确实有输出 token 时输出。对齐上游 ctx.ui.notify / ctx.hasUI: ;; 优先用 ctx 携带的 notify(TUI 已 arm),其次全局注入点,最后回退 stderr。 (when (> out 0) - (let ((line (%tps-line tps out in cr cw total elapsed-s)) + (let ((line (%tps-line tps out in cr cw total elapsed-dt)) (ctx-notify (and ctx (extension-context-notify ctx))) ) ; (unless (and (procedure? ctx-notify) (ctx-notify line)) From a632317c0dd7b3013a3d0a887af10dea9eaa5fd4 Mon Sep 17 00:00:00 2001 From: Da Shen Date: Tue, 24 Nov 2026 15:55:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[1056]=20=E6=A0=BC=E5=BC=8F=E5=8C=96=20tps?= =?UTF-8?q?=20=E6=89=A9=E5=B1=95=E4=BF=AE=E5=A4=8D=20CI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/tps.scm | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/extensions/tps.scm b/extensions/tps.scm index 1195ea03..172f0267 100644 --- a/extensions/tps.scm +++ b/extensions/tps.scm @@ -147,21 +147,23 @@ (define (%format-duration dt) (let ((minutes (time-delta-minutes dt)) (hours (time-delta-hours dt))) - (cond ((and (zero? minutes) (zero? hours)) - (string-append (%fixed-decimals (exact->inexact (time-delta-seconds dt)) 1) "s")) - ((zero? hours) - (let ((rest (time-delta-seconds dt))) - (if (zero? rest) - (string-append (number->string minutes) "m") - (string-append (number->string minutes) - "m" - (%fixed-decimals (exact->inexact rest) 0) - "s" - ) ;string-append - ) ;if - ) ;let - ) ; - (else (string-append (number->string hours) "h" (number->string minutes) "m")) + (cond + ((and (zero? minutes) (zero? hours)) + (string-append (%fixed-decimals (exact->inexact (time-delta-seconds dt)) 1) "s") + ) ; + ((zero? hours) + (let ((rest (time-delta-seconds dt))) + (if (zero? rest) + (string-append (number->string minutes) "m") + (string-append (number->string minutes) + "m" + (%fixed-decimals (exact->inexact rest) 0) + "s" + ) ;string-append + ) ;if + ) ;let + ) ; + (else (string-append (number->string hours) "h" (number->string minutes) "m")) ) ;cond ) ;let ) ;define