2 * Copyright (C) ARM Limited 2010-2014. All rights reserved.
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.
9 #include "SessionData.h"
13 #include "SessionXML.h"
16 SessionData* gSessionData = NULL;
18 SessionData::SessionData() {
22 SessionData::~SessionData() {
25 void SessionData::initialize() {
26 mWaitingOnCommand = false;
27 mSessionIsActive = false;
28 mLocalCapture = false;
31 mConfigurationXMLPath = NULL;
32 mSessionXMLPath = NULL;
33 mEventsXMLPath = NULL;
41 // sysconf(_SC_NPROCESSORS_CONF) is unreliable on 2.6 Android, get the value from the kernel module
46 void SessionData::parseSessionXML(char* xmlString) {
47 SessionXML session(xmlString);
50 // Set session data values - use prime numbers just below the desired value to reduce the chance of events firing at the same time
51 if (strcmp(session.parameters.sample_rate, "high") == 0) {
52 mSampleRate = 9973; // 10000
53 } else if (strcmp(session.parameters.sample_rate, "normal") == 0) {
54 mSampleRate = 997; // 1000
55 } else if (strcmp(session.parameters.sample_rate, "low") == 0) {
56 mSampleRate = 97; // 100
57 } else if (strcmp(session.parameters.sample_rate, "none") == 0) {
60 logg->logError(__FILE__, __LINE__, "Invalid sample rate (%s) in session xml.", session.parameters.sample_rate);
63 mBacktraceDepth = session.parameters.call_stack_unwinding == true ? 128 : 0;
64 mDuration = session.parameters.duration;
66 // Determine buffer size (in MB) based on buffer mode
68 if (strcmp(session.parameters.buffer_mode, "streaming") == 0) {
71 } else if (strcmp(session.parameters.buffer_mode, "small") == 0) {
73 } else if (strcmp(session.parameters.buffer_mode, "normal") == 0) {
75 } else if (strcmp(session.parameters.buffer_mode, "large") == 0) {
76 mTotalBufferSize = 16;
78 logg->logError(__FILE__, __LINE__, "Invalid value for buffer mode in session xml.");
82 mImages = session.parameters.images;
83 // Convert milli- to nanoseconds
84 mLiveRate = session.parameters.live_rate * (int64_t)1000000;
85 if (mLiveRate > 0 && mLocalCapture) {
86 logg->logMessage("Local capture is not compatable with live, disabling live");
91 void SessionData::readCpuInfo() {
92 char temp[256]; // arbitrarily large amount
93 strcpy(mCoreName, "unknown");
94 memset(&mCpuIds, -1, sizeof(mCpuIds));
97 FILE* f = fopen("/proc/cpuinfo", "r");
99 logg->logMessage("Error opening /proc/cpuinfo\n"
100 "The core name in the captured xml file will be 'unknown'.");
104 bool foundCoreName = false;
106 while (fgets(temp, sizeof(temp), f)) {
107 if (strlen(temp) > 0) {
108 temp[strlen(temp) - 1] = 0; // Replace the line feed with a null
111 const bool foundHardware = strstr(temp, "Hardware") != 0;
112 const bool foundCPUPart = strstr(temp, "CPU part") != 0;
113 const bool foundProcessor = strstr(temp, "processor") != 0;
114 if (foundHardware || foundCPUPart || foundProcessor) {
115 char* position = strchr(temp, ':');
116 if (position == NULL || (unsigned int)(position - temp) + 2 >= strlen(temp)) {
117 logg->logMessage("Unknown format of /proc/cpuinfo\n"
118 "The core name in the captured xml file will be 'unknown'.");
124 strncpy(mCoreName, position, sizeof(mCoreName));
125 mCoreName[sizeof(mCoreName) - 1] = 0; // strncpy does not guarantee a null-terminated string
126 foundCoreName = true;
130 mCpuIds[processor] = strtol(position, NULL, 0);
131 // If this does not have the full topology in /proc/cpuinfo, mCpuIds[0] may not have the 1 CPU part emitted - this guarantees it's in mMaxCpuId
132 if (mCpuIds[processor] > mMaxCpuId) {
133 mMaxCpuId = mCpuIds[processor];
137 if (foundProcessor) {
138 processor = strtol(position, NULL, 0);
143 if (!foundCoreName) {
144 logg->logMessage("Could not determine core name from /proc/cpuinfo\n"
145 "The core name in the captured xml file will be 'unknown'.");
151 // key 0 is reserved as a timestamp
152 // key 1 is reserved as the marker for thread specific counters
153 // Odd keys are assigned by the driver, even keys by the daemon