Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0dc7e544 authored by Yi Jin's avatar Yi Jin Committed by Android (Google) Code Review
Browse files

Merge "Implement Cpu Freq Section"

parents 3fbc4f38 0eb22349
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ cc_library {
            // runtime, as well as the only protos that are actually
            // needed by the device.
            srcs: [
                "core/proto/android/os/cpufreq.proto",
                "core/proto/android/os/cpuinfo.proto",
                "core/proto/android/os/kernelwake.proto",
                "core/proto/android/os/pagetypeinfo.proto",
@@ -83,6 +84,7 @@ gensrcs {
    ],

    srcs: [
        "core/proto/android/os/cpufreq.proto",
        "core/proto/android/os/cpuinfo.proto",
        "core/proto/android/os/kernelwake.proto",
        "core/proto/android/os/pagetypeinfo.proto",
+3 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#define LOG_TAG "incident_helper"

#include "parsers/CpuFreqParser.h"
#include "parsers/CpuInfoParser.h"
#include "parsers/KernelWakesParser.h"
#include "parsers/PageTypeInfoParser.h"
@@ -60,6 +61,8 @@ static TextParserBase* selectParser(int section) {
            return new KernelWakesParser();
        case 2003:
            return new CpuInfoParser();
        case 2004:
            return new CpuFreqParser();
        default:
            return NULL;
    }
+90 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#define LOG_TAG "incident_helper"

#include <android/util/ProtoOutputStream.h>
#include <unistd.h>

#include "frameworks/base/core/proto/android/os/cpufreq.proto.h"
#include "ih_util.h"
#include "CpuFreqParser.h"

using namespace android::os;

status_t
CpuFreqParser::Parse(const int in, const int out) const
{
    Reader reader(in);
    string line;

    // parse header
    reader.readLine(&line);
    header_t header = parseHeader(line, TAB_DELIMITER);
    if (header.size() < 1) {
        fprintf(stderr, "Bad header: %s\n", line.c_str());
        return BAD_VALUE;
    }
    const int numCpus = (int)header.size() - 1;
    vector<pair<int, long long>> cpucores[numCpus];

    // parse freq and time
    while (reader.readLine(&line)) {
        if (line.empty()) continue;

        record_t record = parseRecord(line, TAB_DELIMITER);
        if (record.size() != header.size()) {
            fprintf(stderr, "Bad line: %s\n", line.c_str());
            continue;
        }

        int freq = toInt(record[0]);
        for (int i=0; i<numCpus; i++) {
            if (strcmp(record[i+1].c_str(), "N/A") == 0) {
                continue;
            }
            cpucores[i].push_back(make_pair(freq, toLongLong(record[i+1])));
        }
    }

    ProtoOutputStream proto;

    long jiffyHz = sysconf(_SC_CLK_TCK);
    proto.write(CpuFreq::JIFFY_HZ, (int)jiffyHz);

    for (int i=0; i<numCpus; i++) {
        long long token = proto.start(CpuFreq::CPU_FREQS);
        proto.write(CpuFreqStats::CPU_NAME, header[i+1]);
        for (vector<pair<int, long long>>::iterator it = cpucores[i].begin(); it != cpucores[i].end(); it++) {
            long long stateToken = proto.start(CpuFreqStats::TIMES);
            proto.write(CpuFreqStats::TimeInState::STATE_KHZ, it->first);
            proto.write(CpuFreqStats::TimeInState::TIME_JIFFY, it->second);
            proto.end(stateToken);
        }
        proto.end(token);
    }

    if (!reader.ok(&line)) {
        fprintf(stderr, "Bad read from fd %d: %s\n", in, line.c_str());
        return -1;
    }

    if (!proto.flush(out)) {
        fprintf(stderr, "[%s]Error writing proto back\n", this->name.string());
        return -1;
    }
    fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.string(), proto.size());
    return NO_ERROR;
}
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef CPU_FREQ_PARSER_H
#define CPU_FREQ_PARSER_H

#include "TextParserBase.h"

using namespace android;

/**
 * Cpu frequency parser, parses text in /sys/devices/system/cpu/cpufreq/all_time_in_state
 */
class CpuFreqParser : public TextParserBase {
public:
    CpuFreqParser() : TextParserBase(String8("CpuFreqParser")) {};
    ~CpuFreqParser() {};

    virtual status_t Parse(const int in, const int out) const;
};

#endif  // CPU_FREQ_PARSER_H
+6 −0
Original line number Diff line number Diff line
freq		cpu0		cpu1		cpu2		cpu3		
307200		23860761		23860761		23890935		23890935		
384000		83124		83124		29383		29383		
748800		N/A		N/A		10547		10547		
768000		22652		22652		N/A		N/A		
825600		N/A		N/A		13173		13173			
Loading