2 * Copyright (C) ARM Limited 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 "FtraceDriver.h"
15 class FtraceCounter : public DriverCounter {
17 FtraceCounter(DriverCounter *next, char *name, const char *regex);
20 int read(const char *const line, int64_t *values);
25 // Intentionally unimplemented
26 FtraceCounter(const FtraceCounter &);
27 FtraceCounter &operator=(const FtraceCounter &);
30 FtraceCounter::FtraceCounter(DriverCounter *next, char *name, const char *regex) : DriverCounter(next, name) {
31 int result = regcomp(®, regex, REG_EXTENDED);
34 regerror(result, ®, buf, sizeof(buf));
35 logg->logError(__FILE__, __LINE__, "Invalid regex '%s': %s", regex, buf);
40 FtraceCounter::~FtraceCounter() {
44 int FtraceCounter::read(const char *const line, int64_t *values) {
46 int result = regexec(®, line, 2, match, 0);
52 if (match[1].rm_so < 0) {
53 logg->logError(__FILE__, __LINE__, "Parsing %s failed", getName());
58 int64_t value = strtoll(line + match[1].rm_so, NULL, 0);
60 logg->logError(__FILE__, __LINE__, "Parsing %s failed: %s", getName(), strerror(errno));
70 FtraceDriver::FtraceDriver() : mValues(NULL) {
73 FtraceDriver::~FtraceDriver() {
77 void FtraceDriver::readEvents(mxml_node_t *const xml) {
78 mxml_node_t *node = xml;
81 node = mxmlFindElement(node, xml, "event", NULL, NULL, MXML_DESCEND);
85 const char *counter = mxmlElementGetAttr(node, "counter");
86 if (counter == NULL) {
90 if (strncmp(counter, "ftrace_", 7) != 0) {
94 const char *regex = mxmlElementGetAttr(node, "regex");
96 logg->logError(__FILE__, __LINE__, "The regex counter %s is missing the required regex attribute", counter);
99 setCounters(new FtraceCounter(getCounters(), strdup(counter), regex));
103 mValues = new int64_t[2*count];
106 int FtraceDriver::read(const char *line, int64_t **buf) {
109 for (FtraceCounter *counter = static_cast<FtraceCounter *>(getCounters()); counter != NULL; counter = static_cast<FtraceCounter *>(counter->getNext())) {
110 if (!counter->isEnabled()) {
113 count += counter->read(line, mValues + 2*count);