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