抖音开放平台Logo
开发者文档
“/”唤起搜索
控制台
  • JS API 列表
  • 基础
  • tt.canIUse
  • tt.canIPutStuffOverComponent
  • tt.base64ToArrayBuffer
  • tt.arrayBufferToBase64
  • tt.setPageInfo
  • 性能
  • tt.performance.createObserver
  • tt.performance.getEntries
  • tt.performance.getEntriesByName
  • tt.performance.getCurrentPageEntries
  • tt.performance.setBufferSize
  • PerformanceEntry
  • tt.performance.clearMarks
  • tt.performance.mark
  • tt.performance.getEntriesByPage
  • tt.performance.getEntriesByType
  • 线程
  • 窗口尺寸变化
  • 生命周期
  • 版本更新
  • 定时器
  • 应用级事件
  • 环境变量
  • TTML
  • 网络
  • 媒体
  • 地图
  • 文件
  • 数据缓存
  • 地理位置
  • 设备
  • 画布
  • 界面
  • 页面导航
  • 开放接口
  • 行业开放
  • 第三方平台
  • 其它
  • 生活服务(即将废弃)
  • 小程序智能体
  • tt.performance.mark
    收藏
    我的收藏

    基础库 1.42.1 开始支持本方法,低版本需做兼容处理
    在性能缓冲区中使用给定名称添加一个 name 为 [name] 的性能数据。

    语法

    tt.performance.mark(name)

    参数说明

    name

    类型
    默认值
    必填
    说明
    最低支持版本
    string
    期望标记的 name
    1.42.1

    返回值

      基础库 1.42.1 ~ 1.59.0 版本 无返回值

    代码示例

    // 创建一些标记 tt.performance && tt.performance.mark("bytedance"); tt.performance && tt.performance.mark("bytedance"); tt.performance && tt.performance.mark("toutiao"); tt.performance && tt.performance.mark("toutiao"); tt.performance && tt.performance.mark("douyin"); tt.performance && tt.performance.mark("douyin"); // 获取所有的 PerformanceMark 条目 const allEntries = tt.performance && tt.performance.getEntriesByType("mark"); console.log(allEntries.length); // 6 // 获取所有的名为 "bytedance" PerformanceMark 条目 const bytedanceEntries = tt.performance && tt.performance.performance.getEntriesByName("bytedance"); console.log(bytedanceEntries.length); // 2 // 删除所有标记。 tt.performance && tt.performance.clearMarks(); console.log(tt.performance && tt.performance.getEntriesByType("mark")); // 0

    标记FMP

    还可以利用 mark 统计上报 FMP 指标,如果 name 为 FMP,基础库会自动上报数据至服务端,开发者可以在开发者后台中选择自己的小程序,即可查看 FMP 数据。
    建议在关键首屏有意义的渲染当次setData回调里标记上报,保证指标的准确性。
    // 假设 FMP 依赖某个接口的数据,接口返回数据后 setData 更新页面后上报 FMP Page({ data: { pages: [], }, onLoad() { tt.request({ url: `${developer_api_url}`, success: (res) => { this.setData( { pages: res.data, }, () => { // 统计 FMP tt.performance && tt.performance.mark("FMP"); } ); }, fail: (err) => {}, }); }, });
      开发者控制台FMP数据
    在开发-性能分析-启动性能核心数据模块,切换到首次有意义渲染耗时( FMP )卡片即可。