I have been trying to read a .trace
file, which I had generated using a custom instruments template(instruments: Automator, Allocations, Leaks) using Instruments.
The best help I found in this stackoverflow answer. Basically the author created a custom Objective-C program(Traced) to read a specific type of Apples .trace
file(instrument: OpenGL ES Driver). His answer is geared towards XCode 4.6.
The code still works with XCode 6.1, but the trace-file seems to have changed slightly. You have to find the *.run.zip
file within the .trace
package and unzip it. In the extracted folder you now have to find the *.run
file. There are several *.run.zip
files in a .trace
package; one per used instrument.
Simply running the Traced program got me a uncaught exception 'NSArchiverArchiveInconsistency', reason: '*** class error for 'XRObjectAllocRun'
-error.
This error was initially easy to figure out. All I had to do was implement the missing class XRObjectAllocRun
; parallel to the example XRRun
or XRVideoCardRun
classes in XRRun.m.
This is how far I got and where I got stuck:
#import "XRObjectAllocRun.h"
@implementation XRObjectAllocRun
- (id)initWithCoder:(NSCoder *)decoder
{
if((self = [super init]))
{
NSObject *a = [decoder decodeObject];
NSObject *b = [decoder decodeObject];
NSObject *c = [decoder decodeObject];
NSObject *d = [decoder decodeObject];
NSObject *e = [decoder decodeObject];
NSObject *f = [decoder decodeObject];
NSObject *g = [decoder decodeObject];
NSObject *h = [decoder decodeObject];
NSObject *i = [decoder decodeObject];
// NSObject *j = [decoder decodeObject];
// NSObject *k = [decoder decodeObject];
NSLog(@"test");
}
return self;
}
@end
Basically I am stuck reverse-engineering the XRObjectAllocRun
class. But no matter how many or little objects I decode I always receive the following exception: uncaught exception 'NSArchiverArchiveInconsistency', reason: '*** NSUnarchiver: inconsistency between written and read data for object 0x100112750'
If you uncomment the last two decode
statements the program will crash with this exception: uncaught exception 'NSArchiverArchiveInconsistency', reason: '*** file inconsistency: read 'i', expecting '@''
.
Does anyone know the signature of Apples XRObjectAllocRun class? This class is used for the Allocations instrument.
Any help would be great!
Update
I played around with Swift and translated the entire *.trace
-reader - it fails with exactly the same error(s):
import Foundation
import Cocoa
@objc(XRObjectAllocRun)
class XRObjectAllocRun: NSObject {
func initWithCoder(decoder:NSCoder){
var x = decoder.decodeObject()
// this is where things start breaking...
}
}
@objc(XRRun)
class XRRun: NSObject {
// to be implemented
}
@objc(XRTrackSegment)
class XRTrackSegment: NSObject {
func initWithCoder(decoder:NSCoder)->NSString{
var a = decoder.decodeObject()?.integerValue
var b = decoder.decodeObject()?.integerValue
var c = decoder.decodeObject()?.integerValue
var d = decoder.decodeObject()?.integerValue
var e = decoder.decodeObject()
return "test"
}
}
@objc(PFTTrackSegment)
class PFTTrackSegment: NSObject {
func initWithCoder(decoder:NSCoder){
var a = decoder.decodeObject()?.integerValue
var b = decoder.decodeObject()?.integerValue
var c = decoder.decodeObject()?.integerValue
var d = decoder.decodeObject()?.integerValue
var e = decoder.decodeObject()?.integerValue
var f = decoder.decodeObject()?.integerValue
}
}
// parse command line
var traceFilePath = Process.arguments[1]
println("input: \(traceFilePath)")
var traceFile = NSURL(fileURLWithPath: traceFilePath)
var error:NSError?
// check if the file exists
if (traceFile?.checkResourceIsReachableAndReturnError(&error) == false){
// file does not exist or cannot be accessed
println("\(error)")
exit(1)
}
var rawData = NSData(contentsOfURL: traceFile!)
var data = NSUnarchiver(forReadingWithData: rawData!)
var decodedObject: AnyObject? = data?.decodeObject()
println("\(decodedObject)")