尝试读取 Xcode Instruments .trace 文件。.trace 文件的文件格式是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16737621/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:25:41  来源:igfitidea点击:

Trying to read a Xcode Instruments .trace file. What is the file format of a .trace file?

iphoneiosxcodeopengl-esinstruments

提问by georgeparrish

I am writing an automated profiling system, to profile different GPU intensive screens in my App. I have been trying to use 'XCode Instruments' for this, with the 'OpenGL ES Driver' instrument that captures the gpu usage data.

我正在编写一个自动分析系统,以在我的应用程序中分析不同的 GPU 密集型屏幕。为此,我一直在尝试使用“XCode Instruments”,以及捕获 gpu 使用数据的“OpenGL ES Driver”工具。

My automated system runs Xcode Instruments from the command line which runs the App, profiles and captures the data, and writes the data to a ".trace" file.

我的自动化系统从命令行运行 Xcode Instruments,该命令行运行应用程序、配置文件和捕获数据,并将数据写入“.trace”文件。

I now want to be able to open the trace file, and read the trace data using my automated profiling system, so that I can inform App developers of how the various parts of the App perform.

我现在希望能够打开跟踪文件,并使用我的自动分析系统读取跟踪数据,以便我可以通知应用程序开发人员应用程序的各个部分的执行情况。

I cannot however find any way of reading the trace file. It seems to be package which contain various directories, and buried in there is a .zip file which seems to contain some binary data. How is the data in this file parsed?

但是,我找不到任何读取跟踪文件的方法。它似乎是一个包含各种目录的包,其中埋藏着一个似乎包含一些二进制数据的 .zip 文件。这个文件中的数据是如何解析的?

The Instruments system seems fairly sosphisticated, and I've been suprised how hard it has been to access the trace data that it produces.

Instruments 系统似乎相当复杂,我很惊讶访问它产生的跟踪数据是多么困难。

Does anyone know how to parse the trace file?

有谁知道如何解析跟踪文件?

I am currently using XCode 4.6.1

我目前正在使用 XCode 4.6.1

回答by JustSid

Alright, so to answer the main question: The data in the .zip archive is a blob of data that was serialized with the NSArchiverclass (they have a fairly distinctive header when being opened with a hex tool (I used hex fiend), so that was the first clue). It's fairly straight forward to read, all you have to do is making a call to NSUnarchiver, at least that's the theory. Before I go in into the details, here is a very simple example app that dumps a few infos: https://github.com/JustSid/Traced

好的,所以要回答主要问题:.zip 存档中的数据是与NSArchiver类一起序列化的数据块(当使用十六进制工具(我使用 hex fiend)打开时,它们有一个相当独特的标头,因此是第一个线索)。读起来相当直接,你所要做的就是打电话给NSUnarchiver,至少这是理论。在我详细介绍之前,这里有一个非常简单的示例应用程序,它会转储一些信息:https: //github.com/JustSid/Traced

