2 * Copyright (C) ARM Limited 2010-2013. 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.
10 #include "SessionData.h"
11 #include "SessionXML.h"
14 SessionData* gSessionData = NULL;
16 SessionData::SessionData() {
20 SessionData::~SessionData() {
23 void SessionData::initialize() {
24 mWaitingOnCommand = false;
25 mSessionIsActive = false;
26 mLocalCapture = false;
29 mConfigurationXMLPath = NULL;
30 mSessionXMLPath = NULL;
31 mEventsXMLPath = NULL;
39 // sysconf(_SC_NPROCESSORS_CONF) is unreliable on 2.6 Android, get the value from the kernel module
43 void SessionData::parseSessionXML(char* xmlString) {
44 SessionXML session(xmlString);
47 // Set session data values
48 if (strcmp(session.parameters.sample_rate, "high") == 0) {
50 } else if (strcmp(session.parameters.sample_rate, "normal") == 0) {
52 } else if (strcmp(session.parameters.sample_rate, "low") == 0) {
54 } else if (strcmp(session.parameters.sample_rate, "none") == 0) {
57 logg->logError(__FILE__, __LINE__, "Invalid sample rate (%s) in session xml.", session.parameters.sample_rate);
60 mBacktraceDepth = session.parameters.call_stack_unwinding == true ? 128 : 0;
61 mDuration = session.parameters.duration;
63 // Determine buffer size (in MB) based on buffer mode
65 if (strcmp(session.parameters.buffer_mode, "streaming") == 0) {
68 } else if (strcmp(session.parameters.buffer_mode, "small") == 0) {
70 } else if (strcmp(session.parameters.buffer_mode, "normal") == 0) {
72 } else if (strcmp(session.parameters.buffer_mode, "large") == 0) {
73 mTotalBufferSize = 16;
75 logg->logError(__FILE__, __LINE__, "Invalid value for buffer mode in session xml.");
79 mImages = session.parameters.images;
80 // Convert milli- to nanoseconds
81 mLiveRate = session.parameters.live_rate * (int64_t)1000000;
82 if (mLiveRate > 0 && mLocalCapture) {
83 logg->logMessage("Local capture is not compatable with live, disabling live");
88 void SessionData::readCpuInfo() {
89 char temp[256]; // arbitrarily large amount
90 strcpy(mCoreName, "unknown");
93 FILE* f = fopen("/proc/cpuinfo", "r");
95 logg->logMessage("Error opening /proc/cpuinfo\n"
96 "The core name in the captured xml file will be 'unknown'.");
100 bool foundCoreName = false;
101 bool foundCpuId = false;
102 while (fgets(temp, sizeof(temp), f) && (!foundCoreName || !foundCpuId)) {
103 if (strlen(temp) > 0) {
104 temp[strlen(temp) - 1] = 0; // Replace the line feed with a null
107 const bool foundHardware = strstr(temp, "Hardware") != 0;
108 const bool foundCPUPart = strstr(temp, "CPU part") != 0;
109 if (foundHardware || foundCPUPart) {
110 char* position = strchr(temp, ':');
111 if (position == NULL || (unsigned int)(position - temp) + 2 >= strlen(temp)) {
112 logg->logMessage("Unknown format of /proc/cpuinfo\n"
113 "The core name in the captured xml file will be 'unknown'.");
119 strncpy(mCoreName, position, sizeof(mCoreName));
120 mCoreName[sizeof(mCoreName) - 1] = 0; // strncpy does not guarantee a null-terminated string
121 foundCoreName = true;
125 int cpuId = strtol(position, NULL, 16);
126 if (cpuId > mCpuId) {
134 if (!foundCoreName) {
135 logg->logMessage("Could not determine core name from /proc/cpuinfo\n"
136 "The core name in the captured xml file will be 'unknown'.");
142 // Start one after the gator.ko's value of 1