148f512ceSopenharmony_ci/* 248f512ceSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 348f512ceSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 448f512ceSopenharmony_ci * you may not use this file except in compliance with the License. 548f512ceSopenharmony_ci * You may obtain a copy of the License at 648f512ceSopenharmony_ci * 748f512ceSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 848f512ceSopenharmony_ci * 948f512ceSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1048f512ceSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1148f512ceSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1248f512ceSopenharmony_ci * See the License for the specific language governing permissions and 1348f512ceSopenharmony_ci * limitations under the License. 1448f512ceSopenharmony_ci */ 1548f512ceSopenharmony_ci#define HILOG_TAG "Protobuf" 1648f512ceSopenharmony_ci 1748f512ceSopenharmony_ci#include "report_protobuf_file.h" 1848f512ceSopenharmony_ci#include "utilities.h" 1948f512ceSopenharmony_ci 2048f512ceSopenharmony_ciusing namespace Proto; 2148f512ceSopenharmony_cinamespace OHOS { 2248f512ceSopenharmony_cinamespace Developtools { 2348f512ceSopenharmony_cinamespace HiPerf { 2448f512ceSopenharmony_ci// output 2548f512ceSopenharmony_ciReportProtobufFileWriter::~ReportProtobufFileWriter() 2648f512ceSopenharmony_ci{ 2748f512ceSopenharmony_ci Close(); 2848f512ceSopenharmony_ci} 2948f512ceSopenharmony_ci 3048f512ceSopenharmony_civoid ReportProtobufFileWriter::BeforeClose() 3148f512ceSopenharmony_ci{ 3248f512ceSopenharmony_ci HiperfRecord record; 3348f512ceSopenharmony_ci SampleStatistic *message = record.mutable_statistic(); 3448f512ceSopenharmony_ci 3548f512ceSopenharmony_ci message->set_count(recordCount_); 3648f512ceSopenharmony_ci message->set_lost(recordLost_); 3748f512ceSopenharmony_ci protpbufCodedOutputStream_->WriteLittleEndian32(record.ByteSizeLong()); 3848f512ceSopenharmony_ci record.SerializeToCodedStream(protpbufCodedOutputStream_.get()); 3948f512ceSopenharmony_ci} 4048f512ceSopenharmony_ci 4148f512ceSopenharmony_civoid ReportProtobufFileWriter::Close() 4248f512ceSopenharmony_ci{ 4348f512ceSopenharmony_ci if (protobufFileStream_->is_open()) { 4448f512ceSopenharmony_ci BeforeClose(); 4548f512ceSopenharmony_ci // write 0 as end 4648f512ceSopenharmony_ci protpbufCodedOutputStream_->WriteLittleEndian32(0); 4748f512ceSopenharmony_ci protpbufCodedOutputStream_.reset(nullptr); 4848f512ceSopenharmony_ci protpbufOutputStream_.reset(nullptr); 4948f512ceSopenharmony_ci protobufFileStream_->close(); 5048f512ceSopenharmony_ci } 5148f512ceSopenharmony_ci} 5248f512ceSopenharmony_ci 5348f512ceSopenharmony_cibool ReportProtobufFileWriter::Write(const void *buffer, int size) 5448f512ceSopenharmony_ci{ 5548f512ceSopenharmony_ci if (protobufFileStream_->is_open()) { 5648f512ceSopenharmony_ci try { 5748f512ceSopenharmony_ci protobufFileStream_->write(static_cast<const char *>(buffer), size); 5848f512ceSopenharmony_ci HLOGM("writed %d bytes", size); 5948f512ceSopenharmony_ci return true; 6048f512ceSopenharmony_ci } catch (std::ofstream::failure &writeErr) { 6148f512ceSopenharmony_ci HLOGE("write file failed %s", fileName_.c_str()); 6248f512ceSopenharmony_ci } 6348f512ceSopenharmony_ci } else { 6448f512ceSopenharmony_ci printf("no file open for write (request %d bytes).\n", size); 6548f512ceSopenharmony_ci } 6648f512ceSopenharmony_ci return false; 6748f512ceSopenharmony_ci} 6848f512ceSopenharmony_ci 6948f512ceSopenharmony_cibool ReportProtobufFileWriter::Create(std::string fileName) 7048f512ceSopenharmony_ci{ 7148f512ceSopenharmony_ci fileName_ = fileName; 7248f512ceSopenharmony_ci try { 7348f512ceSopenharmony_ci protobufFileStream_->exceptions(std::ofstream::failbit | std::ofstream::badbit | 7448f512ceSopenharmony_ci std::ofstream::eofbit); 7548f512ceSopenharmony_ci std::string resolvedPath = CanonicalizeSpecPath(fileName_.c_str()); 7648f512ceSopenharmony_ci protobufFileStream_->open(resolvedPath.c_str(), 7748f512ceSopenharmony_ci std::fstream::out | std::fstream::trunc | std::fstream::binary); 7848f512ceSopenharmony_ci protpbufOutputStream_ = 7948f512ceSopenharmony_ci std::make_unique<google::protobuf::io::CopyingOutputStreamAdaptor>(this); 8048f512ceSopenharmony_ci protpbufCodedOutputStream_ = 8148f512ceSopenharmony_ci std::make_unique<google::protobuf::io::CodedOutputStream>(protpbufOutputStream_.get()); 8248f512ceSopenharmony_ci 8348f512ceSopenharmony_ci printf("open proto buf file succeed.\n"); 8448f512ceSopenharmony_ci 8548f512ceSopenharmony_ci Write(FILE_MAGIC, sizeof(FILE_MAGIC) - 1); 8648f512ceSopenharmony_ci Write(&FILE_VERSION, sizeof(FILE_VERSION)); 8748f512ceSopenharmony_ci 8848f512ceSopenharmony_ci printf("create proto buf file succeed.\n"); 8948f512ceSopenharmony_ci return true; 9048f512ceSopenharmony_ci } catch (const std::fstream::failure &e) { 9148f512ceSopenharmony_ci printf("open proto buf file faild. %s\n", e.what()); 9248f512ceSopenharmony_ci } 9348f512ceSopenharmony_ci return false; 9448f512ceSopenharmony_ci} 9548f512ceSopenharmony_ci 9648f512ceSopenharmony_cibool ReportProtobufFileWriter::IsOpen() 9748f512ceSopenharmony_ci{ 9848f512ceSopenharmony_ci return protobufFileStream_->is_open(); 9948f512ceSopenharmony_ci} 10048f512ceSopenharmony_ci 10148f512ceSopenharmony_cibool ReportProtobufFileWriter::ProcessRecord(const PerfEventRecord &record) 10248f512ceSopenharmony_ci{ 10348f512ceSopenharmony_ci HLOGM("ProcessRecord %d", record.GetType()); 10448f512ceSopenharmony_ci if (record.GetType() == PERF_RECORD_SAMPLE) { 10548f512ceSopenharmony_ci HLOGF("record.GetType() == PERF_RECORD_SAMPLE"); 10648f512ceSopenharmony_ci } else if (record.GetType() == PERF_RECORD_LOST_SAMPLES) { 10748f512ceSopenharmony_ci ProcessRecord(*static_cast<const PerfRecordLost *>(&record)); 10848f512ceSopenharmony_ci } else if (record.GetType() == PERF_RECORD_COMM) { 10948f512ceSopenharmony_ci ProcessRecord(*static_cast<const PerfRecordComm *>(&record)); 11048f512ceSopenharmony_ci } else { 11148f512ceSopenharmony_ci HLOGM("skip record type %d", record.GetType()); 11248f512ceSopenharmony_ci return false; 11348f512ceSopenharmony_ci } 11448f512ceSopenharmony_ci return true; 11548f512ceSopenharmony_ci} 11648f512ceSopenharmony_ci 11748f512ceSopenharmony_cibool ReportProtobufFileWriter::ProcessSampleRecord( 11848f512ceSopenharmony_ci const PerfRecordSample &recordSample, uint32_t configIndex, 11948f512ceSopenharmony_ci const std::vector<std::unique_ptr<SymbolsFile>> &symbolsFiles) 12048f512ceSopenharmony_ci{ 12148f512ceSopenharmony_ci HiperfRecord record; 12248f512ceSopenharmony_ci CallStackSample *sample = record.mutable_sample(); 12348f512ceSopenharmony_ci sample->set_time(recordSample.data_.time); 12448f512ceSopenharmony_ci sample->set_tid(recordSample.data_.tid); 12548f512ceSopenharmony_ci for (const DfxFrame &frame : recordSample.callFrames_) { 12648f512ceSopenharmony_ci auto callframe = sample->add_callstackframe(); 12748f512ceSopenharmony_ci callframe->set_symbols_vaddr(frame.funcOffset); 12848f512ceSopenharmony_ci callframe->set_loaded_vaddr(frame.pc - frame.mapOffset); 12948f512ceSopenharmony_ci if (frame.symbolFileIndex >= 0) { 13048f512ceSopenharmony_ci callframe->set_symbols_file_id(frame.symbolFileIndex); 13148f512ceSopenharmony_ci callframe->set_function_name_id(frame.index); 13248f512ceSopenharmony_ci } 13348f512ceSopenharmony_ci } 13448f512ceSopenharmony_ci sample->set_event_count(recordSample.data_.period); 13548f512ceSopenharmony_ci sample->set_config_name_id(configIndex); 13648f512ceSopenharmony_ci 13748f512ceSopenharmony_ci protpbufCodedOutputStream_->WriteLittleEndian32(record.ByteSizeLong()); 13848f512ceSopenharmony_ci record.SerializeToCodedStream(protpbufCodedOutputStream_.get()); 13948f512ceSopenharmony_ci recordCount_++; 14048f512ceSopenharmony_ci 14148f512ceSopenharmony_ci return true; 14248f512ceSopenharmony_ci} 14348f512ceSopenharmony_cibool ReportProtobufFileWriter::ProcessReportInfo(const std::vector<std::string> &configNames, 14448f512ceSopenharmony_ci const std::string &workloadCmd) 14548f512ceSopenharmony_ci{ 14648f512ceSopenharmony_ci HiperfRecord record; 14748f512ceSopenharmony_ci ReportInfo *info = record.mutable_info(); 14848f512ceSopenharmony_ci HLOGV("configNames:%zu", configNames.size()); 14948f512ceSopenharmony_ci for (auto configName : configNames) { 15048f512ceSopenharmony_ci info->add_config_name(configName); 15148f512ceSopenharmony_ci } 15248f512ceSopenharmony_ci info->set_workload_cmd(workloadCmd); 15348f512ceSopenharmony_ci 15448f512ceSopenharmony_ci protpbufCodedOutputStream_->WriteLittleEndian32(record.ByteSizeLong()); 15548f512ceSopenharmony_ci record.SerializeToCodedStream(protpbufCodedOutputStream_.get()); 15648f512ceSopenharmony_ci return true; 15748f512ceSopenharmony_ci} 15848f512ceSopenharmony_ci 15948f512ceSopenharmony_cibool ReportProtobufFileWriter::ProcessRecord(const PerfRecordLost &recordLost) 16048f512ceSopenharmony_ci{ 16148f512ceSopenharmony_ci recordLost.DumpLog(__FUNCTION__); 16248f512ceSopenharmony_ci recordLost_ += recordLost.data_.lost; 16348f512ceSopenharmony_ci return true; 16448f512ceSopenharmony_ci} 16548f512ceSopenharmony_ci 16648f512ceSopenharmony_cibool ReportProtobufFileWriter::ProcessRecord(const PerfRecordComm &recordComm) 16748f512ceSopenharmony_ci{ 16848f512ceSopenharmony_ci recordComm.DumpLog(__FUNCTION__); 16948f512ceSopenharmony_ci HiperfRecord record; 17048f512ceSopenharmony_ci VirtualThreadInfo *thread = record.mutable_thread(); 17148f512ceSopenharmony_ci 17248f512ceSopenharmony_ci thread->set_tid(recordComm.data_.tid); 17348f512ceSopenharmony_ci thread->set_pid(recordComm.data_.pid); 17448f512ceSopenharmony_ci thread->set_name(recordComm.data_.comm); 17548f512ceSopenharmony_ci 17648f512ceSopenharmony_ci protpbufCodedOutputStream_->WriteLittleEndian32(record.ByteSizeLong()); 17748f512ceSopenharmony_ci record.SerializeToCodedStream(protpbufCodedOutputStream_.get()); 17848f512ceSopenharmony_ci return true; 17948f512ceSopenharmony_ci} 18048f512ceSopenharmony_ci 18148f512ceSopenharmony_cibool ReportProtobufFileWriter::ProcessSymbolsFiles( 18248f512ceSopenharmony_ci const std::vector<std::unique_ptr<SymbolsFile>> &symbolsFiles) 18348f512ceSopenharmony_ci{ 18448f512ceSopenharmony_ci uint32_t id = 0; 18548f512ceSopenharmony_ci for (auto &symbolsFile : symbolsFiles) { 18648f512ceSopenharmony_ci HiperfRecord record; 18748f512ceSopenharmony_ci SymbolTableFile *message = record.mutable_file(); 18848f512ceSopenharmony_ci 18948f512ceSopenharmony_ci message->set_id(id++); 19048f512ceSopenharmony_ci message->set_path(symbolsFile->filePath_); 19148f512ceSopenharmony_ci 19248f512ceSopenharmony_ci for (auto &symbol : symbolsFile->GetSymbols()) { 19348f512ceSopenharmony_ci message->add_function_name(symbol.GetName().data()); 19448f512ceSopenharmony_ci } 19548f512ceSopenharmony_ci 19648f512ceSopenharmony_ci protpbufCodedOutputStream_->WriteLittleEndian32(record.ByteSizeLong()); 19748f512ceSopenharmony_ci record.SerializeToCodedStream(protpbufCodedOutputStream_.get()); 19848f512ceSopenharmony_ci } 19948f512ceSopenharmony_ci return true; 20048f512ceSopenharmony_ci} 20148f512ceSopenharmony_ci 20248f512ceSopenharmony_ci// input 20348f512ceSopenharmony_ciint ReportProtobufFileReader::Read(void *buffer, int size) 20448f512ceSopenharmony_ci{ 20548f512ceSopenharmony_ci if (protobufFileStream_->is_open()) { 20648f512ceSopenharmony_ci try { 20748f512ceSopenharmony_ci protobufFileStream_->read(static_cast<char *>(buffer), size); 20848f512ceSopenharmony_ci HLOGM("readed %d bytes", size); 20948f512ceSopenharmony_ci return size; 21048f512ceSopenharmony_ci } catch (std::ifstream::failure &readErr) { 21148f512ceSopenharmony_ci if (protobufFileStream_->eof()) { 21248f512ceSopenharmony_ci // this is not a issue 21348f512ceSopenharmony_ci HLOGW("read file %d bytes failed eof. only return %zu\n", size, 21448f512ceSopenharmony_ci protobufFileStream_->gcount()); 21548f512ceSopenharmony_ci 21648f512ceSopenharmony_ci return protobufFileStream_->gcount(); 21748f512ceSopenharmony_ci } 21848f512ceSopenharmony_ci printf("read file %d bytes failed %s : %s\n", size, fileName_.c_str(), readErr.what()); 21948f512ceSopenharmony_ci } 22048f512ceSopenharmony_ci } else { 22148f512ceSopenharmony_ci printf("no file open for read (request %d bytes).\n", size); 22248f512ceSopenharmony_ci } 22348f512ceSopenharmony_ci return 0; 22448f512ceSopenharmony_ci} 22548f512ceSopenharmony_ci 22648f512ceSopenharmony_cibool ReportProtobufFileReader::CheckFileMagic() 22748f512ceSopenharmony_ci{ 22848f512ceSopenharmony_ci char fileMagic[sizeof(FILE_MAGIC)] = {0}; 22948f512ceSopenharmony_ci Read(fileMagic, sizeof(FILE_MAGIC) - 1); 23048f512ceSopenharmony_ci if (memcmp(fileMagic, FILE_MAGIC, sizeof(FILE_MAGIC) - 1) != 0) { 23148f512ceSopenharmony_ci printf("file magic is NOT correct. %s: %x\n", fileMagic, fileMagic[0]); 23248f512ceSopenharmony_ci return false; 23348f512ceSopenharmony_ci } 23448f512ceSopenharmony_ci 23548f512ceSopenharmony_ci uint16_t version = 0; 23648f512ceSopenharmony_ci Read(&version, sizeof(version)); 23748f512ceSopenharmony_ci if (version != FILE_VERSION) { 23848f512ceSopenharmony_ci printf("file version is NOT correct.\n"); 23948f512ceSopenharmony_ci return false; 24048f512ceSopenharmony_ci } 24148f512ceSopenharmony_ci 24248f512ceSopenharmony_ci return true; 24348f512ceSopenharmony_ci} 24448f512ceSopenharmony_ci 24548f512ceSopenharmony_cibool ReportProtobufFileReader::Dump(std::string fileName, ProtobufReadBack readBack) 24648f512ceSopenharmony_ci{ 24748f512ceSopenharmony_ci const int defaultIndent = 0; 24848f512ceSopenharmony_ci fileName_ = fileName; 24948f512ceSopenharmony_ci try { 25048f512ceSopenharmony_ci protobufFileStream_->exceptions(std::ifstream::failbit | std::ifstream::badbit); 25148f512ceSopenharmony_ci std::string resolvedPath = CanonicalizeSpecPath(fileName_.c_str()); 25248f512ceSopenharmony_ci protobufFileStream_->open(resolvedPath.c_str(), std::fstream::in | std::fstream::binary); 25348f512ceSopenharmony_ci printf("open proto buf file succeed.\n"); 25448f512ceSopenharmony_ci if (!CheckFileMagic()) { 25548f512ceSopenharmony_ci return false; 25648f512ceSopenharmony_ci } 25748f512ceSopenharmony_ci protpbufInputStream_ = std::make_unique<google::protobuf::io::CopyingInputStreamAdaptor>(this); 25848f512ceSopenharmony_ci protpbufCodedInputStream_ = 25948f512ceSopenharmony_ci std::make_unique<google::protobuf::io::CodedInputStream>(protpbufInputStream_.get()); 26048f512ceSopenharmony_ci uint32_t recordLength = 0; 26148f512ceSopenharmony_ci do { 26248f512ceSopenharmony_ci protpbufCodedInputStream_->ReadLittleEndian32(&recordLength); 26348f512ceSopenharmony_ci if (recordLength != 0) { 26448f512ceSopenharmony_ci PRINT_INDENT(defaultIndent, "record length:%u (%x)\n", recordLength, recordLength); 26548f512ceSopenharmony_ci HiperfRecord record; 26648f512ceSopenharmony_ci std::string recordBuf; 26748f512ceSopenharmony_ci recordBuf.resize(recordLength); 26848f512ceSopenharmony_ci if (!protpbufCodedInputStream_->ReadString(&recordBuf, recordLength)) { 26948f512ceSopenharmony_ci printf("read record error\n"); 27048f512ceSopenharmony_ci return false; 27148f512ceSopenharmony_ci } 27248f512ceSopenharmony_ci if (!record.ParseFromString(recordBuf)) { 27348f512ceSopenharmony_ci printf("parse format error\n"); 27448f512ceSopenharmony_ci return false; 27548f512ceSopenharmony_ci } else { 27648f512ceSopenharmony_ci if (readBack == nullptr) { 27748f512ceSopenharmony_ci PRINT_INDENT(defaultIndent, "\n"); 27848f512ceSopenharmony_ci Dump(record, defaultIndent); 27948f512ceSopenharmony_ci } else { 28048f512ceSopenharmony_ci readBack(record); 28148f512ceSopenharmony_ci } 28248f512ceSopenharmony_ci } 28348f512ceSopenharmony_ci } else { 28448f512ceSopenharmony_ci if (readBack == nullptr) { 28548f512ceSopenharmony_ci printf("no more record\n"); 28648f512ceSopenharmony_ci } 28748f512ceSopenharmony_ci break; 28848f512ceSopenharmony_ci } 28948f512ceSopenharmony_ci } while (recordLength != 0); 29048f512ceSopenharmony_ci return true; 29148f512ceSopenharmony_ci } catch (const std::fstream::failure &e) { 29248f512ceSopenharmony_ci HLOGE("open proto buf file faild. %s\n", e.what()); 29348f512ceSopenharmony_ci } 29448f512ceSopenharmony_ci return false; 29548f512ceSopenharmony_ci} 29648f512ceSopenharmony_ci 29748f512ceSopenharmony_cibool ReportProtobufFileReader::Dump(const CallStackSample &message, int indent) 29848f512ceSopenharmony_ci{ 29948f512ceSopenharmony_ci PRINT_INDENT(indent, "%s:\n", message.GetTypeName().c_str()); 30048f512ceSopenharmony_ci if (message.has_time()) { 30148f512ceSopenharmony_ci PRINT_INDENT(indent + 1, "time:%" PRId64 "\n", message.time()); 30248f512ceSopenharmony_ci } 30348f512ceSopenharmony_ci if (message.has_tid()) { 30448f512ceSopenharmony_ci PRINT_INDENT(indent + 1, "tid:%u\n", message.tid()); 30548f512ceSopenharmony_ci } 30648f512ceSopenharmony_ci for (int i = 0; i < message.callstackframe_size(); i++) { 30748f512ceSopenharmony_ci PRINT_INDENT(indent + 1, "%d:\n", i); 30848f512ceSopenharmony_ci auto &callframe = message.callstackframe(i); 30948f512ceSopenharmony_ci if (callframe.has_symbols_vaddr()) { 31048f512ceSopenharmony_ci PRINT_INDENT(indent + INDENT_TWO, "symbols_vaddr: 0x%" PRIx64 " \n", 31148f512ceSopenharmony_ci callframe.symbols_vaddr()); 31248f512ceSopenharmony_ci } 31348f512ceSopenharmony_ci if (callframe.has_symbols_file_id()) { 31448f512ceSopenharmony_ci PRINT_INDENT(indent + INDENT_TWO, "symbols_file_id: %u\n", callframe.symbols_file_id()); 31548f512ceSopenharmony_ci } 31648f512ceSopenharmony_ci if (callframe.has_function_name_id()) { 31748f512ceSopenharmony_ci PRINT_INDENT(indent + INDENT_TWO, "function_name_id: %d\n", callframe.function_name_id()); 31848f512ceSopenharmony_ci } 31948f512ceSopenharmony_ci } 32048f512ceSopenharmony_ci if (message.has_event_count()) { 32148f512ceSopenharmony_ci PRINT_INDENT(indent + 1, "event_count:%" PRIu64 "\n", message.event_count()); 32248f512ceSopenharmony_ci } 32348f512ceSopenharmony_ci if (message.has_config_name_id()) { 32448f512ceSopenharmony_ci PRINT_INDENT(indent + 1, "config_name_id:%u\n", message.config_name_id()); 32548f512ceSopenharmony_ci } 32648f512ceSopenharmony_ci return true; 32748f512ceSopenharmony_ci} 32848f512ceSopenharmony_ci 32948f512ceSopenharmony_cibool ReportProtobufFileReader::Dump(const SampleStatistic &message, int indent) 33048f512ceSopenharmony_ci{ 33148f512ceSopenharmony_ci PRINT_INDENT(indent, "%s:\n", message.GetTypeName().c_str()); 33248f512ceSopenharmony_ci if (message.has_count()) { 33348f512ceSopenharmony_ci PRINT_INDENT(indent + 1, "count:%" PRIu64 "\n", message.count()); 33448f512ceSopenharmony_ci } 33548f512ceSopenharmony_ci if (message.has_lost()) { 33648f512ceSopenharmony_ci PRINT_INDENT(indent + 1, "lost:%" PRIu64 "\n", message.lost()); 33748f512ceSopenharmony_ci } 33848f512ceSopenharmony_ci return false; 33948f512ceSopenharmony_ci} 34048f512ceSopenharmony_ci 34148f512ceSopenharmony_cibool ReportProtobufFileReader::Dump(const SymbolTableFile &message, int indent) 34248f512ceSopenharmony_ci{ 34348f512ceSopenharmony_ci PRINT_INDENT(indent, "%s:\n", message.GetTypeName().c_str()); 34448f512ceSopenharmony_ci if (message.has_id()) { 34548f512ceSopenharmony_ci PRINT_INDENT(indent + 1, "id: %u\n", message.id()); 34648f512ceSopenharmony_ci } 34748f512ceSopenharmony_ci if (message.has_path()) { 34848f512ceSopenharmony_ci PRINT_INDENT(indent + 1, "path: %s\n", message.path().c_str()); 34948f512ceSopenharmony_ci } 35048f512ceSopenharmony_ci for (int i = 0; i < message.function_name_size(); i++) { 35148f512ceSopenharmony_ci PRINT_INDENT(indent + INDENT_TWO, "%d:%s\n", i, message.function_name(i).c_str()); 35248f512ceSopenharmony_ci } 35348f512ceSopenharmony_ci return false; 35448f512ceSopenharmony_ci} 35548f512ceSopenharmony_cibool ReportProtobufFileReader::Dump(const VirtualThreadInfo &message, int indent) 35648f512ceSopenharmony_ci{ 35748f512ceSopenharmony_ci PRINT_INDENT(indent, "%s:\n", message.GetTypeName().c_str()); 35848f512ceSopenharmony_ci if (message.has_pid()) { 35948f512ceSopenharmony_ci PRINT_INDENT(indent + 1, "pid:%u\n", message.pid()); 36048f512ceSopenharmony_ci } 36148f512ceSopenharmony_ci if (message.has_tid()) { 36248f512ceSopenharmony_ci PRINT_INDENT(indent + 1, "tid:%u\n", message.tid()); 36348f512ceSopenharmony_ci } 36448f512ceSopenharmony_ci if (message.has_pid()) { 36548f512ceSopenharmony_ci PRINT_INDENT(indent + 1, "name:%s\n", message.name().c_str()); 36648f512ceSopenharmony_ci } 36748f512ceSopenharmony_ci return false; 36848f512ceSopenharmony_ci} 36948f512ceSopenharmony_cibool ReportProtobufFileReader::Dump(const ReportInfo &message, int indent) 37048f512ceSopenharmony_ci{ 37148f512ceSopenharmony_ci PRINT_INDENT(indent, "%s:\n", message.GetTypeName().c_str()); 37248f512ceSopenharmony_ci for (int i = 0; i < message.config_name_size(); i++) { 37348f512ceSopenharmony_ci PRINT_INDENT(indent + 1, "config_name:%d:%s\n", i, message.config_name(i).c_str()); 37448f512ceSopenharmony_ci } 37548f512ceSopenharmony_ci if (message.has_workload_cmd()) { 37648f512ceSopenharmony_ci PRINT_INDENT(indent + 1, "workload:%s\n", message.workload_cmd().c_str()); 37748f512ceSopenharmony_ci } 37848f512ceSopenharmony_ci return true; 37948f512ceSopenharmony_ci} 38048f512ceSopenharmony_cibool ReportProtobufFileReader::Dump(const HiperfRecord &record, int indent) 38148f512ceSopenharmony_ci{ 38248f512ceSopenharmony_ci PRINT_INDENT(indent, "%s:\n", record.GetTypeName().c_str()); 38348f512ceSopenharmony_ci if (record.has_sample()) { 38448f512ceSopenharmony_ci return Dump(record.sample(), indent + 1); 38548f512ceSopenharmony_ci } else if (record.has_statistic()) { 38648f512ceSopenharmony_ci return Dump(record.statistic(), indent + 1); 38748f512ceSopenharmony_ci } else if (record.has_file()) { 38848f512ceSopenharmony_ci return Dump(record.file(), indent + 1); 38948f512ceSopenharmony_ci } else if (record.has_thread()) { 39048f512ceSopenharmony_ci return Dump(record.thread(), indent + 1); 39148f512ceSopenharmony_ci } else if (record.has_info()) { 39248f512ceSopenharmony_ci return Dump(record.info(), indent + 1); 39348f512ceSopenharmony_ci } else { 39448f512ceSopenharmony_ci printf("unknow proto buf format\n"); 39548f512ceSopenharmony_ci return false; 39648f512ceSopenharmony_ci } 39748f512ceSopenharmony_ci} 39848f512ceSopenharmony_cibool ReportProtobufFileReader::IsOpen() 39948f512ceSopenharmony_ci{ 40048f512ceSopenharmony_ci return protobufFileStream_->is_open(); 40148f512ceSopenharmony_ci} 40248f512ceSopenharmony_ci} // namespace HiPerf 40348f512ceSopenharmony_ci} // namespace Developtools 40448f512ceSopenharmony_ci} // namespace OHOS 405