1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "ffrt_converter.h"
16
17 namespace SysTuning {
18 namespace TraceStreamer {
RecoverTraceAndGenerateNewFile(const std::string & ffrtFileName,std::ofstream & outFile)19 bool FfrtConverter::RecoverTraceAndGenerateNewFile(const std::string& ffrtFileName, std::ofstream& outFile)
20 {
21 std::ifstream ffrtFile(ffrtFileName);
22 if (!ffrtFile.is_open() || !outFile.is_open()) {
23 TS_LOGE("ffrtFile or outFile is invalid.");
24 return false;
25 }
26 std::vector<std::string> lines;
27 std::string line;
28 while (std::getline(ffrtFile, line))
29 lines.push_back(std::move(line));
30 ffrtFile.close();
31 CheckTraceMarker(lines);
32 TypeFfrtPid result = ClassifyLogsForFfrtWorker(lines);
33 ConvertFfrtThreadToFfrtTask(lines, result);
34 for (const std::string& lineergodic : lines) {
35 outFile << lineergodic << std::endl;
36 }
37 return true;
38 }
CheckTraceMarker(vector<std::string> & lines)39 void FfrtConverter::CheckTraceMarker(vector<std::string>& lines)
40 {
41 for (auto line : lines) {
42 if (line.find(" tracing_mark_write: ") != std::string::npos) {
43 tracingMarkerKey_ = "tracing_mark_write: ";
44 break;
45 }
46 if (line.find(" print: ") != std::string::npos) {
47 tracingMarkerKey_ = "print: ";
48 break;
49 }
50 }
51 }
ExtractProcessId(const std::string & log)52 int FfrtConverter::ExtractProcessId(const std::string& log)
53 {
54 std::smatch match;
55 static const std::regex pidPattern = std::regex(R"(\(\s*\d+\) \[)");
56 if (std::regex_search(log, match, pidPattern)) {
57 for (size_t i = 0; i < match.size(); i++) {
58 if (match[i] == '-') {
59 return 0;
60 }
61 }
62 auto beginPos = match.str().find('(') + 1;
63 auto endPos = match.str().find(')');
64 return std::stoi(match.str().substr(beginPos, endPos - beginPos));
65 } else {
66 return 0;
67 }
68 }
69
ExtractTimeStr(const std::string & log)70 std::string FfrtConverter::ExtractTimeStr(const std::string& log)
71 {
72 std::smatch match;
73 static const std::regex timePattern = std::regex(R"( (\d+)\.(\d+):)");
74 if (std::regex_search(log, match, timePattern)) {
75 return match.str().substr(1, match.str().size() - STR_LEGH);
76 } else {
77 return "";
78 }
79 }
80
ExtractCpuId(const std::string & log)81 std::string FfrtConverter::ExtractCpuId(const std::string& log)
82 {
83 std::smatch match;
84 static const std::regex cpuIdPattern = std::regex(R"(\) \[.*?\])");
85 if (std::regex_search(log, match, cpuIdPattern)) {
86 auto beginPos = match.str().find('[') + 1;
87 auto endPos = match.str().find(']');
88 return match.str().substr(beginPos, endPos - beginPos);
89 } else {
90 return "";
91 }
92 }
93
MakeBeginFakeLog(const std::string & mark,const int pid,const std::string & label,const long long gid,const int tid,const std::string & threadName,const int prio)94 std::string FfrtConverter::MakeBeginFakeLog(const std::string& mark,
95 const int pid,
96 const std::string& label,
97 const long long gid,
98 const int tid,
99 const std::string& threadName,
100 const int prio)
101 {
102 auto beginTimeStamp = ExtractTimeStr(mark);
103 auto cpuId = ExtractCpuId(mark);
104 std::unique_ptr<char[]> result = std::make_unique<char[]>(MAX_LEN);
105 auto taskId = GetTaskId(pid, gid);
106 (void)sprintf_s(
107 result.get(), MAX_LEN,
108 "\n %s-%d (%7d) [%s] .... %s: sched_switch: prev_comm=%s prev_pid=%d prev_prio=%d prev_state=S ==> "
109 "next_comm=%s next_pid=%s next_prio=%d\n",
110 threadName.c_str(), tid, pid, cpuId.c_str(), beginTimeStamp.c_str(), threadName.c_str(), tid, prio,
111 label.c_str(), taskId.c_str(), prio);
112 return mark + result.get();
113 }
114
MakeEndFakeLog(const std::string & mark,const int pid,const std::string & label,const long long gid,const int tid,const std::string & threadName,const int prio)115 std::string FfrtConverter::MakeEndFakeLog(const std::string& mark,
116 const int pid,
117 const std::string& label,
118 const long long gid,
119 const int tid,
120 const std::string& threadName,
121 const int prio)
122 {
123 auto endTimeStamp = ExtractTimeStr(mark);
124 auto cpuId = ExtractCpuId(mark);
125 std::unique_ptr<char[]> result = std::make_unique<char[]>(MAX_LEN);
126 auto taskId = GetTaskId(pid, gid);
127 (void)sprintf_s(
128 result.get(), MAX_LEN,
129 " %s-%s (%7d) [%s] .... %s: sched_switch: prev_comm=%s prev_pid=%s prev_prio=%d prev_state=S ==> "
130 "next_comm=%s next_pid=%s next_prio=%d\n",
131 label.c_str(), taskId.c_str(), pid, cpuId.c_str(), endTimeStamp.c_str(), label.c_str(), taskId.c_str(), prio,
132 threadName.c_str(), tid, prio);
133 std::string fakeLog = result.get();
134 memset_s(result.get(), MAX_LEN, 0, MAX_LEN);
135 return fakeLog;
136 }
137
ReplaceSchedSwitchLog(std::string & fakeLog,const std::string & mark,const int pid,const std::string & label,const long long gid,const int tid)138 std::string FfrtConverter::ReplaceSchedSwitchLog(std::string& fakeLog,
139 const std::string& mark,
140 const int pid,
141 const std::string& label,
142 const long long gid,
143 const int tid)
144 {
145 std::unique_ptr<char[]> result = std::make_unique<char[]>(MAX_LEN);
146 std::smatch match;
147 auto taskId = GetTaskId(pid, gid);
148 if (mark.find("prev_pid=" + std::to_string(tid)) != std::string::npos) {
149 if (regex_search(fakeLog, match, indexPattern_)) {
150 auto beginPos = fakeLog.find(match.str());
151 (void)sprintf_s(result.get(), MAX_LEN, " %s-%s ", label.c_str(), taskId.c_str());
152 fakeLog = result.get() + fakeLog.substr(beginPos);
153 size_t pcommPos = fakeLog.find("prev_comm=");
154 size_t pPidPos = fakeLog.find("prev_pid=");
155 memset_s(result.get(), MAX_LEN, 0, MAX_LEN);
156 (void)sprintf_s(result.get(), MAX_LEN, "prev_comm=%s ", label.c_str());
157 fakeLog = fakeLog.substr(0, pcommPos) + result.get() + fakeLog.substr(pPidPos);
158 memset_s(result.get(), MAX_LEN, 0, MAX_LEN);
159 pPidPos = fakeLog.find("prev_pid=");
160 size_t pPrioPos = fakeLog.find("prev_prio=");
161 (void)sprintf_s(result.get(), MAX_LEN, "prev_pid=%s ", taskId.c_str());
162 fakeLog = fakeLog.substr(0, pPidPos) + result.get() + fakeLog.substr(pPrioPos);
163 memset_s(result.get(), MAX_LEN, 0, MAX_LEN);
164 }
165 } else if (mark.find("next_pid=" + std::to_string(tid)) != std::string::npos) {
166 (void)sprintf_s(result.get(), MAX_LEN, "next_comm=%s ", label.c_str());
167 size_t nCommPos = fakeLog.find("next_comm=");
168 size_t nPidPos = fakeLog.find("next_pid=");
169 fakeLog = fakeLog.substr(0, nCommPos) + result.get() + fakeLog.substr(nPidPos);
170 memset_s(result.get(), MAX_LEN, 0, MAX_LEN);
171 (void)sprintf_s(result.get(), MAX_LEN, "next_pid=%s ", taskId.c_str());
172 nPidPos = fakeLog.find("next_pid=");
173 size_t nPrioPos = fakeLog.find("next_prio=");
174 fakeLog = fakeLog.substr(0, nPidPos) + result.get() + fakeLog.substr(nPrioPos);
175 }
176 return fakeLog;
177 }
178
ReplaceSchedWakeLog(std::string & fakeLog,const std::string & label,const int pid,const long long gid)179 std::string FfrtConverter::ReplaceSchedWakeLog(std::string& fakeLog,
180 const std::string& label,
181 const int pid,
182 const long long gid)
183 {
184 std::unique_ptr<char[]> result = std::make_unique<char[]>(MAX_LEN);
185 auto taskId = GetTaskId(pid, gid);
186 (void)sprintf_s(result.get(), MAX_LEN, "comm=%s ", label.c_str());
187 size_t commPos = fakeLog.find("comm=");
188 size_t pidPos = fakeLog.find("pid=");
189 fakeLog = fakeLog.substr(0, commPos) + result.get() + fakeLog.substr(pidPos);
190 memset_s(result.get(), MAX_LEN, 0, MAX_LEN);
191 (void)sprintf_s(result.get(), MAX_LEN, "pid=%s ", taskId.c_str());
192 pidPos = fakeLog.find("pid=");
193 size_t prioPos = fakeLog.find("prio=");
194 fakeLog = fakeLog.substr(0, pidPos) + result.get() + fakeLog.substr(prioPos);
195 return fakeLog;
196 }
197
ReplaceSchedBlockLog(std::string & fakeLog,const int pid,const long long gid)198 std::string FfrtConverter::ReplaceSchedBlockLog(std::string& fakeLog, const int pid, const long long gid)
199 {
200 std::unique_ptr<char[]> result = std::make_unique<char[]>(MAX_LEN);
201 auto taskId = GetTaskId(pid, gid);
202 (void)sprintf_s(result.get(), MAX_LEN, "pid=%s ", taskId.c_str());
203 size_t pidPos = fakeLog.find("pid");
204 size_t ioPos = fakeLog.find("iowait=");
205 fakeLog = fakeLog.substr(0, pidPos) + result.get() + fakeLog.substr(ioPos);
206 return fakeLog;
207 }
ReplaceTracingMarkLog(std::string & fakeLog,const std::string & label,const int pid,const long long gid)208 std::string FfrtConverter::ReplaceTracingMarkLog(std::string& fakeLog,
209 const std::string& label,
210 const int pid,
211 const long long gid)
212 {
213 std::unique_ptr<char[]> result = std::make_unique<char[]>(MAX_LEN);
214 std::smatch match;
215 auto taskId = GetTaskId(pid, gid);
216 if (regex_search(fakeLog, match, indexPattern_)) {
217 auto beginPos = fakeLog.find(match.str());
218 (void)sprintf_s(result.get(), MAX_LEN, " %s-%s ", label.c_str(), taskId.c_str());
219 fakeLog = result.get() + fakeLog.substr(beginPos);
220 }
221 return fakeLog;
222 }
ConvertWorkerLogToTask(const std::string & mark,const int pid,const std::string & label,const long long gid,const int tid)223 std::string FfrtConverter::ConvertWorkerLogToTask(const std::string& mark,
224 const int pid,
225 const std::string& label,
226 const long long gid,
227 const int tid)
228 {
229 std::string fakeLog = mark;
230 if (mark.find("sched_switch: ") != std::string::npos) {
231 return ReplaceSchedSwitchLog(fakeLog, mark, pid, label, gid, tid);
232 }
233 if (mark.find(": sched_wak") != std::string::npos) {
234 return ReplaceSchedWakeLog(fakeLog, label, pid, gid);
235 }
236 if (mark.find("sched_blocked_reason: ") != std::string::npos) {
237 return ReplaceSchedBlockLog(fakeLog, pid, gid);
238 }
239 return ReplaceTracingMarkLog(fakeLog, label, pid, gid);
240 }
FindTid(std::string & log)241 int FfrtConverter::FindTid(std::string& log)
242 {
243 std::string index = "prev_pid=";
244 auto beginPos = log.find(index);
245 auto endPos = log.find_first_of(" ", beginPos);
246 beginPos = beginPos + index.length();
247 auto tid = stoi(log.substr(beginPos, endPos - beginPos));
248 return tid;
249 }
250
ClassifySchedSwitchLogs(std::string & log,size_t line,std::unordered_map<int,std::vector<int>> & traceMap,FfrtConverter::TypeFfrtPid & ffrtPidsMap)251 void FfrtConverter::ClassifySchedSwitchLogs(std::string& log,
252 size_t line,
253 std::unordered_map<int, std::vector<int>>& traceMap,
254 FfrtConverter::TypeFfrtPid& ffrtPidsMap)
255 {
256 if (log.find("prev_comm=ffrt") != std::string::npos || log.find("prev_comm=OS_FFRT") != std::string::npos) {
257 auto pid = ExtractProcessId(log);
258 if (ffrtPidsMap.find(pid) == ffrtPidsMap.end()) {
259 ffrtPidsMap[pid] = {};
260 }
261 std::string begin = "prev_comm=";
262 std::string end = " prev_pid=";
263 auto beginPos = log.find(begin) + begin.length();
264 auto endPos = log.find(end);
265 auto tid = FindTid(log);
266 if (ffrtPidsMap[pid].find(tid) == ffrtPidsMap[pid].end()) {
267 ffrtPidsMap[pid][tid].name = log.substr(beginPos, endPos - beginPos);
268 }
269 }
270 auto prevTid = FindTid(log);
271 if (traceMap.find(prevTid) == traceMap.end()) {
272 traceMap[prevTid] = std::vector<int>();
273 }
274 traceMap[prevTid].push_back(line);
275 std::string begin = "next_pid=";
276 auto beginPos = log.find(begin) + begin.length();
277 std::string end = " next_prio=";
278 auto endPos = log.find(end);
279 auto nextTid = stoi(log.substr(beginPos, endPos - beginPos));
280 if (traceMap.find(nextTid) == traceMap.end()) {
281 traceMap[nextTid] = std::vector<int>();
282 }
283 traceMap[nextTid].push_back(line);
284 return;
285 }
FindFfrtProcessAndClassifyLogs(std::string & log,size_t line,std::unordered_map<int,std::vector<int>> & traceMap,FfrtConverter::TypeFfrtPid & ffrtPidsMap)286 void FfrtConverter::FindFfrtProcessAndClassifyLogs(std::string& log,
287 size_t line,
288 std::unordered_map<int, std::vector<int>>& traceMap,
289 FfrtConverter::TypeFfrtPid& ffrtPidsMap)
290 {
291 if (log.find("sched_switch") != std::string::npos) {
292 ClassifySchedSwitchLogs(log, line, traceMap, ffrtPidsMap);
293 return;
294 }
295 if (log.find(": sched_wak") != std::string::npos || (log.find("sched_blocked_reason:") != std::string::npos)) {
296 std::string begin = "pid=";
297 auto beginPos = log.find(begin);
298 auto endPos = log.find_first_of(" ", beginPos);
299 beginPos = beginPos + begin.length();
300 auto tid = stoi(log.substr(beginPos, endPos - beginPos));
301 if (traceMap.find(tid) == traceMap.end()) {
302 traceMap[tid] = std::vector<int>();
303 }
304 traceMap[tid].push_back(line);
305 return;
306 }
307 static std::smatch match;
308 if (std::regex_search(log, match, matchPattern_)) {
309 auto endPos = log.find(match.str());
310 std::string res = log.substr(0, endPos);
311 std::string begin = "-";
312 auto beginPos = res.find_last_of(begin);
313 beginPos = beginPos + begin.length();
314 auto tid = stoi(log.substr(beginPos, endPos - beginPos));
315 if (traceMap.find(tid) == traceMap.end()) {
316 traceMap[tid] = std::vector<int>();
317 }
318 traceMap[tid].push_back(line);
319 }
320 return;
321 }
322
GetTaskId(int pid,long long gid)323 std::string FfrtConverter::GetTaskId(int pid, long long gid)
324 {
325 std::stringstream ss;
326 auto max = INVALID_UINT32 / scaleFactor_;
327 int length = 1;
328 auto temp = gid;
329 while (temp > 0) {
330 temp /= scaleFactor_;
331 length++;
332 max /= scaleFactor_;
333 }
334 while (pid >= max) {
335 pid /= scaleFactor_;
336 }
337 ss << pid << "0" << gid;
338 return ss.str();
339 }
340
IsDigit(const std::string & str)341 bool FfrtConverter::IsDigit(const std::string& str)
342 {
343 auto endPos = str.find_last_not_of(" ");
344 string newStr = str;
345 newStr.erase(endPos + 1);
346 if (newStr.back() == '\r') {
347 newStr.pop_back();
348 }
349 for (int i = 0; i < newStr.length(); i++) {
350 if (!std::isdigit(newStr[i])) {
351 return false;
352 }
353 }
354 return true;
355 }
356
ClassifyLogsForFfrtWorker(vector<std::string> & results)357 FfrtConverter::TypeFfrtPid FfrtConverter::ClassifyLogsForFfrtWorker(vector<std::string>& results)
358 {
359 TypeFfrtPid ffrtPidMap;
360 std::unordered_map<int, std::vector<int>> traceMap;
361 for (auto line = 0; line < results.size(); line++) {
362 FindFfrtProcessAndClassifyLogs(results[line], line, traceMap, ffrtPidMap);
363 }
364 for (auto& [pid, tids] : ffrtPidMap) {
365 for (const auto& pair : tids) {
366 auto tid = pair.first;
367 ffrtPidMap[pid][tid].line = traceMap[tid];
368 }
369 }
370 return ffrtPidMap;
371 }
UpdatePrio(int & prio,const std::string & mark,const int tid)372 void FfrtConverter::UpdatePrio(int& prio, const std::string& mark, const int tid)
373 {
374 if (mark.find("sched_switch:") == std::string::npos) {
375 return;
376 }
377 if (mark.find("prev_pid=" + std::to_string(tid) + " ") != std::string::npos) {
378 static std::string beginPprio = "prev_prio=";
379 auto beginPos = mark.find(beginPprio);
380 beginPos = beginPos + beginPprio.length();
381 auto endPos = mark.find_first_of(" ", beginPos);
382 prio = stoi(mark.substr(beginPos, endPos - beginPos));
383 } else if (mark.find("next_pid=" + std::to_string(tid)) != std::string::npos) {
384 static std::string beginNprio = "next_prio=";
385 auto beginPos = mark.find(beginNprio);
386 beginPos = beginPos + beginNprio.length();
387 prio = stoi(mark.substr(beginPos));
388 }
389 }
GetLabel(const string & mark)390 std::string FfrtConverter::GetLabel(const string& mark)
391 {
392 std::string label;
393 if (mark.find("|H:FFRT") != std::string::npos) {
394 if (mark.find("H:FFRT::") != std::string::npos) {
395 auto beginPos = mark.rfind("[");
396 auto endPos = mark.rfind("]");
397 auto label = mark.substr(beginPos + 1, endPos - beginPos - 1);
398 } else {
399 static std::string indexHFfrt = "|H:FFRT";
400 auto beginPos = mark.find(indexHFfrt);
401 beginPos = beginPos + indexHFfrt.length();
402 auto endPos = mark.find_first_of("|", beginPos);
403 label = mark.substr(beginPos, endPos - beginPos);
404 }
405 } else {
406 if (mark.find("|FFRT::") != std::string::npos) {
407 auto beginPos = mark.rfind("[");
408 auto endPos = mark.rfind("]");
409 auto label = mark.substr(beginPos + 1, endPos - beginPos - 1);
410 } else {
411 static std::string indexFfrt = "|FFRT";
412 auto beginPos = mark.find(indexFfrt);
413 beginPos = beginPos + indexFfrt.length();
414 auto endPos = mark.find_first_of("|", beginPos);
415 label = mark.substr(beginPos, endPos - beginPos);
416 }
417 }
418 return label;
419 }
getNewMissLog(std::string & missLog,const std::string & mark,const int pid,const int tid,std::string threadName)420 std::string FfrtConverter::getNewMissLog(std::string& missLog,
421 const std::string& mark,
422 const int pid,
423 const int tid,
424 std::string threadName)
425 {
426 auto timestamp = ExtractTimeStr(mark);
427 auto cpuId = ExtractCpuId(mark);
428 std::unique_ptr<char[]> result = std::make_unique<char[]>(MAX_LEN);
429 (void)sprintf_s(result.get(), MAX_LEN, " %s-%d (%7d) [%s] .... %s: %sE|%d\n", threadName.c_str(), tid, pid,
430 cpuId.c_str(), timestamp.c_str(), tracingMarkerKey_.c_str(), pid);
431 missLog = missLog + result.get();
432 memset_s(result.get(), MAX_LEN, 0, MAX_LEN);
433 return missLog;
434 }
435
DeleteRedundance(const std::string & mark,std::string & log,bool switchInFakeLog,bool switchOutFakeLog,const int pid,const std::string & label,long long gid,const int tid,const std::string & threadName,const int prio)436 void FfrtConverter::DeleteRedundance(const std::string& mark,
437 std::string& log,
438 bool switchInFakeLog,
439 bool switchOutFakeLog,
440 const int pid,
441 const std::string& label,
442 long long gid,
443 const int tid,
444 const std::string& threadName,
445 const int prio)
446 {
447 static const std::regex CoPattern = std::regex(R"( F\|(\d+)\|Co\|(\d+))");
448 static const std::regex HCoPattern = std::regex(R"( F\|(\d+)\|H:Co\s(\d+))");
449 if (std::regex_search(mark, CoPattern) || std::regex_search(mark, HCoPattern)) {
450 log.clear();
451 if (switchInFakeLog) {
452 switchInFakeLog = false;
453 return;
454 } else {
455 switchOutFakeLog = true;
456 return;
457 }
458 }
459 if (switchInFakeLog && (mark.find(tracingMarkerKey_ + "B") != std::string::npos)) {
460 log.clear();
461 return;
462 }
463 if (switchOutFakeLog && (mark.find(tracingMarkerKey_ + "E") != std::string::npos)) {
464 log.clear();
465 return;
466 }
467 static const std::regex EndPattern = std::regex(R"( F\|(\d+)\|[BF]\|(\d+))");
468 static const std::regex HEndPattern = std::regex(R"( F\|(\d+)\|H:[BF]\s(\d+))");
469 if (std::regex_search(mark, EndPattern) || std::regex_search(mark, HEndPattern)) {
470 log = MakeEndFakeLog(mark, pid, label, gid, tid, threadName, prio);
471 gid = WAKE_EVENT_DEFAULT_VALUE;
472 switchOutFakeLog = false;
473 return;
474 }
475 auto fakeLog = ConvertWorkerLogToTask(mark, pid, label, gid, tid);
476 log = fakeLog;
477 return;
478 }
ConvertFfrtThreadToFfrtTaskByLine(int pid,int tid,int & prio,std::vector<std::string> & results,ffrtContent & content,std::unordered_map<int,std::unordered_map<int,std::string>> & taskLabels)479 void FfrtConverter::ConvertFfrtThreadToFfrtTaskByLine(
480 int pid,
481 int tid,
482 int& prio,
483 std::vector<std::string>& results,
484 ffrtContent& content,
485 std::unordered_map<int, std::unordered_map<int, std::string>>& taskLabels)
486 {
487 auto& threadName = content.name;
488 auto switchInFakeLog = false;
489 auto switchOutFakeLog = false;
490 auto gid = WAKE_EVENT_DEFAULT_VALUE;
491 for (auto& line : content.line) {
492 auto mark = results[line];
493 UpdatePrio(prio, mark, tid);
494 if (mark.find("FFRT::[") != std::string::npos) {
495 std::string missLog;
496 auto label = GetLabel(mark);
497 if (label.find("executor_task") != std::string::npos || label.find("ex_task") != std::string::npos) {
498 continue;
499 }
500 if (gid != WAKE_EVENT_DEFAULT_VALUE) {
501 missLog = MakeEndFakeLog(mark, pid, taskLabels[pid][gid], gid, tid, threadName, prio);
502 missLog = getNewMissLog(missLog, mark, pid, tid, threadName);
503 }
504 auto beginPos = mark.rfind("|");
505 if (beginPos != std::string::npos && IsDigit(mark.substr(beginPos + 1))) {
506 gid = stoll(mark.substr(beginPos + 1));
507 } else {
508 continue;
509 }
510 if (taskLabels[pid].find(gid) == taskLabels[pid].end()) {
511 taskLabels[pid][gid] = label;
512 }
513 results[line] = MakeBeginFakeLog(mark, pid, taskLabels[pid][gid], gid, tid, threadName, prio);
514 if (!missLog.empty()) {
515 results[line] = missLog + results[line];
516 }
517 switchInFakeLog = true;
518 continue;
519 }
520 if (gid != WAKE_EVENT_DEFAULT_VALUE) {
521 DeleteRedundance(mark, results[line], switchInFakeLog, switchOutFakeLog, pid, taskLabels[pid][gid], gid,
522 tid, threadName, prio);
523 }
524 }
525 }
ConvertFfrtThreadToFfrtTask(vector<std::string> & results,FfrtConverter::TypeFfrtPid & ffrtPidsMap)526 void FfrtConverter::ConvertFfrtThreadToFfrtTask(vector<std::string>& results, FfrtConverter::TypeFfrtPid& ffrtPidsMap)
527 {
528 int prio;
529 std::unordered_map<int, std::unordered_map<int, std::string>> taskLabels;
530 for (auto& [pid, tids] : ffrtPidsMap) {
531 taskLabels[pid] = {};
532 for (auto& [tid, info] : ffrtPidsMap[pid]) {
533 ConvertFfrtThreadToFfrtTaskByLine(pid, tid, prio, results, info, taskLabels);
534 }
535 }
536 return;
537 }
538 } // namespace TraceStreamer
539 } // namespace SysTuning
540