当 TQProfile.Enabled 值为 true 时,程序退出时,会将跟踪记录以 JSON 格式导出到 TQProfile.FileName 指定文件中,默认文件为程序运行目录下的 profiles.json,为了方便大家做跟踪分析,本教程来说明下各个字段的含义:
首先,我们来看示例程序生成的 profiles.json 的内容:
{
"mainThreadId":1528,
"freq":10000000,
"threads":[
{
"threadId":11100,
"startTime":57066653,
"latestTime":57067471,
"chains":[
{
"name":"TForm1.DoProfile",
"maxNestLevel":32,
"runs":1,
"minTime":0,
"maxTime":644,
"totalTime":644,
"avgTime":644
}
]
},
{
"threadId":1528,
"startTime":14070978,
"latestTime":56858345,
"chains":[
{
"name":"TForm1.Button1Click",
"maxNestLevel":0,
"runs":1,
"minTime":0,
"maxTime":765,
"totalTime":765,
"avgTime":765,
"children":[
{
"name":"TForm1.DoProfile",
"maxNestLevel":32,
"runs":1,
"minTime":0,
"maxTime":540,
"totalTime":540,
"avgTime":540
}
]
},
{
"name":"TForm1.Button1Click.ForceQueue",
"maxNestLevel":0,
"runs":1,
"minTime":0,
"maxTime":15547236,
"totalTime":15547236,
"avgTime":15547236,
"refs":[
"TForm1.Button1Click"
]
},
{
"name":"TForm1.Button5Click",
"maxNestLevel":0,
"runs":1,
"minTime":0,
"maxTime":770,
"totalTime":770,
"avgTime":770,
"children":[
{
"name":"TForm1.DoProfile",
"maxNestLevel":32,
"runs":1,
"minTime":0,
"maxTime":584,
"totalTime":584,
"avgTime":584
}
]
},
{
"name":"TForm1.Button5Click.ForceQueue",
"maxNestLevel":0,
"runs":1,
"minTime":0,
"maxTime":13112761,
"totalTime":13112761,
"avgTime":13112761,
"refs":[
"TForm1.Button5Click"
]
},
{
"name":"TForm1.Button3Click",
"maxNestLevel":0,
"runs":1,
"minTime":0,
"maxTime":817,
"totalTime":817,
"avgTime":817
}
]
}
]
}
- 根结点是一个对象结点,下面有 3个子结点
- mainThreadId 记录的是主线程 ID,在 threads 结点中,可以看到这个线程的基础信息
- freq 记录的是时间的频率,如果换算成秒,就是 时间戳/频率的值
- threads 是一个数组,记录的是每一个线程函数的调用层次关系,每个线程的相关信息为一个对象
- threadId 线程ID
- startTime 线程第一个跟踪记录时间
- latestTime 线程最后一个跟踪记录的时间
- chains 函数调用信息数组
- name 函数名
- maxNestLevel 最大嵌套循环层数
- runs 运行次数
- minTime 函数最小执行时间
- maxTime 函数最大执行时间
- totalTime 函数总执行时间
- avgTime 函数平均执行时间
- refs 调用本函数来源列表,一般用来记录异步执行操作的原始函数名称,具体参考前面的教程
对此格式如果有更多疑问,请在群里反馈或者发送邮件给我。