• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef TRACE_STDTYPE_H
17 #define TRACE_STDTYPE_H
18 
19 #include <array>
20 #include <deque>
21 #include <limits>
22 #include <map>
23 #include <mutex>
24 #include <optional>
25 #include <sstream>
26 #include <stdexcept>
27 #include <string>
28 #include <unordered_map>
29 #include <vector>
30 
31 #include "cfg/trace_streamer_config.h"
32 #include "double_map.h"
33 #include "log.h"
34 #include "ts_common.h"
35 
36 namespace SysTuning {
37 namespace TraceStdtype {
38 using namespace SysTuning::TraceCfg;
39 using namespace SysTuning::TraceStreamer;
40 class CacheBase {
41 public:
Size()42     size_t Size() const
43     {
44         return std::max(timeStamps_.size(), ids_.size());
45     }
IdsData()46     const std::deque<uint64_t>& IdsData() const
47     {
48         return ids_;
49     }
TimeStamData()50     const std::deque<uint64_t>& TimeStamData() const
51     {
52         return timeStamps_;
53     }
InternalTidsData()54     const std::deque<InternalTid>& InternalTidsData() const
55     {
56         return internalTids_;
57     }
Clear()58     virtual void Clear()
59     {
60         internalTids_.clear();
61         timeStamps_.clear();
62         ids_.clear();
63     }
64 
65 public:
66     std::deque<InternalTid> internalTids_ = {};
67     std::deque<uint64_t> timeStamps_ = {};
68     std::deque<uint64_t> ids_ = {};
69 };
70 
71 class CpuCacheBase {
72 public:
DursData()73     const std::deque<uint64_t>& DursData() const
74     {
75         return durs_;
76     }
77 
CpusData()78     const std::deque<uint32_t>& CpusData() const
79     {
80         return cpus_;
81     }
Clear()82     virtual void Clear()
83     {
84         durs_.clear();
85         cpus_.clear();
86     }
87     void SetDur(uint64_t index, uint64_t dur);
88 public:
89     std::deque<uint64_t> durs_;
90     std::deque<uint32_t> cpus_;
91 };
92 class Thread {
93 public:
Thread(uint32_t t)94     explicit Thread(uint32_t t) : tid_(t) {}
95     InternalPid internalPid_ = INVALID_UINT32;
96     uint32_t tid_ = 0;
97     DataIndex nameIndex_ = 0;
98     InternalTime startT_ = 0;
99     InternalTime endT_ = 0;
100     uint32_t switchCount_ = 0;
101     uint32_t sliceSize_ = 0;
102     uint32_t cpuStatesCount_ = 0;
103 };
104 
105 class Process {
106 public:
Process(uint32_t p)107     explicit Process(uint32_t p) : pid_(p) {}
108     std::string cmdLine_ = "";
109     InternalTime startT_ = 0;
110     uint32_t pid_ = 0;
111     uint32_t memSize_ = 0;
112     uint32_t threadSize_ = 0;
113     uint32_t sliceSize_ = 0;
114     uint32_t switchCount_ = 0;
115     int32_t threadCount_ = -1;
116     uint32_t cpuStatesCount_ = 0;
117 };
118 
119 class ThreadState {
120 public:
121     TableRowId
122         AppendThreadState(InternalTime ts, InternalTime dur, InternalCpu cpu, InternalTid itid, TableRowId idState);
123     void SetDuration(TableRowId index, InternalTime dur);
124     TableRowId UpdateDuration(TableRowId index, InternalTime ts);
125     void UpdateState(TableRowId index, TableRowId idState);
126     void UpdateDuration(TableRowId index, InternalTime ts, TableRowId idState);
127     void UpdateTidAndPid(TableRowId index, InternalTid tid, InternalTid pid);
128     TableRowId UpdateDuration(TableRowId index, InternalTime ts, InternalCpu cpu, TableRowId idState);
Clear()129     void Clear()
130     {
131         timeStamps_.clear();
132         durations_.clear();
133         itids_.clear();
134         tids_.clear();
135         pids_.clear();
136         states_.clear();
137         cpus_.clear();
138     }
Size()139     const uint32_t Size() const
140     {
141         return itids_.size();
142     }
143 
TimeStamsData()144     const std::deque<InternalTime>& TimeStamsData() const
145     {
146         return timeStamps_;
147     }
DursData()148     const std::deque<InternalTime>& DursData() const
149     {
150         return durations_;
151     }
ItidsData()152     const std::deque<InternalTid>& ItidsData() const
153     {
154         return itids_;
155     }
TidsData()156     const std::deque<InternalTid>& TidsData() const
157     {
158         return tids_;
159     }
PidsData()160     const std::deque<InternalPid>& PidsData() const
161     {
162         return pids_;
163     }
StatesData()164     const std::deque<DataIndex>& StatesData() const
165     {
166         return states_;
167     }
CpusData()168     const std::deque<InternalCpu>& CpusData() const
169     {
170         return cpus_;
171     }
172 private:
173     std::deque<InternalTime> timeStamps_;
174     std::deque<InternalTime> durations_;
175     std::deque<InternalTid> itids_;
176     std::deque<InternalTid> tids_;
177     std::deque<InternalPid> pids_;
178     std::deque<DataIndex> states_;
179     std::deque<InternalCpu> cpus_;
180 };
181 
182 class SchedSlice : public CacheBase, public CpuCacheBase {
183 public:
184     size_t AppendSchedSlice(uint64_t ts,
185                             uint64_t dur,
186                             uint64_t cpu,
187                             uint64_t internalTid,
188                             uint64_t endState,
189                             uint64_t priority);
190     void SetDuration(size_t index, uint64_t duration);
191     void Update(uint64_t index, uint64_t ts, uint64_t state, uint64_t pior);
192 
EndStatesData()193     const std::deque<uint64_t>& EndStatesData() const
194     {
195         return endStates_;
196     }
197 
PriorityData()198     const std::deque<uint64_t>& PriorityData() const
199     {
200         return priority_;
201     }
TsEndData()202     const std::deque<uint64_t>& TsEndData() const
203     {
204         return tsEnds_;
205     }
InternalPidsData()206     const std::deque<InternalPid>& InternalPidsData() const
207     {
208         return internalPids_;
209     }
AppendInternalPid(InternalPid ipid)210     void AppendInternalPid(InternalPid ipid)
211     {
212         internalPids_.emplace_back(ipid);
213     }
Clear()214     void Clear() override
215     {
216         CacheBase::Clear();
217         CpuCacheBase::Clear();
218         endStates_.clear();
219         priority_.clear();
220         internalPids_.clear();
221         tsEnds_.clear();
222     }
223 
224 private:
225     std::deque<InternalPid> internalPids_ = {};
226     std::deque<uint64_t> tsEnds_ = {};
227     std::deque<uint64_t> endStates_ = {};
228     std::deque<uint64_t> priority_ = {};
229 };
230 
231 class CallStack : public CacheBase, public CpuCacheBase {
232 public:
233     size_t AppendInternalAsyncSlice(uint64_t startT,
234                                     uint64_t durationNs,
235                                     InternalTid internalTid,
236                                     DataIndex cat,
237                                     uint16_t nameIdentify,
238                                     DataIndex name,
239                                     uint8_t depth,
240                                     uint64_t cookid,
241                                     const std::optional<uint64_t>& parentId);
242     size_t AppendInternalSlice(uint64_t startT,
243                                uint64_t durationNs,
244                                InternalTid internalTid,
245                                DataIndex cat,
246                                uint16_t nameIdentify,
247                                DataIndex name,
248                                uint8_t depth,
249                                const std::optional<uint64_t>& parentId);
250     void SetDistributeInfo(size_t index,
251                            const std::string& chainId,
252                            const std::string& spanId,
253                            const std::string& parentSpanId,
254                            const std::string& flag,
255                            const std::string& args);
256     void AppendDistributeInfo(const std::string& chainId,
257                               const std::string& spanId,
258                               const std::string& parentSpanId,
259                               const std::string& flag,
260                               const std::string& args);
261     void AppendDistributeInfo();
262     void SetDuration(size_t index, uint64_t timestamp);
263     void SetIrqDurAndArg(size_t index, uint64_t timestamp, uint32_t argSetId);
264     void SetTimeStamp(size_t index, uint64_t timestamp);
265     void SetDepth(size_t index, uint8_t depth);
266     void SetArgSetId(size_t index, uint32_t argSetId);
Clear()267     void Clear() override
268     {
269         CacheBase::Clear();
270         CpuCacheBase::Clear();
271         cats_.clear();
272         cookies_.clear();
273         callIds_.clear();
274         names_.clear();
275         depths_.clear();
276         chainIds_.clear();
277         spanIds_.clear();
278         parentSpanIds_.clear();
279         flags_.clear();
280         args_.clear();
281         argSet_.clear();
282     }
283 
284     const std::deque<std::optional<uint64_t>>& ParentIdData() const;
285     const std::deque<DataIndex>& CatsData() const;
286     const std::deque<DataIndex>& NamesData() const;
287     const std::deque<uint8_t>& Depths() const;
288     const std::deque<uint64_t>& Cookies() const;
289     const std::deque<uint32_t>& CallIds() const;
290     const std::deque<uint16_t>& IdentifysData() const;
291     const std::deque<std::string>& ChainIds() const;
292     const std::deque<std::string>& SpanIds() const;
293     const std::deque<std::string>& ParentSpanIds() const;
294     const std::deque<std::string>& Flags() const;
295     const std::deque<std::string>& ArgsData() const;
296     const std::deque<uint32_t>& ArgSetIdsData() const;
297 
298 private:
299     void AppendCommonInfo(uint64_t startT, uint64_t durationNs, InternalTid internalTid);
300     void AppendCallStack(DataIndex cat, DataIndex name, uint8_t depth, std::optional<uint64_t> parentId);
301 
302 private:
303     std::deque<std::optional<uint64_t>> parentIds_;
304     std::deque<DataIndex> cats_ = {};
305     std::deque<uint64_t> cookies_ = {};
306     std::deque<uint32_t> callIds_ = {};
307     std::deque<uint16_t> identifys_ = {};
308     std::deque<DataIndex> names_ = {};
309     std::deque<uint8_t> depths_ = {};
310 
311     std::deque<std::string> chainIds_ = {};
312     std::deque<std::string> spanIds_ = {};
313     std::deque<std::string> parentSpanIds_ = {};
314     std::deque<std::string> flags_ = {};
315     std::deque<std::string> args_ = {};
316     std::deque<uint32_t> argSet_ = {};
317 };
318 
319 class Filter : public CacheBase {
320 public:
321     size_t AppendNewFilterData(std::string type, std::string name, uint64_t sourceArgSetId);
NameData()322     const std::deque<std::string>& NameData() const
323     {
324         return nameDeque_;
325     }
TypeData()326     const std::deque<std::string>& TypeData() const
327     {
328         return typeDeque_;
329     }
SourceArgSetIdData()330     const std::deque<uint64_t>& SourceArgSetIdData() const
331     {
332         return sourceArgSetId_;
333     }
Clear()334     void Clear() override
335     {
336         CacheBase::Clear();
337         nameDeque_.clear();
338         typeDeque_.clear();
339         sourceArgSetId_.clear();
340     }
341 
342 private:
343     std::deque<std::string> nameDeque_ = {};
344     std::deque<std::string> typeDeque_ = {};
345     std::deque<uint64_t> sourceArgSetId_ = {};
346 };
347 
348 class Measure : public CacheBase {
349 public:
350     size_t AppendMeasureData(uint32_t type, uint64_t timestamp, int64_t value, uint32_t filterId);
TypeData()351     const std::deque<uint32_t>& TypeData() const
352     {
353         return typeDeque_;
354     }
ValuesData()355     const std::deque<int64_t>& ValuesData() const
356     {
357         return valuesDeque_;
358     }
FilterIdData()359     const std::deque<uint32_t>& FilterIdData() const
360     {
361         return filterIdDeque_;
362     }
Clear()363     void Clear() override
364     {
365         CacheBase::Clear();
366         typeDeque_.clear();
367         valuesDeque_.clear();
368         filterIdDeque_.clear();
369     }
370 
371 private:
372     std::deque<uint32_t> typeDeque_ = {};
373     std::deque<int64_t> valuesDeque_ = {};
374     std::deque<uint32_t> filterIdDeque_ = {};
375 };
376 
377 class Raw : public CacheBase {
378 public:
379     size_t AppendRawData(uint32_t id, uint64_t timestamp, uint32_t name, uint32_t cpu, uint32_t internalTid);
NameData()380     const std::deque<uint32_t>& NameData() const
381     {
382         return nameDeque_;
383     }
CpuData()384     const std::deque<uint32_t>& CpuData() const
385     {
386         return cpuDeque_;
387     }
InternalTidData()388     const std::deque<uint32_t>& InternalTidData() const
389     {
390         return itidDeque_;
391     }
Clear()392     void Clear() override
393     {
394         CacheBase::Clear();
395         nameDeque_.clear();
396         cpuDeque_.clear();
397         itidDeque_.clear();
398     }
399 
400 private:
401     std::deque<uint32_t> nameDeque_ = {};
402     std::deque<uint32_t> cpuDeque_ = {};
403     std::deque<uint32_t> itidDeque_ = {};
404 };
405 
406 class ThreadMeasureFilter {
407 public:
408     size_t AppendNewFilter(uint64_t filterId, uint32_t nameIndex, uint64_t internalTid);
Size()409     size_t Size() const
410     {
411         return filterId_.size();
412     }
FilterIdData()413     const std::deque<uint64_t>& FilterIdData() const
414     {
415         return filterId_;
416     }
InternalTidData()417     const std::deque<uint64_t>& InternalTidData() const
418     {
419         return internalTids_;
420     }
NameIndexData()421     const std::deque<uint32_t>& NameIndexData() const
422     {
423         return nameIndex_;
424     }
Clear()425     void Clear()
426     {
427         filterId_.clear();
428         internalTids_.clear();
429         nameIndex_.clear();
430     }
431 
432 private:
433     std::deque<uint64_t> filterId_ = {};
434     std::deque<uint64_t> internalTids_ = {};
435     std::deque<uint32_t> nameIndex_ = {};
436 };
437 
438 class CpuMeasureFilter : public CacheBase {
439 public:
AppendNewFilter(uint64_t filterId,DataIndex name,uint32_t cpu)440     inline size_t AppendNewFilter(uint64_t filterId, DataIndex name, uint32_t cpu)
441     {
442         ids_.emplace_back(filterId);
443         cpu_.emplace_back(cpu);
444         name_.emplace_back(name);
445         return Size() - 1;
446     }
447 
CpuData()448     const std::deque<uint32_t>& CpuData() const
449     {
450         return cpu_;
451     }
452 
TypeData()453     const std::deque<DataIndex>& TypeData() const
454     {
455         return type_;
456     }
457 
NameData()458     const std::deque<DataIndex>& NameData() const
459     {
460         return name_;
461     }
Clear()462     void Clear() override
463     {
464         CacheBase::Clear();
465         cpu_.clear();
466         type_.clear();
467         name_.clear();
468     }
469 
470 private:
471     std::deque<uint32_t> cpu_ = {};
472     std::deque<DataIndex> type_ = {};
473     std::deque<DataIndex> name_ = {};
474 };
475 
476 class Instants : public CacheBase {
477 public:
478     size_t AppendInstantEventData(uint64_t timestamp,
479                                   DataIndex nameIndex,
480                                   int64_t internalTid,
481                                   int64_t wakeupFromInternalPid);
482 
NameIndexsData()483     const std::deque<DataIndex>& NameIndexsData() const
484     {
485         return NameIndexs_;
486     }
WakeupFromPidsData()487     const std::deque<int64_t>& WakeupFromPidsData() const
488     {
489         return wakeupFromInternalPids_;
490     }
Clear()491     void Clear() override
492     {
493         CacheBase::Clear();
494         NameIndexs_.clear();
495         wakeupFromInternalPids_.clear();
496     }
497 
498 private:
499     std::deque<DataIndex> NameIndexs_;
500     std::deque<int64_t> wakeupFromInternalPids_;
501 };
502 
503 class ProcessMeasureFilter : public CacheBase {
504 public:
505     size_t AppendNewFilter(uint64_t id, DataIndex name, uint32_t internalPid);
506 
UpidsData()507     const std::deque<uint32_t>& UpidsData() const
508     {
509         return internalPids_;
510     }
511 
NamesData()512     const std::deque<DataIndex>& NamesData() const
513     {
514         return names_;
515     }
Clear()516     void Clear() override
517     {
518         CacheBase::Clear();
519         internalPids_.clear();
520         names_.clear();
521     }
522 
523 private:
524     std::deque<uint32_t> internalPids_ = {};
525     std::deque<DataIndex> names_ = {};
526 };
527 class ClockEventData : public CacheBase {
528 public:
529     size_t AppendNewFilter(uint64_t id, DataIndex type, DataIndex name, uint64_t cpu);
530 
CpusData()531     const std::deque<uint64_t>& CpusData() const
532     {
533         return cpus_;
534     }
535 
NamesData()536     const std::deque<DataIndex>& NamesData() const
537     {
538         return names_;
539     }
TypesData()540     const std::deque<DataIndex>& TypesData() const
541     {
542         return types_;
543     }
Clear()544     void Clear() override
545     {
546         CacheBase::Clear();
547         cpus_.clear();
548         names_.clear();
549         types_.clear();
550     }
551 
552 private:
553     std::deque<uint64_t> cpus_ = {}; // in clock_set_rate event, it save cpu
554     std::deque<DataIndex> names_ = {};
555     std::deque<DataIndex> types_ = {};
556 };
557 class ClkEventData : public CacheBase {
558 public:
559     size_t AppendNewFilter(uint64_t id, uint64_t rate, DataIndex name, uint64_t cpu);
560 
NamesData()561     const std::deque<DataIndex>& NamesData() const
562     {
563         return names_;
564     }
RatesData()565     const std::deque<uint64_t>& RatesData() const
566     {
567         return rates_;
568     }
CpusData()569     const std::deque<uint64_t>& CpusData() const
570     {
571         return cpus_;
572     }
Clear()573     void Clear() override
574     {
575         CacheBase::Clear();
576         names_.clear();
577         rates_.clear();
578         cpus_.clear();
579     }
580 
581 private:
582     std::deque<DataIndex> names_;
583     std::deque<uint64_t> rates_;
584     std::deque<uint64_t> cpus_;
585 };
586 class SysCall : public CacheBase {
587 public:
588     size_t AppendSysCallData(int64_t sysCallNum, DataIndex type, uint64_t ipid, uint64_t timestamp, int64_t ret);
SysCallsData()589     const std::deque<int64_t>& SysCallsData() const
590     {
591         return sysCallNums_;
592     }
TypesData()593     const std::deque<DataIndex>& TypesData() const
594     {
595         return types_;
596     }
IpidsData()597     const std::deque<uint64_t>& IpidsData() const
598     {
599         return ipids_;
600     }
RetsData()601     const std::deque<uint64_t>& RetsData() const
602     {
603         return rets_;
604     }
Clear()605     void Clear() override
606     {
607         CacheBase::Clear();
608         sysCallNums_.clear();
609         types_.clear();
610         ipids_.clear();
611         rets_.clear();
612     }
613 
614 private:
615     std::deque<int64_t> sysCallNums_ = {};
616     std::deque<DataIndex> types_ = {};
617     std::deque<uint64_t> ipids_ = {};
618     std::deque<uint64_t> rets_ = {};
619 };
620 class ArgSet : public CacheBase {
621 public:
622     size_t AppendNewArg(DataIndex nameId, BaseDataType dataType, int64_t value, size_t argSet);
623     const std::deque<BaseDataType>& DataTypes() const;
624     const std::deque<int64_t>& ValuesData() const;
625     const std::deque<uint64_t>& ArgsData() const;
626     const std::deque<DataIndex>& NamesData() const;
627 
Clear()628     void Clear() override
629     {
630         CacheBase::Clear();
631         names_.clear();
632         dataTypes_.clear();
633         values_.clear();
634         argset_.clear();
635     }
636 
637 private:
638     std::deque<uint64_t> names_ = {};
639     std::deque<BaseDataType> dataTypes_ = {};
640     std::deque<int64_t> values_ = {};
641     std::deque<uint64_t> argset_ = {};
642 };
643 class SysMeasureFilter : public CacheBase {
644 public:
645     size_t AppendNewFilter(uint64_t filterId, DataIndex type, DataIndex nameId);
646     const std::deque<DataIndex>& NamesData() const;
647     const std::deque<DataIndex>& TypesData() const;
Clear()648     void Clear() override
649     {
650         CacheBase::Clear();
651         types_.clear();
652         names_.clear();
653     }
654 
655 private:
656     std::deque<DataIndex> types_ = {};
657     std::deque<DataIndex> names_ = {};
658 };
659 class DataType : public CacheBase {
660 public:
661     size_t AppendNewDataType(BaseDataType dataType, DataIndex dataDescIndex);
662     const std::deque<BaseDataType>& DataTypes() const;
663     const std::deque<DataIndex>& DataDesc() const;
Clear()664     void Clear() override
665     {
666         CacheBase::Clear();
667         dataTypes_.clear();
668         descs_.clear();
669     }
670 
671 private:
672     std::deque<BaseDataType> dataTypes_ = {};
673     std::deque<DataIndex> descs_ = {};
674 };
675 class LogInfo : public CacheBase {
676 public:
677     size_t AppendNewLogInfo(uint64_t seq,
678                             uint64_t timestamp,
679                             uint32_t pid,
680                             uint32_t tid,
681                             DataIndex level,
682                             DataIndex tag,
683                             DataIndex context,
684                             uint64_t originTs);
685     const std::deque<uint64_t>& HilogLineSeqs() const;
686     const std::deque<uint32_t>& Pids() const;
687     const std::deque<uint32_t>& Tids() const;
688     const std::deque<DataIndex>& Levels() const;
689     const std::deque<DataIndex>& Tags() const;
690     const std::deque<DataIndex>& Contexts() const;
691     const std::deque<uint64_t>& OriginTimeStamData() const;
Clear()692     void Clear() override
693     {
694         CacheBase::Clear();
695         hilogLineSeqs_.clear();
696         pids_.clear();
697         levels_.clear();
698         tags_.clear();
699         contexts_.clear();
700         originTs_.clear();
701     }
702 
703 private:
704     std::deque<uint64_t> hilogLineSeqs_ = {};
705     std::deque<uint32_t> pids_ = {};
706     std::deque<uint32_t> tids_ = {};
707     std::deque<DataIndex> levels_ = {};
708     std::deque<DataIndex> tags_ = {};
709     std::deque<DataIndex> contexts_ = {};
710     std::deque<uint64_t> originTs_ = {};
711 };
712 
713 class NativeHook : public CacheBase {
714 public:
715     size_t AppendNewNativeHookData(uint64_t callChainId,
716                                    uint32_t ipid,
717                                    uint32_t itid,
718                                    std::string eventType,
719                                    DataIndex subType,
720                                    uint64_t timestamp,
721                                    uint64_t endTimestamp,
722                                    uint64_t duration,
723                                    uint64_t addr,
724                                    int64_t memSize,
725                                    int64_t allMemSize);
726     void UpdateHeapDuration(size_t row, uint64_t endTimestamp);
727     void UpdateCurrentSizeDur(size_t row, uint64_t timeStamp);
728     void UpdateMemMapSubType();
729     void UpdateAddrToMemMapSubType(uint64_t addr, int64_t size, uint64_t tagId);
730     void UpdateLastCallerPathIndexs(std::map<uint64_t, uint64_t>& callIdToLasLibId);
731     const std::deque<uint64_t>& CallChainIds() const;
732     const std::deque<uint32_t>& Ipids() const;
733     const std::deque<uint32_t>& Itids() const;
734     const std::deque<std::string>& EventTypes() const;
735     const std::deque<DataIndex>& SubTypes() const;
736     const std::deque<uint64_t>& EndTimeStamps() const;
737     const std::deque<uint64_t>& Durations() const;
738     const std::deque<uint64_t>& Addrs() const;
739     const std::deque<int64_t>& MemSizes() const;
740     const std::deque<int64_t>& AllMemSizes() const;
741     const std::deque<uint64_t>& CurrentSizeDurs() const;
742     const std::deque<uint64_t>& LastCallerPathIndexs() const;
Clear()743     void Clear() override
744     {
745         CacheBase::Clear();
746         callChainIds_.clear();
747         ipids_.clear();
748         itids_.clear();
749         eventTypes_.clear();
750         subTypes_.clear();
751         endTimestamps_.clear();
752         durations_.clear();
753         addrs_.clear();
754         memSizes_.clear();
755         allMemSizes_.clear();
756         currentSizeDurs_.clear();
757         lastCallerPathIndexs_.clear();
758     }
759 
760 private:
761     std::deque<uint64_t> callChainIds_ = {};
762     std::deque<uint32_t> ipids_ = {};
763     std::deque<uint32_t> itids_ = {};
764     std::deque<std::string> eventTypes_ = {};
765     std::deque<DataIndex> subTypes_ = {};
766     std::deque<uint64_t> endTimestamps_ = {};
767     std::deque<uint64_t> durations_ = {};
768     std::deque<uint64_t> addrs_ = {};
769     std::deque<int64_t> memSizes_ = {};
770     std::deque<int64_t> allMemSizes_ = {};
771     std::deque<uint64_t> currentSizeDurs_ = {};
772     std::deque<uint64_t> lastCallerPathIndexs_ = {};
773     DoubleMap<uint64_t, int64_t, uint64_t> addrToMmapTag_ = INVALID_UINT64;
774     int64_t countHeapSizes_ = 0;
775     int64_t countMmapSizes_ = 0;
776     const std::string ALLOC_EVET = "AllocEvent";
777     const std::string FREE_EVENT = "FreeEvent";
778     const std::string MMAP_EVENT = "MmapEvent";
779     const std::string MUNMAP_EVENT = "MunmapEvent";
780 };
781 
782 class NativeHookFrame {
783 public:
784     size_t AppendNewNativeHookFrame(uint64_t callChainId,
785                                     uint64_t depth,
786                                     uint64_t ip,
787                                     uint64_t sp,
788                                     DataIndex symbolName,
789                                     DataIndex filePath,
790                                     uint64_t offset,
791                                     uint64_t symbolOffset);
792     void UpdateSymbolIdToNameMap(uint64_t originSymbolId, uint64_t symbolId);
793     void UpdateSymbolId();
794     void UpdateFileId(std::map<uint32_t, uint64_t>& filePathIdToFilePathName);
795     void GetCallIdToLastLibId(const std::set<DataIndex>& invalidLibs,
796                               std::map<uint64_t, uint64_t>& callIdToLastCallerPathIndex);
797     const std::deque<uint64_t>& CallChainIds() const;
798     const std::deque<uint64_t>& Depths() const;
799     const std::deque<uint64_t>& Ips() const;
800     const std::deque<uint64_t>& Sps() const;
801     const std::deque<DataIndex>& SymbolNames() const;
802     const std::deque<DataIndex>& FilePaths() const;
803     const std::deque<uint64_t>& Offsets() const;
804     const std::deque<uint64_t>& SymbolOffsets() const;
Size()805     size_t Size() const
806     {
807         return callChainIds_.size();
808     }
Clear()809     void Clear()
810     {
811         callChainIds_.clear();
812         depths_.clear();
813         ips_.clear();
814         sps_.clear();
815         symbolNames_.clear();
816         filePaths_.clear();
817         offsets_.clear();
818         symbolOffsets_.clear();
819     }
820 
821 private:
822     std::deque<uint64_t> callChainIds_ = {};
823     std::deque<uint64_t> depths_ = {};
824     std::deque<uint64_t> ips_ = {};
825     std::deque<uint64_t> sps_ = {};
826     std::deque<DataIndex> symbolNames_ = {};
827     std::deque<DataIndex> filePaths_ = {};
828     std::deque<uint64_t> offsets_ = {};
829     std::deque<uint64_t> symbolOffsets_ = {};
830     std::map<uint32_t, uint64_t> symbolIdToSymbolName_ = {};
831     DataIndex libcFilePathIndex_ = INVALID_UINT64;
832     DataIndex muslFilePathIndex_ = INVALID_UINT64;
833 };
834 
835 class Hidump : public CacheBase {
836 public:
837     size_t AppendNewHidumpInfo(uint64_t timestamp, uint32_t fps);
838     const std::deque<uint32_t>& Fpss() const;
839 
840 private:
841     std::deque<uint32_t> fpss_ = {};
842 };
843 
844 class PerfCallChain : public CacheBase {
845 public:
846     size_t AppendNewPerfCallChain(uint64_t sampleId,
847                                   uint64_t callChainId,
848                                   uint64_t vaddrInFile,
849                                   uint64_t fileId,
850                                   uint64_t symbolId);
851     const std::deque<uint64_t>& SampleIds() const;
852     const std::deque<uint64_t>& CallChainIds() const;
853     const std::deque<uint64_t>& VaddrInFiles() const;
854     const std::deque<uint64_t>& FileIds() const;
855     const std::deque<uint64_t>& SymbolIds() const;
856     const std::deque<std::string>& Names() const;
857     void SetName(uint64_t index, const std::string& name);
858 
859 private:
860     std::deque<uint64_t> sampleIds_ = {};
861     std::deque<uint64_t> callChainIds_ = {};
862     std::deque<uint64_t> vaddrInFiles_ = {};
863     std::deque<uint64_t> fileIds_ = {};
864     std::deque<uint64_t> symbolIds_ = {};
865     std::deque<std::string> names_ = {};
866 };
867 
868 class PerfFiles : public CacheBase {
869 public:
870     size_t AppendNewPerfFiles(uint64_t fileIds, uint32_t serial, DataIndex symbols, DataIndex filePath);
871     const std::deque<uint64_t>& FileIds() const;
872     const std::deque<DataIndex>& Symbols() const;
873     const std::deque<DataIndex>& FilePaths() const;
874     const std::deque<uint32_t>& Serials() const;
875 
876 private:
877     std::deque<uint64_t> fileIds_ = {};
878     std::deque<uint32_t> serials_ = {};
879     std::deque<DataIndex> symbols_ = {};
880     std::deque<DataIndex> filePaths_ = {};
881 };
882 
883 class PerfSample : public CacheBase {
884 public:
885     size_t AppendNewPerfSample(uint64_t sampleId,
886                                uint64_t timestamp,
887                                uint64_t tid,
888                                uint64_t eventCount,
889                                uint64_t eventTypeId,
890                                uint64_t timestampTrace,
891                                uint64_t cpuId,
892                                uint64_t threadState);
893     const std::deque<uint64_t>& SampleIds() const;
894     const std::deque<uint64_t>& Tids() const;
895     const std::deque<uint64_t>& EventCounts() const;
896     const std::deque<uint64_t>& EventTypeIds() const;
897     const std::deque<uint64_t>& TimestampTraces() const;
898     const std::deque<uint64_t>& CpuIds() const;
899     const std::deque<DataIndex>& ThreadStates() const;
900 private:
901     std::deque<uint64_t> sampleIds_ = {};
902     std::deque<uint64_t> tids_ = {};
903     std::deque<uint64_t> eventCounts_ = {};
904     std::deque<uint64_t> eventTypeIds_ = {};
905     std::deque<uint64_t> timestampTraces_ = {};
906     std::deque<uint64_t> cpuIds_ = {};
907     std::deque<DataIndex> threadStates_ = {};
908 };
909 
910 class PerfThread : public CacheBase {
911 public:
912     size_t AppendNewPerfThread(uint64_t pid, uint64_t tid, DataIndex threadName);
913     const std::deque<uint64_t>& Pids() const;
914     const std::deque<uint64_t>& Tids() const;
915     const std::deque<DataIndex>& ThreadNames() const;
916 private:
917     std::deque<uint64_t> tids_ = {};
918     std::deque<uint64_t> pids_ = {};
919     std::deque<DataIndex> threadNames_ = {};
920 };
921 
922 class PerfReport : public CacheBase {
923 public:
924     size_t AppendNewPerfReport(DataIndex type, DataIndex value);
925     const std::deque<DataIndex>& Types() const;
926     const std::deque<DataIndex>& Values() const;
927 private:
928     std::deque<DataIndex> types_ = {};
929     std::deque<DataIndex> values_ = {};
930 };
931 class StatAndInfo {
932 public:
933     StatAndInfo();
934     ~StatAndInfo() = default;
935     void IncreaseStat(SupportedTraceEventType eventType, StatType type);
936     const uint32_t& GetValue(SupportedTraceEventType eventType, StatType type) const;
937     const std::string& GetEvent(SupportedTraceEventType eventType) const;
938     const std::string& GetStat(StatType type) const;
939     const std::string& GetSeverityDesc(SupportedTraceEventType eventType, StatType type) const;
940     const StatSeverityLevel& GetSeverity(SupportedTraceEventType eventType, StatType type) const;
941     std::map<BuiltinClocks, std::string> clockid2ClockNameMap_ = {};
942 private:
943     uint32_t statCount_[TRACE_EVENT_MAX][STAT_EVENT_MAX];
944     std::string event_[TRACE_EVENT_MAX];
945     std::string stat_[STAT_EVENT_MAX];
946     std::string statSeverityDesc_[TRACE_EVENT_MAX][STAT_EVENT_MAX];
947     StatSeverityLevel statSeverity_[TRACE_EVENT_MAX][STAT_EVENT_MAX];
948     TraceStreamerConfig config_{};
949 };
950 class SymbolsData {
951 public:
952     SymbolsData() = default;
953     ~SymbolsData() = default;
954     uint64_t Size() const;
955     void InsertSymbol(const DataIndex& name, const uint64_t& addr);
956     const std::deque<DataIndex>& GetConstFuncNames() const;
957     const std::deque<uint64_t>& GetConstAddrs() const;
Clear()958     void Clear()
959     {
960         addrs_.clear();
961         funcName_.clear();
962     }
963 
964 private:
965     std::deque<uint64_t> addrs_ = {};
966     std::deque<DataIndex> funcName_ = {};
967 };
968 class DiskIOData : public CacheBase {
969 public:
970     DiskIOData() = default;
971     ~DiskIOData() = default;
972     void AppendNewData(uint64_t ts,
973                        uint64_t dur,
974                        uint64_t rd,
975                        uint64_t wr,
976                        uint64_t rdPerSec,
977                        uint64_t wrPerSec,
978                        double rdCountPerSec,
979                        double wrCountPerSec,
980                        uint64_t rdCount,
981                        uint64_t wrCount);
982     const std::deque<uint64_t>& Durs() const;
983     const std::deque<uint64_t>& RdDatas() const;
984     const std::deque<uint64_t>& WrDatas() const;
985     const std::deque<double>& RdSpeedDatas() const;
986     const std::deque<double>& WrSpeedDatas() const;
987     const std::deque<double>& RdCountPerSecDatas() const;
988     const std::deque<double>& WrCountPerSecDatas() const;
989     const std::deque<uint64_t>& RdCountDatas() const;
990     const std::deque<uint64_t>& WrCountDatas() const;
991 
992 private:
993     std::deque<uint64_t> durs_ = {};
994     std::deque<uint64_t> rdDatas_ = {};
995     std::deque<uint64_t> wrDatas_ = {};
996     std::deque<double> wrPerSec_ = {};
997     std::deque<double> rdPerSec_ = {};
998     std::deque<double> wrCountPerSec_ = {};
999     std::deque<double> rdCountPerSec_ = {};
1000     std::deque<uint64_t> rdCountDatas_ = {};
1001     std::deque<uint64_t> wrCountDatas_ = {};
1002 };
1003 class MetaData {
1004 public:
1005     MetaData();
1006     ~MetaData() = default;
1007     void SetTraceType(const std::string& traceType);
1008     void SetSourceFileName(const std::string& fileName);
1009     void SetOutputFileName(const std::string& fileName);
1010     void SetParserToolVersion(const std::string& version);
1011     void SetParserToolPublishDateTime(const std::string& datetime);
1012     void SetTraceDataSize(uint64_t dataSize);
1013     void SetTraceDuration(uint64_t dur);
1014     const std::string& Value(uint64_t row) const;
1015     const std::string& Name(uint64_t row) const;
Clear()1016     void Clear()
1017     {
1018         columnNames_.clear();
1019         values_.clear();
1020     }
1021 
1022 private:
1023     const std::string METADATA_ITEM_DATASIZE_COLNAME = "datasize";
1024     const std::string METADATA_ITEM_PARSETOOL_NAME_COLNAME = "parse_tool";
1025     const std::string METADATA_ITEM_PARSERTOOL_VERSION_COLNAME = "tool_version";
1026     const std::string METADATA_ITEM_PARSERTOOL_PUBLISH_DATETIME_COLNAME = "tool_publish_time";
1027     const std::string METADATA_ITEM_SOURCE_FILENAME_COLNAME = "source_name";
1028     const std::string METADATA_ITEM_OUTPUT_FILENAME_COLNAME = "output_name";
1029     const std::string METADATA_ITEM_PARSERTIME_COLNAME = "runtime";
1030     const std::string METADATA_ITEM_TRACE_DURATION_COLNAME = "trace_duration";
1031     const std::string METADATA_ITEM_SOURCE_DATETYPE_COLNAME = "source_type";
1032 
1033     std::deque<std::string> columnNames_ = {};
1034     std::deque<std::string> values_ = {};
1035 };
1036 class DataDict {
1037 public:
Size()1038     size_t Size() const
1039     {
1040         return dataDict_.size();
1041     }
1042     DataIndex GetStringIndex(std::string_view str);
1043     DataIndex GetStringIndexNoWrite(std::string_view str) const;
GetDataFromDict(DataIndex id)1044     const std::string& GetDataFromDict(DataIndex id) const
1045     {
1046         TS_ASSERT(id < dataDict_.size());
1047         return dataDict_[id];
1048     }
1049     void Finish();
Clear()1050     void Clear()
1051     {
1052         dataDict_.clear();
1053     }
1054 
1055 public:
1056     std::deque<std::string> dataDict_;
1057     std::unordered_map<uint64_t, DataIndex> dataDictInnerMap_;
1058 
1059 private:
1060     std::hash<std::string_view> hashFun;
1061     std::mutex mutex_;
1062 };
1063 class NetDetailData : public CacheBase {
1064 public:
1065     size_t AppendNewNetData(uint64_t newTimeStamp,
1066                             uint64_t tx,
1067                             uint64_t rx,
1068                             uint64_t dur,
1069                             double rxSpeed,
1070                             double txSpeed,
1071                             uint64_t packetIn,
1072                             double packetInSec,
1073                             uint64_t packetOut,
1074                             double packetOutSec,
1075                             const std::string& netType);
1076     const std::deque<uint64_t>& Durs() const;
1077     const std::deque<double>& RxSpeed() const;
1078     const std::deque<double>& TxSpeed() const;
1079     const std::deque<std::string>& NetTypes() const;
1080     const std::deque<uint64_t>& RxDatas() const;
1081     const std::deque<uint64_t>& TxDatas() const;
1082     const std::deque<uint64_t>& PacketIn() const;
1083     const std::deque<double>& PacketInSec() const;
1084     const std::deque<uint64_t>& PacketOut() const;
1085     const std::deque<double>& PacketOutSec() const;
Clear()1086     void Clear() override
1087     {
1088         CacheBase::Clear();
1089         durs_.clear();
1090         rxSpeeds_.clear();
1091         txSpeeds_.clear();
1092         netTypes_.clear();
1093         packetIn_.clear();
1094         packetInSec_.clear();
1095         packetOut_.clear();
1096         packetOutSec_.clear();
1097     }
1098 
1099 private:
1100     std::deque<uint64_t> rxs_ = {};
1101     std::deque<uint64_t> txs_ = {};
1102     std::deque<uint64_t> durs_ = {};
1103     std::deque<double> rxSpeeds_ = {};
1104     std::deque<double> txSpeeds_ = {};
1105     std::deque<uint64_t> packetIn_ = {};
1106     std::deque<double> packetInSec_ = {};
1107     std::deque<uint64_t> packetOut_ = {};
1108     std::deque<double> packetOutSec_ = {};
1109     std::deque<std::string> netTypes_ = {};
1110 };
1111 class LiveProcessDetailData : public CacheBase {
1112 public:
1113     size_t AppendNewData(uint64_t newTimeStamp,
1114                          uint64_t dur,
1115                          int32_t processID,
1116                          std::string processName,
1117                          int32_t parentProcessID,
1118                          int32_t uid,
1119                          std::string userName,
1120                          double cpuUsage,
1121                          int32_t pssInfo,
1122                          uint64_t cpuTime,
1123                          int32_t threads,
1124                          int64_t diskWrites,
1125                          int64_t diskReads);
1126     const std::deque<uint64_t>& Durs() const;
1127     const std::deque<int32_t>& ProcessID() const;
1128     const std::deque<std::string>& ProcessName() const;
1129     const std::deque<int32_t>& ParentProcessID() const;
1130     const std::deque<int32_t>& Uid() const;
1131     const std::deque<std::string>& UserName() const;
1132     const std::deque<double>& CpuUsage() const;
1133     const std::deque<int32_t>& PssInfo() const;
1134     const std::deque<int32_t>& Threads() const;
1135     const std::deque<int64_t>& DiskWrites() const;
1136     const std::deque<int64_t>& DiskReads() const;
1137     const std::deque<uint64_t>& CpuTimes() const;
Clear()1138     void Clear() override
1139     {
1140         CacheBase::Clear();
1141         durs_.clear();
1142         processID_.clear();
1143         processName_.clear();
1144         parentProcessID_.clear();
1145         uid_.clear();
1146         userName_.clear();
1147         cpuUsage_.clear();
1148         pssInfo_.clear();
1149         threads_.clear();
1150         diskWrites_.clear();
1151         diskReads_.clear();
1152     }
1153 
1154 private:
1155     std::deque<uint64_t> durs_ = {};
1156     std::deque<int32_t> processID_ = {};
1157     std::deque<std::string> processName_ = {};
1158     std::deque<int32_t> parentProcessID_ = {};
1159     std::deque<int32_t> uid_ = {};
1160     std::deque<std::string> userName_ = {};
1161     std::deque<double> cpuUsage_ = {};
1162     std::deque<int32_t> pssInfo_ = {};
1163     std::deque<int32_t> threads_ = {};
1164     std::deque<int64_t> diskWrites_ = {};
1165     std::deque<int64_t> diskReads_ = {};
1166     std::deque<uint64_t> cpuTimes_ = {};
1167 };
1168 class CpuUsageDetailData : public CacheBase {
1169 public:
1170     size_t AppendNewData(uint64_t newTimeStamp,
1171                          uint64_t dur,
1172                          double totalLoad,
1173                          double userLoad,
1174                          double systemLoad,
1175                          int64_t threads);
1176     const std::deque<uint64_t>& Durs() const;
1177     const std::deque<double>& TotalLoad() const;
1178     const std::deque<double>& UserLoad() const;
1179     const std::deque<double>& SystemLoad() const;
1180     const std::deque<int64_t>& Threads() const;
Clear()1181     void Clear() override
1182     {
1183         CacheBase::Clear();
1184         durs_.clear();
1185         totalLoad_.clear();
1186         userLoad_.clear();
1187         systemLoad_.clear();
1188         threads_.clear();
1189     }
1190 
1191 private:
1192     std::deque<uint64_t> durs_ = {};
1193     std::deque<double> totalLoad_ = {};
1194     std::deque<double> userLoad_ = {};
1195     std::deque<double> systemLoad_ = {};
1196     std::deque<int64_t> threads_ = {};
1197 };
1198 class FileSystemSample : public CacheBase {
1199 public:
1200     size_t AppendNewData(uint64_t callChainId,
1201                          uint16_t type,
1202                          uint32_t ipid,
1203                          uint32_t itid,
1204                          uint64_t startTs,
1205                          uint64_t endTs,
1206                          uint64_t dur,
1207                          DataIndex returnValue,
1208                          DataIndex errorCode,
1209                          size_t size,
1210                          int32_t fd,
1211                          DataIndex fileId,
1212                          DataIndex firstArgument,
1213                          DataIndex secondArgument,
1214                          DataIndex thirdArgument,
1215                          DataIndex fourthArgument);
1216     const std::deque<uint64_t>& CallChainIds() const;
1217     const std::deque<uint16_t>& Types() const;
1218     const std::deque<uint32_t>& Ipids() const;
1219     const std::deque<uint32_t>& Itids() const;
1220     const std::deque<uint64_t>& StartTs() const;
1221     const std::deque<uint64_t>& EndTs() const;
1222     const std::deque<uint64_t>& Durs() const;
1223     const std::deque<DataIndex>& ReturnValues() const;
1224     const std::deque<DataIndex>& ErrorCodes() const;
1225     const std::deque<int32_t>& Fds() const;
1226     const std::deque<DataIndex>& FileIds() const;
1227     const std::deque<size_t>& Sizes() const;
1228     const std::deque<DataIndex>& FirstArguments() const;
1229     const std::deque<DataIndex>& SecondArguments() const;
1230     const std::deque<DataIndex>& ThirdArguments() const;
1231     const std::deque<DataIndex>& FourthArguments() const;
Clear()1232     void Clear() override
1233     {
1234         CacheBase::Clear();
1235         callChainIds_.clear();
1236         types_.clear();
1237         ipids_.clear();
1238         itids_.clear();
1239         startTs_.clear();
1240         endTs_.clear();
1241         durs_.clear();
1242         returnValues_.clear();
1243         errorCodes_.clear();
1244         fds_.clear();
1245         Sizes_.clear();
1246         firstArguments_.clear();
1247         secondArguments_.clear();
1248         thirdArguments_.clear();
1249         fourthArguments_.clear();
1250     }
1251 
1252 private:
1253     std::deque<uint64_t> callChainIds_ = {};
1254     std::deque<uint16_t> types_ = {};
1255     std::deque<uint32_t> ipids_ = {};
1256     std::deque<uint32_t> itids_ = {};
1257     std::deque<uint64_t> startTs_ = {};
1258     std::deque<uint64_t> endTs_ = {};
1259     std::deque<uint64_t> durs_ = {};
1260     std::deque<DataIndex> returnValues_ = {};
1261     std::deque<DataIndex> errorCodes_ = {};
1262     std::deque<int32_t> fds_ = {};
1263     std::deque<DataIndex> fileIds_ = {};
1264     std::deque<size_t> Sizes_ = {};
1265     std::deque<DataIndex> firstArguments_ = {};
1266     std::deque<DataIndex> secondArguments_ = {};
1267     std::deque<DataIndex> thirdArguments_ = {};
1268     std::deque<DataIndex> fourthArguments_ = {};
1269 };
1270 class EbpfCallStackData : public CacheBase {
1271 public:
1272     size_t AppendNewData(uint64_t callChainId,
1273                          uint32_t depth,
1274                          uint64_t ip,
1275                          uint64_t symbolId,
1276                          uint64_t filePathId);
1277     const std::deque<uint64_t>& CallChainIds() const;
1278     const std::deque<uint32_t>& Depths() const;
1279     const std::deque<uint64_t>& Ips() const;
1280     const std::deque<uint64_t>& SymbolIds() const;
1281     const std::deque<uint64_t>& FilePathIds() const;
Clear()1282     void Clear() override
1283     {
1284         CacheBase::Clear();
1285         callChainIds_.clear();
1286         depths_.clear();
1287         symbolIds_.clear();
1288         filePathIds_.clear();
1289     }
1290 
1291 private:
1292     std::deque<uint64_t> callChainIds_ = {};
1293     std::deque<uint32_t> depths_ = {};
1294     std::deque<uint64_t> ips_ = {};
1295     std::deque<uint64_t> symbolIds_ = {};
1296     std::deque<uint64_t> filePathIds_ = {};
1297 };
1298 class PagedMemorySampleData : public CacheBase {
1299 public:
1300     size_t AppendNewData(uint64_t callChainId,
1301                          uint16_t type,
1302                          uint32_t ipid,
1303                          uint64_t startTs,
1304                          uint64_t endTs,
1305                          uint64_t dur,
1306                          size_t size,
1307                          DataIndex addr,
1308                          uint32_t itid);
1309     const std::deque<uint64_t>& CallChainIds() const;
1310     const std::deque<uint16_t>& Types() const;
1311     const std::deque<uint32_t>& Ipids() const;
1312     const std::deque<uint64_t>& StartTs() const;
1313     const std::deque<uint64_t>& EndTs() const;
1314     const std::deque<uint64_t>& Durs() const;
1315     const std::deque<size_t>& Sizes() const;
1316     const std::deque<DataIndex>& Addr() const;
1317     const std::deque<uint32_t>& Itids() const;
Clear()1318     void Clear() override
1319     {
1320         CacheBase::Clear();
1321         callChainIds_.clear();
1322         types_.clear();
1323         ipids_.clear();
1324         startTs_.clear();
1325         endTs_.clear();
1326         durs_.clear();
1327         Sizes_.clear();
1328         addrs_.clear();
1329         itids_.clear();
1330     }
1331 
1332 private:
1333     std::deque<uint64_t> callChainIds_ = {};
1334     std::deque<uint16_t> types_ = {};
1335     std::deque<uint32_t> ipids_ = {};
1336     std::deque<uint64_t> startTs_ = {};
1337     std::deque<uint64_t> endTs_ = {};
1338     std::deque<uint64_t> durs_ = {};
1339     std::deque<size_t> Sizes_ = {};
1340     std::deque<DataIndex> addrs_ = {};
1341     std::deque<uint32_t> itids_ = {};
1342 };
1343 #if WITH_EBPF_HELP
1344 class EbpfProcessMaps : public CacheBase {
1345 public:
1346     size_t AppendNewData(uint64_t start,
1347                          uint64_t end,
1348                          uint32_t offset,
1349                          uint32_t pid,
1350                          uint32_t fileNameLen,
1351                          uint64_t fileNameIndex);
1352     const std::deque<uint64_t>& Starts() const;
1353     const std::deque<uint64_t>& Ends() const;
1354     const std::deque<uint32_t>& Offsets() const;
1355     const std::deque<uint32_t>& Pids() const;
1356     const std::deque<uint32_t>& FileNameLens() const;
1357     const std::deque<uint64_t>& FileNameIndexs() const;
Clear()1358     void Clear() override
1359     {
1360         CacheBase::Clear();
1361         starts_.clear();
1362         ends_.clear();
1363         offsets_.clear();
1364         pids_.clear();
1365         fileNameLens_.clear();
1366         fileNameIndexs_.clear();
1367     }
1368 private:
1369     std::deque<uint64_t> starts_ = {};
1370     std::deque<uint64_t> ends_ = {};
1371     std::deque<uint32_t> offsets_ = {};
1372     std::deque<uint32_t> pids_ = {};
1373     std::deque<uint32_t> fileNameLens_ = {};
1374     std::deque<uint64_t> fileNameIndexs_ = {};
1375 };
1376 
1377 class EbpfElf : public CacheBase {
1378 public:
1379     size_t AppendNewData(uint64_t elfId,
1380                          uint64_t textVaddr,
1381                          uint32_t textOffset,
1382                          uint32_t strTabLen,
1383                          uint32_t symTabLen,
1384                          uint32_t fileNameLen,
1385                          uint32_t symEntLen,
1386                          uint64_t fileNameIndex);
1387     const std::deque<uint64_t>& ElfIds() const;
1388     const std::deque<uint64_t>& TextVaddrs() const;
1389     const std::deque<uint32_t>& TextOffsets() const;
1390     const std::deque<uint32_t>& StrTabLens() const;
1391     const std::deque<uint32_t>& SymTabLens() const;
1392     const std::deque<uint32_t>& FileNameLens() const;
1393     const std::deque<uint32_t>& SymEntLens() const;
1394     const std::deque<uint64_t>& FileNameIndexs() const;
1395 
Clear()1396     void Clear() override
1397     {
1398         CacheBase::Clear();
1399         elfIds_.clear();
1400         textVaddrs_.clear();
1401         textOffsets_.clear();
1402         strTabLens_.clear();
1403         symTabLens_.clear();
1404         fileNameLens_.clear();
1405         symEntLens_.clear();
1406         fileNameIndexs_.clear();
1407     }
1408 
1409 private:
1410     std::deque<uint64_t> elfIds_ = {};
1411     std::deque<uint64_t> textVaddrs_ = {};
1412     std::deque<uint32_t> textOffsets_ = {};
1413     std::deque<uint32_t> strTabLens_ = {};
1414     std::deque<uint32_t> symTabLens_ = {};
1415     std::deque<uint32_t> fileNameLens_ = {};
1416     std::deque<uint32_t> symEntLens_ = {};
1417     std::deque<uint64_t> fileNameIndexs_ = {};
1418 };
1419 
1420 class EbpfElfSymbol : public CacheBase {
1421 public:
1422     size_t AppendNewData(uint64_t elfId,
1423                          uint32_t stName,
1424                          uint64_t stValue,
1425                          uint64_t stSize);
1426     const std::deque<uint64_t>& ElfIds() const;
1427     const std::deque<uint32_t>& StNames() const;
1428     const std::deque<uint64_t>& StValues() const;
1429     const std::deque<uint64_t>& StSizes() const;
1430 
Clear()1431     void Clear() override
1432     {
1433         CacheBase::Clear();
1434         elfIds_.clear();
1435         stNames_.clear();
1436         stValues_.clear();
1437         stSizes_.clear();
1438     }
1439 
1440 private:
1441     std::deque<uint64_t> elfIds_ = {};
1442     std::deque<uint32_t> stNames_ = {};
1443     std::deque<uint64_t> stValues_ = {};
1444     std::deque<uint64_t> stSizes_ = {};
1445 };
1446 #endif
1447 class AppNames : public CacheBase {
1448 public:
1449     uint32_t AppendAppName(uint8_t flags, DataIndex eventSource, DataIndex appName);
1450     const std::deque<uint8_t>& Falgs() const;
1451     const std::deque<DataIndex>& EventSourceId() const;
1452     const std::deque<DataIndex>& AppName() const;
Clear()1453     void Clear() override
1454     {
1455         CacheBase::Clear();
1456         flags_.clear();
1457         appNames_.clear();
1458         keyNames_.clear();
1459     }
1460 private:
1461     std::deque<uint8_t> flags_ = {};
1462     std::deque<DataIndex> appNames_ = {};
1463     std::deque<DataIndex> keyNames_ = {};
1464     uint32_t rowCount_ = 0;
1465 };
1466 class SysEventMeasureData : public CacheBase {
1467 public:
1468     void AppendData(uint64_t serial,
1469                     uint64_t ts,
1470                     uint32_t nameId,
1471                     uint32_t keyId,
1472                     int32_t type,
1473                     double numericValue,
1474                     DataIndex stringValue);
1475     const std::deque<uint64_t>& Serial() const;
1476     const std::deque<uint64_t>& Ts() const;
1477     const std::deque<uint32_t>& NameFilterId() const;
1478     const std::deque<uint32_t>& AppKeyFilterId() const;
1479     const std::deque<int32_t>& Type() const;
1480     const std::deque<double>& NumValue() const;
1481     const std::deque<DataIndex>& StringValue() const;
Clear()1482     void Clear() override
1483     {
1484         CacheBase::Clear();
1485         serial_.clear();
1486         ts_.clear();
1487         nameFilterIds_.clear();
1488         appKeyFilterIds_.clear();
1489         types_.clear();
1490         numValues_.clear();
1491         stringValues_.clear();
1492     }
1493 private:
1494     std::deque<uint64_t> serial_ = {};
1495     std::deque<uint64_t> ts_ = {};
1496     std::deque<uint32_t> nameFilterIds_ = {};
1497     std::deque<uint32_t> appKeyFilterIds_ = {};
1498     std::deque<int32_t> types_ = {};
1499     std::deque<double> numValues_ = {};
1500     std::deque<DataIndex> stringValues_ = {};
1501     uint32_t rowCount_ = 0;
1502 };
1503 class DeviceStateData : public CacheBase {
1504 public:
1505     void AppendNewData(int32_t brightness,
1506                        int32_t btState,
1507                        int32_t location,
1508                        int32_t wifi,
1509                        int32_t streamDefault,
1510                        int32_t voiceCall,
1511                        int32_t music,
1512                        int32_t streamRing,
1513                        int32_t media,
1514                        int32_t voiceAssistant,
1515                        int32_t system,
1516                        int32_t alarm,
1517                        int32_t notification,
1518                        int32_t btSco,
1519                        int32_t enforcedAudible,
1520                        int32_t streamDtmf,
1521                        int32_t streamTts,
1522                        int32_t accessibility,
1523                        int32_t recording,
1524                        int32_t streamAll);
1525     const std::deque<int32_t>& Brightness() const;
1526     const std::deque<int32_t>& BtState() const;
1527     const std::deque<int32_t>& Location() const;
1528     const std::deque<int32_t>& Wifi() const;
1529     const std::deque<int32_t>& StreamDefault() const;
1530     const std::deque<int32_t>& VoiceCall() const;
1531     const std::deque<int32_t>& Music() const;
1532     const std::deque<int32_t>& StreamRing() const;
1533     const std::deque<int32_t>& Media() const;
1534     const std::deque<int32_t>& VoiceAssistant() const;
1535     const std::deque<int32_t>& System() const;
1536     const std::deque<int32_t>& Alarm() const;
1537     const std::deque<int32_t>& Notification() const;
1538     const std::deque<int32_t>& BtSco() const;
1539     const std::deque<int32_t>& EnforcedAudible() const;
1540     const std::deque<int32_t>& StreamDtmf() const;
1541     const std::deque<int32_t>& StreamTts() const;
1542     const std::deque<int32_t>& Accessibility() const;
1543     const std::deque<int32_t>& Recording() const;
1544     const std::deque<int32_t>& StreamAll() const;
Clear()1545     void Clear() override
1546     {
1547         CacheBase::Clear();
1548         brightness_.clear();
1549         btStates_.clear();
1550         locations_.clear();
1551         wifis_.clear();
1552         streamDefaults_.clear();
1553         voiceCalls_.clear();
1554         musics_.clear();
1555         streamRings_.clear();
1556         medias_.clear();
1557         voiceAssistants_.clear();
1558         systems_.clear();
1559         alarms_.clear();
1560         notifications_.clear();
1561         btScos_.clear();
1562         enforcedAudibles_.clear();
1563         streamDtmfs_.clear();
1564         streamTts_.clear();
1565         accessibilitys_.clear();
1566         recordings_.clear();
1567         streamAlls_.clear();
1568     }
1569 private:
1570     std::deque<uint32_t> stringValues_ = {};
1571     std::deque<int32_t> brightness_ = {};
1572     std::deque<int32_t> btStates_ = {};
1573     std::deque<int32_t> locations_ = {};
1574     std::deque<int32_t> wifis_ = {};
1575     std::deque<int32_t> streamDefaults_ = {};
1576     std::deque<int32_t> voiceCalls_ = {};
1577     std::deque<int32_t> musics_ = {};
1578     std::deque<int32_t> streamRings_ = {};
1579     std::deque<int32_t> medias_ = {};
1580     std::deque<int32_t> voiceAssistants_ = {};
1581     std::deque<int32_t> systems_ = {};
1582     std::deque<int32_t> alarms_ = {};
1583     std::deque<int32_t> notifications_ = {};
1584     std::deque<int32_t> btScos_ = {};
1585     std::deque<int32_t> enforcedAudibles_ = {};
1586     std::deque<int32_t> streamDtmfs_ = {};
1587     std::deque<int32_t> streamTts_ = {};
1588     std::deque<int32_t> accessibilitys_ = {};
1589     std::deque<int32_t> recordings_ = {};
1590     std::deque<int32_t> streamAlls_ = {};
1591     uint32_t rowCounts_ = 0;
1592 };
1593 class SmapsData : public CacheBase {
1594 public:
1595     void AppendNewData(uint64_t timeStamp,
1596                        std::string startAddr,
1597                        std::string endAddr,
1598                        uint64_t dirty,
1599                        uint64_t swapper,
1600                        uint64_t rss,
1601                        uint64_t pss,
1602                        uint64_t size,
1603                        double reside,
1604                        DataIndex protectionId,
1605                        DataIndex pathId);
1606     const std::deque<uint64_t>& Id() const;
1607     const std::deque<uint64_t>& TimeStamps() const;
1608     const std::deque<std::string>& StartAddrs() const;
1609     const std::deque<std::string>& EndAddrs() const;
1610     const std::deque<uint64_t>& Dirtys() const;
1611     const std::deque<uint64_t>& Swappers() const;
1612     const std::deque<uint64_t>& Rss() const;
1613     const std::deque<uint64_t>& Pss() const;
1614     const std::deque<uint64_t>& Sizes() const;
1615     const std::deque<double>& Resides() const;
1616     const std::deque<DataIndex>& ProtectionIds() const;
1617     const std::deque<DataIndex>& PathIds() const;
Clear()1618     void Clear() override
1619     {
1620         CacheBase::Clear();
1621         timeStamps_.clear();
1622         startAddrs_.clear();
1623         endAddrs_.clear();
1624         dirtys_.clear();
1625         swappers_.clear();
1626         rss_.clear();
1627         pss_.clear();
1628         sizes_.clear();
1629         resides_.clear();
1630         protectionIds_.clear();
1631         pathIds_.clear();
1632     }
1633 private:
1634     std::deque<uint64_t> timeStamps_ = {};
1635     std::deque<std::string> startAddrs_ = {};
1636     std::deque<std::string> endAddrs_ = {};
1637     std::deque<uint64_t> dirtys_ = {};
1638     std::deque<uint64_t> swappers_ = {};
1639     std::deque<uint64_t> rss_ = {};
1640     std::deque<uint64_t> pss_ = {};
1641     std::deque<uint64_t> sizes_ = {};
1642     std::deque<double> resides_ = {};
1643     std::deque<DataIndex> protectionIds_ = {};
1644     std::deque<DataIndex> pathIds_ = {};
1645     uint32_t rowCount_ = 0;
1646 };
1647 class BioLatencySampleData : public CacheBase {
1648 public:
1649     void AppendNewData(uint64_t callChainId,
1650                        uint64_t type,
1651                        uint64_t ipid,
1652                        uint64_t itid,
1653                        uint64_t startTs,
1654                        uint64_t endTs,
1655                        uint64_t latencyDur,
1656                        uint32_t tier,
1657                        uint64_t size,
1658                        uint64_t blockNumber,
1659                        uint64_t filePathId,
1660                        uint64_t durPer4k);
1661     const std::deque<uint64_t>& Id() const;
1662     const std::deque<uint64_t>& CallChainIds() const;
1663     const std::deque<uint64_t>& Types() const;
1664     const std::deque<uint64_t>& Ipids() const;
1665     const std::deque<uint64_t>& Itids() const;
1666     const std::deque<uint64_t>& StartTs() const;
1667     const std::deque<uint64_t>& EndTs() const;
1668     const std::deque<uint64_t>& LatencyDurs() const;
1669     const std::deque<uint32_t>& Tiers() const;
1670     const std::deque<uint64_t>& Sizes() const;
1671     const std::deque<uint64_t>& BlockNumbers() const;
1672     const std::deque<uint64_t>& FilePathIds() const;
1673     const std::deque<uint64_t>& DurPer4k() const;
Clear()1674     void Clear() override
1675     {
1676         CacheBase::Clear();
1677         callChainIds_.clear();
1678         types_.clear();
1679         ipids_.clear();
1680         itids_.clear();
1681         startTs_.clear();
1682         endTs_.clear();
1683         latencyDurs_.clear();
1684         tiers_.clear();
1685         sizes_.clear();
1686         blockNumbers_.clear();
1687         filePathIds_.clear();
1688         durPer4ks_.clear();
1689     }
1690 
1691 private:
1692     std::deque<uint64_t> callChainIds_ = {};
1693     std::deque<uint64_t> types_ = {};
1694     std::deque<uint64_t> ipids_ = {};
1695     std::deque<uint64_t> itids_ = {};
1696     std::deque<uint64_t> startTs_ = {};
1697     std::deque<uint64_t> endTs_ = {};
1698     std::deque<uint64_t> latencyDurs_ = {};
1699     std::deque<uint32_t> tiers_ = {};
1700     std::deque<uint64_t> sizes_ = {};
1701     std::deque<uint64_t> blockNumbers_ = {};
1702     std::deque<uint64_t> filePathIds_ = {};
1703     std::deque<uint64_t> durPer4ks_ = {};
1704     uint32_t rowCount_ = 0;
1705 };
1706 class ClockSnapshotData {
1707 public:
AppendNewSnapshot(uint8_t clockId,uint64_t ts,const std::string & name)1708     size_t AppendNewSnapshot(uint8_t clockId, uint64_t ts, const std::string& name)
1709     {
1710         clockIds_.emplace_back(clockId);
1711         ts_.emplace_back(ts);
1712         names_.emplace_back(name);
1713         return ts_.size();
1714     }
Size()1715     const size_t Size() const
1716     {
1717         return ts_.size();
1718     }
ClockIds()1719     const std::deque<uint8_t>& ClockIds() const
1720     {
1721         return clockIds_;
1722     }
Ts()1723     const std::deque<uint64_t>& Ts() const
1724     {
1725         return ts_;
1726     }
Names()1727     const std::deque<std::string>& Names() const
1728     {
1729         return names_;
1730     }
1731 
1732 private:
1733     std::deque<uint8_t> clockIds_ = {};
1734     std::deque<uint64_t> ts_ = {};
1735     std::deque<std::string> names_ = {};
1736 };
1737 class DataSourceClockIdData {
1738 public:
1739     DataSourceClockIdData();
AppendNewDataSourceClockId(const std::string & dataSoruceName,uint8_t clockId)1740     size_t AppendNewDataSourceClockId(const std::string& dataSoruceName, uint8_t clockId)
1741     {
1742         dataSourceNames_.emplace_back(dataSoruceName);
1743         clockIds_.emplace_back(clockId);
1744         return dataSourceNames_.size();
1745     }
Size()1746     const size_t Size() const
1747     {
1748         return dataSourceNames_.size();
1749     }
ClockIds()1750     const std::deque<uint8_t>& ClockIds() const
1751     {
1752         return clockIds_;
1753     }
Names()1754     const std::deque<std::string>& Names() const
1755     {
1756         return dataSourceNames_;
1757     }
1758     void SetDataSourceClockId(DataSourceType source, uint32_t id);
1759     void Finish();
1760 
1761 private:
1762     std::deque<std::string> dataSourceNames_ = {};
1763     std::deque<uint8_t> clockIds_ = {};
1764     std::map<DataSourceType, uint8_t> dataSource2ClockIdMap_ = {};
1765     std::map<DataSourceType, std::string> dataSource2PluginNameMap_ = {};
1766 };
1767 } // namespace TraceStdtype
1768 } // namespace SysTuning
1769 
1770 #endif // TRACE_STDTYPE_H
1771