#33 added support for importing from instruments indirectly via opening instruments and using the deep copy command. This PR adds support for importing `.trace` files directly, though only for time profiles specifically, and only for the highest sample count thread in the profile.
This PR adds `.trace` files from Instruments 9, and adds support for importing from either Instruments 8 and 9. The only major difference in the file format seems to be that Instruments 9 applies raw `zlib` compression generously throughout the file.
This PR also adds example `.trace` files for memory allocations, which are not supported for direct import. They use a totally different storage format for recording memory allocations, and I haven't yet figured out how that list of allocations references their corresponding callstack.
Lastly, this PR also adds examples from Instruments 7 since I happen to have a machine with an old version of Instruments. Import from Instruments 7 probably wouldn't be hard to add, but I haven't done that in this PR.
This currently only works in Chrome, and only via drag-and-drop of the files.
To test, drag the decompressed `simple-time-profile.trace` from 6016d970b9/sample/profiles/Instruments/9.3.1/simple-time-profile.trace.zip onto speedscope.
The result should be this:

Fixes #15
53 lines
763 B
C++
53 lines
763 B
C++
#include <cstdlib>
|
|
using namespace std;
|
|
|
|
void leakMemory() {
|
|
for (int i = 0, ii = rand() % 27; i < ii; i++) {
|
|
malloc(rand() % (10 * 1024));
|
|
}
|
|
}
|
|
|
|
void alpha() {
|
|
leakMemory();
|
|
int z = 3;
|
|
for (int i = 0, ii = rand() % 100000; i < ii; i++) {
|
|
z *= 3;
|
|
}
|
|
}
|
|
|
|
void beta() {
|
|
leakMemory();
|
|
int z = 3;
|
|
for (int i = 0, ii = rand() % 30000; i < ii; i++) {
|
|
z *= 3;
|
|
}
|
|
}
|
|
|
|
void delta() {
|
|
leakMemory();
|
|
int z = 3;
|
|
for (int i = 0, ii = rand() % 10000; i < ii; i++) {
|
|
z *= 3;
|
|
}
|
|
alpha();
|
|
beta();
|
|
}
|
|
|
|
void gamma() {
|
|
leakMemory();
|
|
int z = 3;
|
|
for (int i = 0, ii = rand() % 70000; i < ii; i++) {
|
|
z *= 3;
|
|
}
|
|
}
|
|
|
|
int main(int argc, char* argv[]) {
|
|
while (true) {
|
|
alpha();
|
|
beta();
|
|
delta();
|
|
gamma();
|
|
}
|
|
return 0;
|
|
}
|