试图读取Xcode Instruments .trace文件。 .trace文件的文件格式是什么? [英] Trying to read a Xcode Instruments .trace file. What is the file format of a .trace file?

查看:751
本文介绍了试图读取Xcode Instruments .trace文件。 .trace文件的文件格式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个自动分析系统,以便在我的应用程序中分析不同的GPU密集型屏幕。我一直试图使用'XCode Instruments',使用'OpenGL ES Driver'仪器来捕获gpu使用数据。

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.

我的自动化系统运行Xcode Instruments运行App的命令行,配置文件并捕获数据,并将数据写入.trace文件。

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.

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

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.

我无法找到任何读取跟踪文件的方法。它似乎是包含各种目录的包,并且埋没在.zip文件中似乎包含一些二进制数据。如何解析此文件中的数据?

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?

Instruments系统看起来相当复杂,我很惊讶访问它生成的跟踪数据有多难。

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

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

Does anyone know how to parse the trace file?

我目前正在使用XCode 4.6.1

I am currently using XCode 4.6.1

推荐答案

好的,回答主要问题:.zip存档中的数据是一系列数据,用于序列化 NSArchiver class(当用十六进制工具打开时,它们有一个相当独特的标题(我使用了十六进制恶魔),所以这是第一个线索)。这是非常直接的阅读,所有你要做的就是打电话给 NSUnarchiver ,至少这是理论。在进入细节之前,这是一个非常简单的示例应用程序,它会转储一些信息: https://github.com/JustSid/Traced

Alright, so to answer the main question: The data in the .zip archive is a blob of data that was serialized with the NSArchiver class (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

因此, NSArchiver NSUnarchiver ,首先你需要拥有所有已归档的类,其次你必须按顺序读取数据,因为它已归档(这是一个棘手的问题,我用过 class-dump 转储几个必需类的接口,然后尝试按对象取消归档数据对象并查看我返回的内容。幸运的是, NSArchiver 死于描述性错误消息,如果缺少类,它会告诉你它的名字是什么)。我遇到的最大问题是Instruments二进制文件和使用过的框架不包含我需要的所有类,特别是存档包含名为 XRVideoCardRun 。我假设 .trace 包中的 .template 文件包含一个带有所需类的动态库(I意思是,它的大小超过300kb并且包含许多blob(它是btw二进制plist))。我太懒了,无法从中提取二进制数据并对它运行 class-dump ,我很幸运,归档文件中出现的大部分数据都是与我期望看到的超类, XRRun (我在其中一个Instruments框架中找到)一致,但包含字典的数组除外,其内容看起来如此就像样本数据一样。

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-dump to 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, NSArchiver dies 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 .template file inside the .trace bundle 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-dump against 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.

所以,其余的只是将所有内容组合在一起。如果您查看示例应用程序,最有趣的部分应该是 XRRun.m .h 文件。它们包含一些文档,以及有关如何从示例中提取数据的一些内容,尽管您可能希望将其替换为您自己的逻辑以实现自动化。希望它有所帮助。

So, the rest was just combining everything together. If you look into the sample app, the most interesting part should be the XRRun.m and .h file. 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.

你的样本文件再次抛出的应用输出:

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:如果格式更改,应用程序也将中断...)

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

这篇关于试图读取Xcode Instruments .trace文件。 .trace文件的文件格式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