1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/**
* Copyright (C) ARM Limited 2010-2011. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
typedef unsigned long long uint64_t;
typedef long long int64_t;
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include "SessionData.h"
#include "CapturedXML.h"
#include "Logging.h"
#include "OlyUtility.h"
extern void handleException();
CapturedXML::CapturedXML() {
}
CapturedXML::~CapturedXML() {
}
const char* CapturedXML::getXML() {
bool perfCounters = false;
int x;
clearXmlString();
xmlHeader();
for (x=0; x<MAX_PERFORMANCE_COUNTERS; x++) {
if (gSessionData.mPerfCounterEnabled[x]) {
perfCounters = true;
break;
}
}
startElement("captured");
attributeInt("version", 1);
attributeInt("protocol", PROTOCOL_VERSION);
if (gSessionData.mBytes > 0) { // Send the following only after the capture is complete
if (time(NULL) > 1267000000) { // If the time is reasonable (after Feb 23, 2010)
attributeUInt("created", time(NULL)); // Valid until the year 2038
}
attributeUInt("bytes", gSessionData.mBytes);
}
startElement("target");
attributeString("name", gSessionData.mCoreName);
attributeInt("sample_rate", gSessionData.mSampleRate);
attributeInt("cores", gSessionData.mCores);
endElement("target");
if (perfCounters) {
startElement("counters");
for (x = 0; x < MAX_PERFORMANCE_COUNTERS; x++) {
if (gSessionData.mPerfCounterEnabled[x]) {
startElement("counter");
attributeString("title", gSessionData.mPerfCounterTitle[x]);
attributeString("name", gSessionData.mPerfCounterName[x]);
attributeHex8("color", gSessionData.mPerfCounterColor[x]);
attributeHex8("key", gSessionData.mPerfCounterKey[x]);
attributeString("type", gSessionData.mPerfCounterType[x]);
attributeHex8("event", gSessionData.mPerfCounterEvent[x]);
if (gSessionData.mPerfCounterPerCPU[x]) {
attributeBool("per_cpu", true);
}
if (strlen(gSessionData.mPerfCounterOperation[x]) > 0) {
attributeString("operation", gSessionData.mPerfCounterOperation[x]);
}
if (gSessionData.mPerfCounterCount[x] > 0) {
attributeInt("count", gSessionData.mPerfCounterCount[x]);
}
attributeString("description", gSessionData.mPerfCounterDescription[x]);
endElement("counter");
}
}
endElement("counters");
}
endElement("captured");
return getXmlString();
}
void CapturedXML::write(char* path) {
char file[PATH_MAX];
// Set full path
snprintf(file, sizeof(file), "%s/captured.xml", path);
// Write the file
const char* xml = getXML();
if (util->writeToDisk(file, xml) < 0) {
logg->logError(__FILE__, __LINE__, "Error writing %s\nPlease verify the path.", file);
handleException();
}
}
|