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

查看:13
本文介绍了试图读取 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,该命令行运行应用程序、分析和捕获数据,并将数据写入.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.

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

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 类(使用十六进制工具(我使用十六进制恶魔)打开时,它们有一个相当独特的标题,所以这是第一个线索).阅读起来相当简单,您所要做的就是调用 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

所以,NSArchiverNSUnarchiver 的问题在于,您首先需要拥有所有已归档的类,其次您必须按照存档的顺序读取数据(这是一个棘手的问题,我使用 class-dump 转储了一些所需类的接口,然后尝试取消存档数据对象通过对象并查看我返回的内容.幸运的是,NSArchiver 死时带有描述性错误消息,如果缺少一个类,它会告诉你它的名称是什么).我遇到的最大问题是 Instruments 二进制文件和使用的框架不包含我需要的所有类,特别是存档包含名为 XRVideoCardRun 的类的序列化数据.我假设 .trace 包中的 .template 文件包含一个具有所需类的动态库(我的意思是,它的大小超过 300kb 并且包含很多blobs(它是二进制 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天全站免登陆