Loading Android.bp +9 −1 Original line number Diff line number Diff line Loading @@ -730,10 +730,18 @@ gensrcs { "core/proto/android/os/procrank.proto", "core/proto/android/os/ps.proto", "core/proto/android/os/system_properties.proto", "core/proto/android/util/event_log_tags.proto", ], // Append protoc-gen-cppstream tool's PATH otherwise aprotoc can't find the plugin tool cmd: "PATH=$$PATH:$$(dirname $(location protoc-gen-cppstream)) $(location aprotoc) --plugin=protoc-gen-cpp-stream=$(location protoc-gen-cppstream) --dependency_out=$(depfile) --cppstream_out=$(genDir)/ -Iexternal/protobuf/src -I . $(in)", cmd: "mkdir -p $(genDir) " + "&& $(location aprotoc) " + " --plugin=$(location protoc-gen-cppstream) " + " --dependency_out=$(depfile) " + " --cppstream_out=$(genDir) " + " -Iexternal/protobuf/src " + " -I . " + " $(in)", output_extension = "proto.h", } Loading cmds/incident_helper/src/ih_util.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -208,6 +208,19 @@ bool stripSuffix(std::string* line, const char* key, bool endAtDelimiter) { return true; } std::string behead(std::string* line, const char cut) { auto found = line->find_first_of(cut); if (found == std::string::npos) { std::string head = line->substr(0); line->assign(""); return head; } std::string head = line->substr(0, found); while(line->at(found) == cut) found++; // trim more cut of the rest line->assign(line->substr(found)); return head; } int toInt(const std::string& s) { return atoi(s.c_str()); } Loading cmds/incident_helper/src/ih_util.h +7 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,8 @@ const std::string DEFAULT_WHITESPACE = " \t"; const std::string DEFAULT_NEWLINE = "\r\n"; const std::string TAB_DELIMITER = "\t"; const std::string COMMA_DELIMITER = ","; const std::string PIPE_DELIMITER = "|"; const std::string PARENTHESES_DELIMITER = "()"; // returns true if c is a-zA-Z0-9 or underscore bool isValidChar(char c); Loading Loading @@ -88,6 +90,11 @@ void printRecord(const record_t& record); bool stripPrefix(std::string* line, const char* key, bool endAtDelimiter = false); bool stripSuffix(std::string* line, const char* key, bool endAtDelimiter = false); /** * behead the given line by the cut, return the head and reassign the line to be the rest. */ std::string behead(std::string* line, const char cut); /** * Converts string to the desired type */ Loading cmds/incident_helper/src/main.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include "parsers/BatteryTypeParser.h" #include "parsers/CpuFreqParser.h" #include "parsers/CpuInfoParser.h" #include "parsers/EventLogTagsParser.h" #include "parsers/KernelWakesParser.h" #include "parsers/PageTypeInfoParser.h" #include "parsers/ProcrankParser.h" Loading Loading @@ -55,6 +56,8 @@ static TextParserBase* selectParser(int section) { // IDs larger than 1 are section ids reserved in incident.proto case 1000: return new SystemPropertiesParser(); case 1100: return new EventLogTagsParser(); case 2000: return new ProcrankParser(); case 2001: Loading cmds/incident_helper/src/parsers/EventLogTagsParser.cpp 0 → 100644 +84 −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 "frameworks/base/core/proto/android/util/event_log_tags.proto.h" #include "ih_util.h" #include "EventLogTagsParser.h" status_t EventLogTagsParser::Parse(const int in, const int out) const { Reader reader(in); string line; ProtoOutputStream proto; // parse line by line while (reader.readLine(&line)) { if (line.empty()) continue; string debug = line; string tagNumber = behead(&line, ' '); string tagName = behead(&line, ' '); if (tagNumber == "" || tagName == "") { fprintf(stderr, "Bad line, expect at least two parts: %s[%s, %s]\n", debug.c_str(), tagNumber.c_str(), tagName.c_str()); continue; } long long token = proto.start(EventLogTagMapProto::EVENT_LOG_TAGS); proto.write(EventLogTag::TAG_NUMBER, toInt(tagNumber)); proto.write(EventLogTag::TAG_NAME, tagName); record_t valueDescriptors = parseRecord(line, PARENTHESES_DELIMITER); for (size_t i = 0; i < valueDescriptors.size(); i++) { record_t valueDescriptor = parseRecord(valueDescriptors[i], PIPE_DELIMITER); if (valueDescriptor.size() != 2 && valueDescriptor.size() != 3) { // If the parts doesn't contains pipe, then skips it. continue; } long long descriptorToken = proto.start(EventLogTag::VALUE_DESCRIPTORS); proto.write(EventLogTag::ValueDescriptor::NAME, valueDescriptor[0]); proto.write(EventLogTag::ValueDescriptor::TYPE, toInt(valueDescriptor[1])); if (valueDescriptor.size() == 3) { char c = valueDescriptor[2][0]; int unit = 0; if (c < '0' || c > '9') { unit = (int) c; } else { unit = toInt(valueDescriptor[2]); } proto.write(EventLogTag::ValueDescriptor::UNIT, unit); } proto.end(descriptorToken); } 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; } Loading
Android.bp +9 −1 Original line number Diff line number Diff line Loading @@ -730,10 +730,18 @@ gensrcs { "core/proto/android/os/procrank.proto", "core/proto/android/os/ps.proto", "core/proto/android/os/system_properties.proto", "core/proto/android/util/event_log_tags.proto", ], // Append protoc-gen-cppstream tool's PATH otherwise aprotoc can't find the plugin tool cmd: "PATH=$$PATH:$$(dirname $(location protoc-gen-cppstream)) $(location aprotoc) --plugin=protoc-gen-cpp-stream=$(location protoc-gen-cppstream) --dependency_out=$(depfile) --cppstream_out=$(genDir)/ -Iexternal/protobuf/src -I . $(in)", cmd: "mkdir -p $(genDir) " + "&& $(location aprotoc) " + " --plugin=$(location protoc-gen-cppstream) " + " --dependency_out=$(depfile) " + " --cppstream_out=$(genDir) " + " -Iexternal/protobuf/src " + " -I . " + " $(in)", output_extension = "proto.h", } Loading
cmds/incident_helper/src/ih_util.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -208,6 +208,19 @@ bool stripSuffix(std::string* line, const char* key, bool endAtDelimiter) { return true; } std::string behead(std::string* line, const char cut) { auto found = line->find_first_of(cut); if (found == std::string::npos) { std::string head = line->substr(0); line->assign(""); return head; } std::string head = line->substr(0, found); while(line->at(found) == cut) found++; // trim more cut of the rest line->assign(line->substr(found)); return head; } int toInt(const std::string& s) { return atoi(s.c_str()); } Loading
cmds/incident_helper/src/ih_util.h +7 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,8 @@ const std::string DEFAULT_WHITESPACE = " \t"; const std::string DEFAULT_NEWLINE = "\r\n"; const std::string TAB_DELIMITER = "\t"; const std::string COMMA_DELIMITER = ","; const std::string PIPE_DELIMITER = "|"; const std::string PARENTHESES_DELIMITER = "()"; // returns true if c is a-zA-Z0-9 or underscore bool isValidChar(char c); Loading Loading @@ -88,6 +90,11 @@ void printRecord(const record_t& record); bool stripPrefix(std::string* line, const char* key, bool endAtDelimiter = false); bool stripSuffix(std::string* line, const char* key, bool endAtDelimiter = false); /** * behead the given line by the cut, return the head and reassign the line to be the rest. */ std::string behead(std::string* line, const char cut); /** * Converts string to the desired type */ Loading
cmds/incident_helper/src/main.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include "parsers/BatteryTypeParser.h" #include "parsers/CpuFreqParser.h" #include "parsers/CpuInfoParser.h" #include "parsers/EventLogTagsParser.h" #include "parsers/KernelWakesParser.h" #include "parsers/PageTypeInfoParser.h" #include "parsers/ProcrankParser.h" Loading Loading @@ -55,6 +56,8 @@ static TextParserBase* selectParser(int section) { // IDs larger than 1 are section ids reserved in incident.proto case 1000: return new SystemPropertiesParser(); case 1100: return new EventLogTagsParser(); case 2000: return new ProcrankParser(); case 2001: Loading
cmds/incident_helper/src/parsers/EventLogTagsParser.cpp 0 → 100644 +84 −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 "frameworks/base/core/proto/android/util/event_log_tags.proto.h" #include "ih_util.h" #include "EventLogTagsParser.h" status_t EventLogTagsParser::Parse(const int in, const int out) const { Reader reader(in); string line; ProtoOutputStream proto; // parse line by line while (reader.readLine(&line)) { if (line.empty()) continue; string debug = line; string tagNumber = behead(&line, ' '); string tagName = behead(&line, ' '); if (tagNumber == "" || tagName == "") { fprintf(stderr, "Bad line, expect at least two parts: %s[%s, %s]\n", debug.c_str(), tagNumber.c_str(), tagName.c_str()); continue; } long long token = proto.start(EventLogTagMapProto::EVENT_LOG_TAGS); proto.write(EventLogTag::TAG_NUMBER, toInt(tagNumber)); proto.write(EventLogTag::TAG_NAME, tagName); record_t valueDescriptors = parseRecord(line, PARENTHESES_DELIMITER); for (size_t i = 0; i < valueDescriptors.size(); i++) { record_t valueDescriptor = parseRecord(valueDescriptors[i], PIPE_DELIMITER); if (valueDescriptor.size() != 2 && valueDescriptor.size() != 3) { // If the parts doesn't contains pipe, then skips it. continue; } long long descriptorToken = proto.start(EventLogTag::VALUE_DESCRIPTORS); proto.write(EventLogTag::ValueDescriptor::NAME, valueDescriptor[0]); proto.write(EventLogTag::ValueDescriptor::TYPE, toInt(valueDescriptor[1])); if (valueDescriptor.size() == 3) { char c = valueDescriptor[2][0]; int unit = 0; if (c < '0' || c > '9') { unit = (int) c; } else { unit = toInt(valueDescriptor[2]); } proto.write(EventLogTag::ValueDescriptor::UNIT, unit); } proto.end(descriptorToken); } 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; }