diff --git a/trace_streamer/build.sh b/trace_streamer/build.sh index e00de2bef4923b57d7fb448ee18a52dca02be6c7..c71c3e1fa3a4a44d253933ccdd2ab10f7a6eded4 100755 --- a/trace_streamer/build.sh +++ b/trace_streamer/build.sh @@ -12,12 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. set -e -. build/build_stanalone_plugins.sh -set_enable_plugin_array "true" -set_enable_extend_plugin_array "false" PARAMS=$* SOURCE="${BASH_SOURCE[0]}" cd "$(dirname "${SOURCE}")" +. build/build_stanalone_plugins.sh +set_enable_plugin_array "true" +set_enable_extend_plugin_array "false" ./pare_third_party.sh choose_os_type ./dl_tools.sh $gn_path diff --git a/trace_streamer/src/base/file.cpp b/trace_streamer/src/base/file.cpp index fe4c4ff13d969fe767452f10bbe17e4ec2515c35..10d33d46269afbc2b841a8e1b88bbed3f6c0703a 100644 --- a/trace_streamer/src/base/file.cpp +++ b/trace_streamer/src/base/file.cpp @@ -83,7 +83,7 @@ std::vector GetFilesNameFromDir(const std::string &path) std::filesystem::path dirPath(path); // 检查文件是否存在 if (!std::filesystem::exists(dirPath)) { - std::cout << "!std::filesystem::exists(dirPath)" << std::endl; + TS_LOGI("!std::filesystem::exists(dirPath), dirPath: %s\n", path.data()); return soFiles; } // 遍历目录 diff --git a/trace_streamer/src/base/log.h b/trace_streamer/src/base/log.h index 95eb95e958012a92e0ac4a73e9f8233db039640b..726254b5ebe644b8c8887c3b45ecedc35dd4e562 100644 --- a/trace_streamer/src/base/log.h +++ b/trace_streamer/src/base/log.h @@ -16,9 +16,8 @@ #ifndef INCLUDE_TS_BASE_LOGGING_H_ #define INCLUDE_TS_BASE_LOGGING_H_ -#include -#include #include +#include // namespace SysTuning { // namespace base { diff --git a/trace_streamer/src/base/string_help.cpp b/trace_streamer/src/base/string_help.cpp index 9eb5a2e03f8a8e5783052a83977e824cd7c98235..e3c7877ec58e25511aa70432d596615b4de8c9e2 100644 --- a/trace_streamer/src/base/string_help.cpp +++ b/trace_streamer/src/base/string_help.cpp @@ -104,6 +104,27 @@ std::string Strip(const std::string &str) return str.substr(first, last - first + 1); } +std::string StrTrim(const std::string &input) +{ + std::string str = input; + if (str.empty()) { + return str; + } + str.erase(0, str.find_first_not_of(' ')); + str.erase(str.find_last_not_of(' ') + 1); + return str; +} + +// in-place版本, 直接修改str +void StrTrim(std::string& input) +{ + if (input.empty()) { + return; + } + input.erase(0, input.find_first_not_of(' ')); + input.erase(input.find_last_not_of(' ') + 1); +} + void RemoveNullTerminator(std::string &str) { size_t pos = str.rfind('\0'); diff --git a/trace_streamer/src/base/string_help.h b/trace_streamer/src/base/string_help.h index 4c6f78b727b8688fb42e037c8d4702bbf811ca8e..476f30bee6dcfe7665b66b6dcf15bd9f0d6353f6 100644 --- a/trace_streamer/src/base/string_help.h +++ b/trace_streamer/src/base/string_help.h @@ -28,6 +28,8 @@ bool StartWith(const std::string &str, const std::string &res); bool EndWith(const std::string &str, const std::string &res); std::string FormatString(const char *p); std::string Strip(const std::string &str); +std::string StrTrim(const std::string &input); +void StrTrim(std::string& input); std::string TrimInvisibleCharacters(const std::string &str); void RemoveNullTerminator(std::string &str); } // namespace base diff --git a/trace_streamer/src/filter/process_filter.cpp b/trace_streamer/src/filter/process_filter.cpp index e002ac442c2ebb055290cb145be1a442995e6c78..e05a60f8a9217129a6691cc452bd155b17bbcf05 100644 --- a/trace_streamer/src/filter/process_filter.cpp +++ b/trace_streamer/src/filter/process_filter.cpp @@ -137,12 +137,7 @@ uint32_t ProcessFilter::UpdateOrCreateThreadWithNameIndex(uint64_t timeStamp, ui if (!thread) { return INVALID_ID; } - if (threadNameIndex != thread->nameIndex_) { - thread->nameIndex_ = threadNameIndex; - } - if (timeStamp < thread->startT_) { - thread->startT_ = timeStamp; - } + thread->nameIndex_ = threadNameIndex; return internalTid; } return internalTids.back(); @@ -191,18 +186,6 @@ std::vector &ProcessFilter::GetInternalTids(uint32_t tid) return tmpTids_; } -bool ProcessFilter::IsThreadNameEmpty(uint32_t tid) const -{ - auto internalTid = GetInternalTid(tid); - if (internalTid != INVALID_ID) { - auto thread = traceDataCache_->GetThreadData(internalTid); - if (thread->nameIndex_) { - return false; - } - } - return true; -} - InternalPid ProcessFilter::GetInternalPid(uint32_t pid) const { auto it = pidToInternalPidMap_.find(pid); diff --git a/trace_streamer/src/filter/process_filter.h b/trace_streamer/src/filter/process_filter.h index 4b23612e02234610d94ab22e70903b2cb692d032..1ef82fe96d44032d2e6b29633dd5cc2a6e9b483f 100644 --- a/trace_streamer/src/filter/process_filter.h +++ b/trace_streamer/src/filter/process_filter.h @@ -36,7 +36,6 @@ public: uint32_t UpdateOrCreateThread(uint64_t timeStamp, uint32_t tid); InternalPid GetInternalPid(uint32_t pid) const; InternalPid GetOrCreateInternalPid(uint64_t timeStamp, uint32_t pid); - bool IsThreadNameEmpty(uint32_t tid) const; InternalTid GetInternalTid(uint32_t tid) const; std::vector &GetInternalTids(uint32_t tid); uint32_t UpdateOrCreateThreadWithNameIndex(uint64_t timeStamp, uint32_t tid, DataIndex threadNameIndex); diff --git a/trace_streamer/src/parser/common_types.h b/trace_streamer/src/parser/common_types.h index 2c3b668b563a7a756843cb5de18ebd948c8a11f6..46c0d4f21e1d64cf6761963a731fa6d376bf1bc1 100644 --- a/trace_streamer/src/parser/common_types.h +++ b/trace_streamer/src/parser/common_types.h @@ -35,8 +35,6 @@ struct BytraceLine { uint32_t cpu = 0; std::string task; // thread name - std::string pidStr; // thread str - std::string tGidStr; // process thread_group uint32_t tgid = 0; std::string eventName; std::string argsStr; diff --git a/trace_streamer/src/parser/ptreader_parser/bytrace_parser/bytrace_event_parser.cpp b/trace_streamer/src/parser/ptreader_parser/bytrace_parser/bytrace_event_parser.cpp index a59cd66e625ee6635cbe9bae615d5482946884d8..19285d9424d4a6808f6d68fdfe8c9b2df06b0c5a 100644 --- a/trace_streamer/src/parser/ptreader_parser/bytrace_parser/bytrace_event_parser.cpp +++ b/trace_streamer/src/parser/ptreader_parser/bytrace_parser/bytrace_event_parser.cpp @@ -78,6 +78,7 @@ BytraceEventParser::BytraceEventParser(TraceDataCache *dataCache, const TraceStr RegulatorEventInitialization(); BinderEventInitialization(); StackEventsInitialization(); + eventList_.reserve(maxBuffSize_); } void BytraceEventParser::InterruptEventInitialization() @@ -742,51 +743,57 @@ bool BytraceEventParser::BinderTransactionAllocBufEvent(const ArgsMap &args, con } void BytraceEventParser::ParseDataItem(const BytraceLine &line) { - eventList_.push_back(std::make_unique(line.ts, std::move(line))); - size_t maxBuffSize = 1000 * 1000; + eventList_.emplace_back(std::make_unique(line.ts, line)); size_t maxQueue = 2; - if (eventList_.size() < maxBuffSize * maxQueue) { + if (eventList_.size() < maxBuffSize_ * maxQueue) { return; } auto cmp = [](const std::unique_ptr &a, const std::unique_ptr &b) { return a->eventTimestamp < b->eventTimestamp; }; std::stable_sort(eventList_.begin(), eventList_.end(), cmp); - auto endOfList = eventList_.begin() + maxBuffSize; + auto endOfList = eventList_.begin() + maxBuffSize_; for (auto itor = eventList_.begin(); itor != endOfList; itor++) { EventInfo *event = itor->get(); BeginFilterEvents(event); itor->reset(); } eventList_.erase(eventList_.begin(), endOfList); - return; } -void BytraceEventParser::GetDataSegArgs(BytraceLine &bufLine, ArgsMap &args, uint32_t &tgid) const + +void BytraceEventParser::GetDataSegArgs(const BytraceLine &bufLine, ArgsMap &args) const { - if (bufLine.tGidStr.size() && bufLine.tGidStr.at(0) != '-') { - tgid = base::StrToInt(bufLine.tGidStr).value_or(0); - } else { - tgid = 0; - } - bufLine.tgid = tgid; - - for (base::PartingString ss(bufLine.argsStr, ' '); ss.Next();) { - std::string key; - std::string value; - if (!(std::string(ss.GetCur()).find("=") != std::string::npos)) { - key = "name"; - value = ss.GetCur(); - args.emplace(std::move(key), std::move(value)); - continue; - } - for (base::PartingString inner(ss.GetCur(), '='); inner.Next();) { - if (key.empty()) { - key = inner.GetCur(); + int32_t len = bufLine.argsStr.size(); + int32_t first = -1; + int32_t second = -1; + for (int32_t i = 0; i < len; i++) { + if (bufLine.argsStr[i] == ' ') { + if (first == -1) { + continue; + } + if (second != -1) { + args.emplace(bufLine.argsStr.substr(first, second - 1 - first), + bufLine.argsStr.substr(second, i - second)); + second = -1; } else { - value = inner.GetCur(); + args.emplace("name", bufLine.argsStr.substr(first, i - first)); + } + first = -1; + } else { + if (first == -1) { + first = i; + } + if (bufLine.argsStr[i] == '=') { + second = i + 1; } } - args.emplace(std::move(key), std::move(value)); + } + if (second != -1) { + args.emplace(bufLine.argsStr.substr(first, second - 1 - first), bufLine.argsStr.substr(second, len - second)); + return; + } + if (first != -1) { + args.emplace("name", bufLine.argsStr.substr(first, len - first)); } } @@ -796,9 +803,8 @@ void BytraceEventParser::FilterAllEvents() return a->eventTimestamp < b->eventTimestamp; }; std::stable_sort(eventList_.begin(), eventList_.end(), cmp); - size_t maxBuffSize = 1000 * 1000; while (eventList_.size()) { - int32_t size = std::min(maxBuffSize, eventList_.size()); + int32_t size = std::min(maxBuffSize_, eventList_.size()); auto endOfList = eventList_.begin() + size; for (auto itor = eventList_.begin(); itor != endOfList; itor++) { EventInfo *event = itor->get(); @@ -821,9 +827,9 @@ void BytraceEventParser::BeginFilterEvents(EventInfo *event) { auto it = eventToFunctionMap_.find(event->line.eventName); if (it != eventToFunctionMap_.end()) { - uint32_t tgid; + uint32_t tgid = event->line.tgid; ArgsMap args; - GetDataSegArgs(event->line, args, tgid); + GetDataSegArgs(event->line, args); if (tgid) { streamFilters_->processFilter_->UpdateOrCreateThreadWithPidAndName(event->line.pid, tgid, event->line.task); } else { diff --git a/trace_streamer/src/parser/ptreader_parser/bytrace_parser/bytrace_event_parser.h b/trace_streamer/src/parser/ptreader_parser/bytrace_parser/bytrace_event_parser.h index 8020006f27dd7090ff741ccc6999f0687fe5b85a..61e0436717deea85ea9c8b595dc04be80735eaf0 100644 --- a/trace_streamer/src/parser/ptreader_parser/bytrace_parser/bytrace_event_parser.h +++ b/trace_streamer/src/parser/ptreader_parser/bytrace_parser/bytrace_event_parser.h @@ -33,7 +33,7 @@ class BytraceEventParser : public EventParserBase { private: class EventInfo { public: - EventInfo(uint64_t ts, BytraceLine li) : eventTimestamp(ts), line(li) {} + EventInfo(uint64_t ts, const BytraceLine& li) : eventTimestamp(ts), line(li) {} uint64_t eventTimestamp; BytraceLine line; }; @@ -46,7 +46,7 @@ public: void Clear(); private: - using FuncCall = std::function; + using FuncCall = std::function; bool SchedSwitchEvent(const ArgsMap &args, const BytraceLine &line) const; bool BlockedReason(const ArgsMap &args, const BytraceLine &line) const; bool TaskRenameEvent(const ArgsMap &args, const BytraceLine &line) const; @@ -78,7 +78,7 @@ private: bool BinderTransaction(const ArgsMap &args, const BytraceLine &line) const; bool BinderTransactionReceived(const ArgsMap &args, const BytraceLine &line) const; bool BinderTransactionAllocBufEvent(const ArgsMap &args, const BytraceLine &line) const; - void GetDataSegArgs(BytraceLine &bufLine, ArgsMap &args, uint32_t &tgid) const; + void GetDataSegArgs(const BytraceLine& bufLine, ArgsMap& args) const; void InterruptEventInitialization(); void ClockEventInitialization(); void CpuEventInitialization(); @@ -116,6 +116,7 @@ private: const DataIndex schedBlockedReasonId_ = traceDataCache_->GetDataIndex("sched_blocked_reason"); const DataIndex cpuFrequencyLimitMaxNameId = traceDataCache_->GetDataIndex("cpu_frequency_limits_max"); const DataIndex cpuFrequencyLimitMinNameId = traceDataCache_->GetDataIndex("cpu_frequency_limits_min"); + const size_t maxBuffSize_ = 1000 * 1000; protected: TraceStreamerConfig config_{}; diff --git a/trace_streamer/src/parser/ptreader_parser/ptreader_parser.cpp b/trace_streamer/src/parser/ptreader_parser/ptreader_parser.cpp index 05de6e13fca91307d39f68fa057e8e1b4cf2a943..5ded73c2deabd4331f400ed0471a90d431768add 100644 --- a/trace_streamer/src/parser/ptreader_parser/ptreader_parser.cpp +++ b/trace_streamer/src/parser/ptreader_parser/ptreader_parser.cpp @@ -281,43 +281,38 @@ int32_t PtreaderParser::GetNextSegment() void PtreaderParser::GetDataSegAttr(DataSegment &seg, const std::smatch &matcheLine) const { - const uint64_t S_TO_NS = 1e9; size_t index = 0; - std::string pidStr = matcheLine[++index].str(); - std::optional optionalPid = base::StrToInt(pidStr); + std::optional optionalPid = base::StrToInt(matcheLine[++index].str()); if (!optionalPid.has_value()) { - TS_LOGD("Illegal pid: %s", pidStr.c_str()); + TS_LOGD("Illegal pid!"); seg.status = TS_PARSE_STATUS_INVALID; return; } - - std::string tGidStr = matcheLine[++index].str(); - std::string cpuStr = matcheLine[++index].str(); - std::optional optionalCpu = base::StrToInt(cpuStr); + seg.bufLine.tgid = base::StrToInt(matcheLine[++index].str()).value_or(0); + std::optional optionalCpu = base::StrToInt(matcheLine[++index].str()); if (!optionalCpu.has_value()) { - TS_LOGD("Illegal cpu %s", cpuStr.c_str()); + TS_LOGD("Illegal cpu!"); seg.status = TS_PARSE_STATUS_INVALID; return; } - std::string timeStr = matcheLine[++index].str(); // Directly parsing double may result in accuracy loss issues - std::optional optionalTime = base::StrToDouble(timeStr); + std::optional optionalTime = base::StrToDouble(matcheLine[++index].str()); if (!optionalTime.has_value()) { - TS_LOGD("Illegal ts %s", timeStr.c_str()); + TS_LOGE("Illegal ts"); seg.status = TS_PARSE_STATUS_INVALID; return; } - std::string eventName = matcheLine[++index].str(); - seg.bufLine.task = StrTrim(matcheLine.prefix()); + seg.bufLine.eventName = matcheLine[++index].str(); + seg.bufLine.task = matcheLine.prefix(); + StrTrim(seg.bufLine.task); if (seg.bufLine.task == "<...>") { seg.bufLine.task = ""; } - seg.bufLine.argsStr = StrTrim(matcheLine.suffix()); + seg.bufLine.argsStr = matcheLine.suffix(); + StrTrim(seg.bufLine.argsStr); seg.bufLine.pid = optionalPid.value(); seg.bufLine.cpu = optionalCpu.value(); - seg.bufLine.ts = optionalTime.value() * S_TO_NS; - seg.bufLine.tGidStr = tGidStr; - seg.bufLine.eventName = eventName; + seg.bufLine.ts = optionalTime.value() * 1e9; seg.status = TS_PARSE_STATUS_PARSED; } void PtreaderParser::ParseThread() @@ -405,17 +400,6 @@ bool PtreaderParser::FilterData(DataSegment &seg) seg.status = TS_PARSE_STATUS_INIT; return true; } -// Remove space at the beginning and end of the string -std::string PtreaderParser::StrTrim(const std::string &input) const -{ - std::string str = input; - if (str.empty()) { - return str; - } - str.erase(0, str.find_first_not_of(" ")); - str.erase(str.find_last_not_of(" ") + 1); - return str; -} #endif } // namespace TraceStreamer } // namespace SysTuning diff --git a/trace_streamer/src/parser/ptreader_parser/ptreader_parser.h b/trace_streamer/src/parser/ptreader_parser/ptreader_parser.h index 0a8cf66703259a147dc86b661ff389f625ab7e3e..b6faa0c0a39cff410160c59cc058af80943e958d 100644 --- a/trace_streamer/src/parser/ptreader_parser/ptreader_parser.h +++ b/trace_streamer/src/parser/ptreader_parser/ptreader_parser.h @@ -106,7 +106,7 @@ private: } inline static bool IsTraceComment(const std::string &buffer) { - return ((buffer[0] == '#') || buffer.find("TASK-PID") != std::string::npos); + return buffer[0] == '#'; } inline static bool IsHtmlTrace(const std::string &buffer) { @@ -119,7 +119,6 @@ private: { return buffer.find(R"(