gator: Merge gator version 5.23.1
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / tools / gator / daemon / ConfigurationXML.cpp
index 6590dd3..eda487b 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Copyright (C) ARM Limited 2010-2014. All rights reserved.
+ * Copyright (C) ARM Limited 2010-2015. 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
 #include "OlyUtility.h"
 #include "SessionData.h"
 
-static const char* ATTR_COUNTER            = "counter";
-static const char* ATTR_REVISION           = "revision";
-static const char* ATTR_EVENT              = "event";
-static const char* ATTR_COUNT              = "count";
-static const char* ATTR_CORES              = "cores";
+static const char ATTR_COUNTER[]            = "counter";
+static const char ATTR_REVISION[]           = "revision";
+static const char ATTR_EVENT[]              = "event";
+static const char ATTR_COUNT[]              = "count";
+static const char ATTR_CORES[]              = "cores";
 
 ConfigurationXML::ConfigurationXML() {
+       if (gSessionData.mCountersError != NULL) {
+               free(gSessionData.mCountersError);
+               gSessionData.mCountersError = NULL;
+       }
+
        const char * configuration_xml;
        unsigned int configuration_xml_len;
        getDefaultConfigurationXml(configuration_xml, configuration_xml_len);
@@ -31,11 +36,11 @@ ConfigurationXML::ConfigurationXML() {
        char path[PATH_MAX];
 
        getPath(path);
-       mConfigurationXML = util->readFromDisk(path);
+       mConfigurationXML = readFromDisk(path);
 
        for (int retryCount = 0; retryCount < 2; ++retryCount) {
                if (mConfigurationXML == NULL) {
-                       logg->logMessage("Unable to locate configuration.xml, using default in binary");
+                       logg.logMessage("Unable to locate configuration.xml, using default in binary");
                        // null-terminate configuration_xml
                        mConfigurationXML = (char*)malloc(configuration_xml_len + 1);
                        memcpy(mConfigurationXML, (const void*)configuration_xml, configuration_xml_len);
@@ -68,14 +73,12 @@ int ConfigurationXML::parse(const char* configurationXML) {
        mxml_node_t *tree, *node;
        int ret;
 
-       // clear counter overflow
-       gSessionData->mCounterOverflow = 0;
-       gSessionData->mIsEBS = false;
+       gSessionData.mIsEBS = false;
        mIndex = 0;
 
        // disable all counters prior to parsing the configuration xml
        for (int i = 0; i < MAX_PERFORMANCE_COUNTERS; i++) {
-               gSessionData->mCounters[i].setEnabled(false);
+               gSessionData.mCounters[i].setEnabled(false);
        }
 
        tree = mxmlLoadString(NULL, configurationXML, MXML_NO_CALLBACK);
@@ -98,26 +101,40 @@ int ConfigurationXML::parse(const char* configurationXML) {
 
        mxmlDelete(tree);
 
+       if (gSessionData.mCountersError == NULL && mIndex > MAX_PERFORMANCE_COUNTERS) {
+               if (asprintf(&gSessionData.mCountersError, "Only %i performance counters are permitted, %i are selected", MAX_PERFORMANCE_COUNTERS, mIndex) <= 0) {
+                       logg.logError("asprintf failed");
+                       handleException();
+               }
+       }
+       gSessionData.mCcnDriver.validateCounters();
+
        return ret;
 }
 
 void ConfigurationXML::validate(void) {
        for (int i = 0; i < MAX_PERFORMANCE_COUNTERS; i++) {
-               const Counter & counter = gSessionData->mCounters[i];
+               const Counter & counter = gSessionData.mCounters[i];
                if (counter.isEnabled()) {
                        if (strcmp(counter.getType(), "") == 0) {
-                               logg->logError(__FILE__, __LINE__, "Invalid required attribute in configuration.xml:\n  counter=\"%s\"\n  event=%d\n", counter.getType(), counter.getEvent());
-                               handleException();
+                               if (gSessionData.mCountersError == NULL && asprintf(&gSessionData.mCountersError, "Invalid required attribute in configuration.xml:\n  counter=\"%s\"\n  event=%d", counter.getType(), counter.getEvent()) <= 0) {
+                                       logg.logError("asprintf failed");
+                                       handleException();
+                               }
+                               return;
                        }
 
                        // iterate through the remaining enabled performance counters
                        for (int j = i + 1; j < MAX_PERFORMANCE_COUNTERS; j++) {
-                               const Counter & counter2 = gSessionData->mCounters[j];
+                               const Counter & counter2 = gSessionData.mCounters[j];
                                if (counter2.isEnabled()) {
                                        // check if the types are the same
                                        if (strcmp(counter.getType(), counter2.getType()) == 0) {
-                                               logg->logError(__FILE__, __LINE__, "Duplicate performance counter type in configuration.xml: %s", counter.getType());
-                                               handleException();
+                                               if (gSessionData.mCountersError == NULL && asprintf(&gSessionData.mCountersError, "Duplicate performance counter type in configuration.xml: %s", counter.getType()) <= 0) {
+                                                       logg.logError("asprintf failed");
+                                                       handleException();
+                                               }
+                                               return;
                                        }
                                }
                        }
@@ -149,19 +166,18 @@ void ConfigurationXML::configurationTag(mxml_node_t *node) {
        // handle all other performance counters
        if (mIndex >= MAX_PERFORMANCE_COUNTERS) {
                mIndex++;
-               gSessionData->mCounterOverflow = mIndex;
                return;
        }
 
        // read attributes
-       Counter & counter = gSessionData->mCounters[mIndex];
+       Counter & counter = gSessionData.mCounters[mIndex];
        counter.clear();
        if (mxmlElementGetAttr(node, ATTR_COUNTER)) counter.setType(mxmlElementGetAttr(node, ATTR_COUNTER));
        if (mxmlElementGetAttr(node, ATTR_EVENT)) counter.setEvent(strtol(mxmlElementGetAttr(node, ATTR_EVENT), NULL, 16));
        if (mxmlElementGetAttr(node, ATTR_COUNT)) counter.setCount(strtol(mxmlElementGetAttr(node, ATTR_COUNT), NULL, 10));
        if (mxmlElementGetAttr(node, ATTR_CORES)) counter.setCores(strtol(mxmlElementGetAttr(node, ATTR_CORES), NULL, 10));
        if (counter.getCount() > 0) {
-               gSessionData->mIsEBS = true;
+               gSessionData.mIsEBS = true;
        }
        counter.setEnabled(true);
 
@@ -169,7 +185,7 @@ void ConfigurationXML::configurationTag(mxml_node_t *node) {
        for (Driver *driver = Driver::getHead(); driver != NULL; driver = driver->getNext()) {
                if (driver->claimCounter(counter)) {
                        if (counter.getDriver() != NULL) {
-                               logg->logError(__FILE__, __LINE__, "More than one driver has claimed %s:%i", counter.getType(), counter.getEvent());
+                               logg.logError("More than one driver has claimed %s:%i", counter.getType(), counter.getEvent());
                                handleException();
                        }
                        counter.setDriver(driver);
@@ -178,7 +194,7 @@ void ConfigurationXML::configurationTag(mxml_node_t *node) {
 
        // If no driver is associated with the counter, disable it
        if (counter.getDriver() == NULL) {
-               logg->logMessage("No driver has claimed %s:%i", counter.getType(), counter.getEvent());
+               logg.logMessage("No driver has claimed %s:%i", counter.getType(), counter.getEvent());
                counter.setEnabled(false);
        }
 
@@ -195,11 +211,11 @@ void ConfigurationXML::getDefaultConfigurationXml(const char * & xml, unsigned i
 }
 
 void ConfigurationXML::getPath(char* path) {
-       if (gSessionData->mConfigurationXMLPath) {
-               strncpy(path, gSessionData->mConfigurationXMLPath, PATH_MAX);
+       if (gSessionData.mConfigurationXMLPath) {
+               strncpy(path, gSessionData.mConfigurationXMLPath, PATH_MAX);
        } else {
-               if (util->getApplicationFullPath(path, PATH_MAX) != 0) {
-                       logg->logMessage("Unable to determine the full path of gatord, the cwd will be used");
+               if (getApplicationFullPath(path, PATH_MAX) != 0) {
+                       logg.logMessage("Unable to determine the full path of gatord, the cwd will be used");
                }
                strncat(path, "configuration.xml", PATH_MAX - strlen(path) - 1);
        }
@@ -210,8 +226,8 @@ void ConfigurationXML::remove() {
        getPath(path);
 
        if (::remove(path) != 0) {
-               logg->logError(__FILE__, __LINE__, "Invalid configuration.xml file detected and unable to delete it. To resolve, delete configuration.xml on disk");
+               logg.logError("Invalid configuration.xml file detected and unable to delete it. To resolve, delete configuration.xml on disk");
                handleException();
        }
-       logg->logMessage("Invalid configuration.xml file detected and removed");
+       logg.logMessage("Invalid configuration.xml file detected and removed");
 }