So, the problem with NSArchiver, and NSUnarchiver, is that you first of all need to have all the classes that were archived, and second of all you have to read the data out in the order in that it was archived (that was the tricky bit, I used class-dumpto dump the interface for a few of the required classes and then tried to unarchive the data object by object and looking at what I got returned. Luckily, NSArchiverdies with descriptive error messages, if there is a class missing, it will tell you what its name is). The biggest problem that I had was that the Instruments binary and the used frameworks don't contain all the classes that I needed, in particular the archive contains serialized data of a class named XRVideoCardRun. I have the assumption that the .templatefile inside the .tracebundle contains a dynamic library with the required class (I mean, it's over 300kb in size and contains a lot of blobs (it's btw a binary plist)). I was too lazy to extract the binary data out of it and run class-dumpagainst it, and I was lucky enough that most of the data that came out of the archive was consistent with what I was expecting to see for the superclass, XRRun(which I found in one of the Instruments frameworks), with the exception of an array containing dictionaries, which content looked like the sample data.

因此,NSArchiver, 和的问题NSUnarchiver在于您首先需要拥有所有已存档的类,其次您必须按照存档顺序读取数据(这是棘手的一点,我曾经class-dump为一些必需的类转储接口,然后尝试逐个对象解压缩数据对象并查看返回的内容。幸运的是,NSArchiver由于描述性错误消息而死亡,如果缺少类,它会告诉你它的名字是什么)。我遇到的最大问题是 Instruments 二进制文件和使用的框架不包含我需要的所有类,特别是存档包含名为XRVideoCardRun. 我假设.template里面的文件.tracebundle 包含一个具有所需类的动态库(我的意思是,它的大小超过 300kb 并且包含很多 blob(顺便说一句,它是一个二进制 plist))。我懒得从中提取二进制数据并运行class-dump它,而且我很幸运,从存档中出来的大部分数据与我期望看到的超类一致,XRRun(我发现在其中一个 Instruments 框架中),但包含字典的数组除外,其内容看起来像示例数据。

So, the rest was just combining everything together. If you look into the sample app, the most interesting part should be the XRRun.mand .hfile. They contain a bit of documentation, and some pieces on how to extract the data from the samples, although you probably want to replace this with your own logic for your automation. Hope it helps.

所以,剩下的就是把所有东西组合在一起。如果您查看示例应用程序,最有趣的部分应该是XRRun.mand.h文件。它们包含一些文档,以及一些关于如何从样本中提取数据的部分,尽管您可能希望将其替换为您自己的自动化逻辑。希望能帮助到你。

The app thrown agains your sample file outputs this:

再次抛出您的示例文件的应用程序输出如下:

Run 1, starting at 24.05.13 17:42:16, running until 24.05.13 17:42:28
Sample 0: FPS: 27 Device: 0% Renderer: 0% Tiler: 0% Timestamp: 1.012740
Sample 1: FPS: 35 Device: 11% Renderer: 10% Tiler: 2% Timestamp: 2.018574
Sample 2: FPS: 34 Device: 33% Renderer: 32% Tiler: 7% Timestamp: 3.026101
Sample 3: FPS: 59 Device: 59% Renderer: 59% Tiler: 16% Timestamp: 4.032030
Sample 4: FPS: 60 Device: 59% Renderer: 58% Tiler: 16% Timestamp: 5.038990
Sample 5: FPS: 59 Device: 59% Renderer: 58% Tiler: 16% Timestamp: 6.046022
Sample 6: FPS: 59 Device: 57% Renderer: 53% Tiler: 17% Timestamp: 7.051187
Sample 7: FPS: 60 Device: 67% Renderer: 66% Tiler: 14% Timestamp: 8.057343
Sample 8: FPS: 59 Device: 64% Renderer: 64% Tiler: 11% Timestamp: 9.064914
Sample 9: FPS: 60 Device: 67% Renderer: 67% Tiler: 11% Timestamp: 10.072592
Sample 10: FPS: 59 Device: 65% Renderer: 65% Tiler: 15% Timestamp: 11.080248

(PS: If the format changes, the app will break as well...)

(PS:如果格式改变,应用程序也会崩溃......)

回答by Qusic

I am trying to parse the .trace document using the undocumented frameworks shipped with Instruments itself. It is now working with Time Profiler and it shouldn't be hard to get it working with other instrument templates as well, with a little more reverse engineering work.

我正在尝试使用 Instruments 本身附带的未记录的框架来解析 .trace 文档。它现在正在与 Time Profiler 一起工作,并且通过更多的逆向工程工作,让它与其他乐器模板一起工作应该不难。

There are quite a few frameworks bundled with Instruments as you can see in /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/Frameworks.

正如您在/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/Frameworks.

However we only need to link against these two:

但是我们只需要链接这两个:

  • DVTInstrumentsFoundation.framework
  • InstrumentsPlugIn.framework
  • DVTInstrumentsFoundation.framework
  • InstrumentsPlugIn.framework

Another thing you should know before starting is that instrument templates are actually plugins in /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns.

在开始之前你应该知道的另一件事是仪器模板实际上是/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns.

For example, SamplerPlugin.xrpluginis for Time Profiler.

例如,SamplerPlugin.xrplugin用于时间分析器。

The code is short and commented out: https://github.com/Qusic/TraceUtility

代码很短,注释掉了:https: //github.com/Qusic/TraceUtility

回答by charleyh

You may not be able to analyze the Trace file directly with a script, but they can exported to a CSV file that can be analyzed by a script or put into Excel, Numbers, etc. You may even be able to add the export as a CSV to your automated testing, depending on how it is done.

您可能无法直接使用脚本分析 Trace 文件,但可以将它们导出为 CSV 文件,该文件可以通过脚本进行分析或放入 Excel、Numbers 等中。您甚至可以将导出添加为CSV 到您的自动化测试,具体取决于它是如何完成的。

回答by Thejus Krishna

.trace is actually a folder and it has a zip 1.run.zip in .trace/instruments_data/ and after some folders you will find the zip. Unzip it and you will get 1.run. Not sure how to decode that. Best way is to call - instruments .trace - this will open in instruments with the details.

.trace 实际上是一个文件夹,它在 .trace/instruments_data/ 中有一个 zip 1.run.zip,在一些文件夹之后你会找到 zip。解压它,你会得到 1.run。不知道如何解码。最好的方法是调用-instruments .trace-这将在带有详细信息的乐器中打开。