1 /**
2 * Copyright (C) ARM Limited 2010-2012. 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 <string.h>
10 #include "SessionData.h"
11 #include "SessionXML.h"
12 #include "Logging.h"
13 extern void handleException();
15 SessionData* gSessionData = NULL;
17 SessionData::SessionData() {
18 initialize();
19 }
21 SessionData::~SessionData() {
22 }
24 void SessionData::initialize() {
25 mWaitingOnCommand = false;
26 mSessionIsActive = false;
27 mLocalCapture = false;
28 mOneShot = false;
29 strcpy(mCoreName, "unknown");
30 configurationXMLPath = NULL;
31 apcDir = NULL;
32 mSampleRate = 0;
33 mDuration = 0;
34 mBytes = 0;
35 mBacktraceDepth = 0;
36 mTotalBufferSize = 0;
37 mCores = 1;
39 initializeCounters();
40 }
42 void SessionData::initializeCounters() {
43 // PMU Counters
44 for (int i = 0; i < MAX_PERFORMANCE_COUNTERS; i++) {
45 mPerfCounterType[i][0] = 0;
46 mPerfCounterTitle[i][0] = 0;
47 mPerfCounterName[i][0] = 0;
48 mPerfCounterDescription[i][0] = 0;
49 mPerfCounterEnabled[i] = 0;
50 mPerfCounterEvent[i] = 0;
51 mPerfCounterColor[i] = 0;
52 mPerfCounterKey[i] = 0;
53 mPerfCounterCount[i] = 0;
54 mPerfCounterOperation[i][0] = 0;
55 mPerfCounterPerCPU[i] = false;
56 mPerfCounterEBSCapable[i] = false;
57 }
58 }
60 void SessionData::parseSessionXML(char* xmlString) {
61 SessionXML session(xmlString);
62 session.parse();
64 // Parameter error checking
65 if (session.parameters.output_path == 0 && session.parameters.target_path == 0) {
66 logg->logError(__FILE__, __LINE__, "No capture path (target or host) was provided.");
67 handleException();
68 } else if (gSessionData->mLocalCapture && session.parameters.target_path == 0) {
69 logg->logError(__FILE__, __LINE__, "Missing target_path tag in session xml required for a local capture.");
70 handleException();
71 }
73 // Set session data values
74 if (strcmp(session.parameters.sample_rate, "high") == 0) {
75 gSessionData->mSampleRate = 10000;
76 } else if (strcmp(session.parameters.sample_rate, "normal") == 0) {
77 gSessionData->mSampleRate = 1000;
78 } else { // "low"
79 gSessionData->mSampleRate = 100;
80 }
81 gSessionData->mBacktraceDepth = session.parameters.call_stack_unwinding == true ? 128 : 0;
82 gSessionData->mDuration = session.parameters.duration;
84 // Determine buffer size (in MB) based on buffer mode
85 gSessionData->mOneShot = true;
86 if (strcmp(session.parameters.buffer_mode, "streaming") == 0) {
87 gSessionData->mOneShot = false;
88 gSessionData->mTotalBufferSize = 1;
89 } else if (strcmp(session.parameters.buffer_mode, "small") == 0) {
90 gSessionData->mTotalBufferSize = 1;
91 } else if (strcmp(session.parameters.buffer_mode, "normal") == 0) {
92 gSessionData->mTotalBufferSize = 4;
93 } else if (strcmp(session.parameters.buffer_mode, "large") == 0) {
94 gSessionData->mTotalBufferSize = 16;
95 } else {
96 logg->logError(__FILE__, __LINE__, "Invalid value for buffer mode in session xml.");
97 handleException();
98 }
100 gSessionData->images = session.parameters.images;
101 gSessionData->target_path = session.parameters.target_path;
102 gSessionData->title = session.parameters.title;
103 }