You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

自定义Instrument中如何将时长纳入os-signpost-interval-schema输出值

自定义OS Signpost Interval Instrument:显示状态+时长

我有一个基于os-signpost-interval-schema的自定义Instrument,用来捕获状态字符串。想要在绘图中显示<state>: <duration>格式的内容,但不知道怎么把时长整合到显示字符串里。

当前的schema仅存储state列,代码如下:

<os-signpost-interval-schema>
    <id>state-interval</id>
    <title>State Interval</title>
    <subsystem>"..."</subsystem>
    <category>"..."</category>
    <name>"state"</name>
    <start-pattern>
        <message>?state</message>
    </start-pattern>

    <column>
        <mnemonic>state</mnemonic>
        <title>State</title>
        <type>string</type>
        <expression>?state</expression>
    </column>

</os-signpost-interval-schema>

尝试将列表达式改为(str-cat ?state ": " ?duration)时,出现报错:

Variable '?duration' must appear in a pattern element to be used in a later expression.

也曾尝试显式创建<duration-column>但无效果,找不到在图表、lane或绘图阶段进行计算的方法。


解决方案

核心问题是?duration属于interval类型数据的隐式属性,不属于signpost的message参数,无法直接在schema的列表达式中引用。需要通过在表中添加计算列的方式实现拼接:

1. 修改表定义,添加计算列

在create-table节点中新增add-column,用来拼接状态字符串和时长:

<create-table>
    <id>state-table</id>
    <schema-ref>state-interval</schema-ref>
    <!-- 添加状态+时长的计算列 -->
    <add-column>
        <mnemonic>state-with-duration</mnemonic>
        <title>State with Duration</title>
        <type>string</type>
        <!-- 使用format-duration格式化时长为易读格式,如"123ms" -->
        <expression>(str-cat ?state ": " (format-duration ?duration))</expression>
    </add-column>
</create-table>

2. 修改Lane配置,使用新的计算列

更新lane的plot配置,指向新增的state-with-duration列:

<lane>
    <title>State</title>
    <table-ref>state-table</table-ref>
    <plot>
        <value-from>state-with-duration</value-from>
    </plot>
</lane>

说明

  • format-duration函数会将时长(默认纳秒单位)转换为更易读的格式(如毫秒、秒),如果需要原始数值,直接使用?duration即可。
  • 原schema无需修改,保留state列用于基础数据存储,计算列仅用于显示拼接后的内容。

内容的提问来源于stack exchange,提问作者Rob Napier

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 20:25:23