diff --git a/ide/src/trace/component/trace/timer-shaft/SportRuler.ts b/ide/src/trace/component/trace/timer-shaft/SportRuler.ts index 38f68539c28f0b3c8c5a35080dad2b5ddcdf8d3e..601e81679d9b60d8c2cc4a9a729917377b08c9d8 100644 --- a/ide/src/trace/component/trace/timer-shaft/SportRuler.ts +++ b/ide/src/trace/component/trace/timer-shaft/SportRuler.ts @@ -225,7 +225,7 @@ export class SportRuler extends Graph { this.context2D.closePath(); } - drawRangeSelect(): void{ + private initRangeSelect() { let range = TraceRow.rangeSelectObject; this.context2D.beginPath(); if (document.querySelector('sp-application')!.dark) { @@ -255,6 +255,10 @@ export class SportRuler extends Graph { this.context2D.fillText(`${txt}`, endX + 5, this.frame.y + 20); } } + } + + drawRangeSelect(): void{ + this.initRangeSelect(); if (this.timeArray.length > 0 && TraceRow.rangeSelectObject) { // 页面可视框选区域的宽度 let rangeSelectWidth = TraceRow.rangeSelectObject!.endX! - TraceRow.rangeSelectObject!.startX!; @@ -290,41 +294,7 @@ export class SportRuler extends Graph { if (isEbpf && useIndex.includes(j)) { continue; } - const itemTime = this.timeArray[j]; - let inRange = false; - // ebpf需要考虑dur - if (this.durArray && this.durArray.length > 0) { - const dur = this.durArray[j]; - if (itemTime === this.range.endNS) { - // 如果时间点刚好和时间轴结束时间一样会导致该时间点没有计数,所以此情况需要的判断条件要多个等号 - inRange = - itemTime >= startNS + sectionTime * (i - 1) && - itemTime <= startNS + sectionTime * i && - itemTime >= this.range.startNS && - itemTime <= this.range.endNS; - } else { - // 判断时间点是否在某时间段内时,一般情况下和左边界相同算在该时间段,和右边界相同算在下一段, - inRange = - itemTime + dur >= startNS + sectionTime * (i - 1) && - itemTime < startNS + sectionTime * i && - itemTime + dur >= this.range.startNS && - itemTime < this.range.endNS; - } - } else { - if (itemTime === this.range.endNS) { - inRange = - itemTime >= startNS + sectionTime * (i - 1) && - itemTime <= startNS + sectionTime * i && - itemTime >= this.range.startNS && - itemTime <= this.range.endNS; - } else { - inRange = - itemTime >= startNS + sectionTime * (i - 1) && - itemTime < startNS + sectionTime * i && - itemTime >= this.range.startNS && - itemTime < this.range.endNS; - } - } + let inRange = this.freshInRange(j, startNS, sectionTime, i); // 如果该时间小于第一个分割点的时间,计数加1,从而算出一段时间的时间数量 if (inRange) { // nm统计模式则统计每个时间的count @@ -340,25 +310,68 @@ export class SportRuler extends Graph { continue; } } - let x = TraceRow.rangeSelectObject!.startX! + (rangeSelectWidth / section) * i; - if (i !== section) { - this.context2D.moveTo(x, this.frame.y + 22); - this.context2D.lineTo(x, this.frame.y + 22 + 5); - } - // 每一格的数量的数字宽度 - let countTextWidth = this.context2D.measureText(String(countArr[i - 1])).width; - // 文本的开始位置 = 框选的开始位置 + 格数 + (一格的宽度 - 文本的宽度) / 2 - let textY = - TraceRow.rangeSelectObject!.startX! + - (rangeSelectWidth / section) * (i - 1) + - (rangeSelectWidth / section - countTextWidth) / 2; - this.context2D.fillText(String(countArr[i - 1]), textY, this.frame.y + 22 + 12); + this.drawRangeSelectFillText(rangeSelectWidth, section, i, countArr); } } this.context2D.stroke(); this.context2D.closePath(); } + private drawRangeSelectFillText(rangeSelectWidth: number, section: number, i: number, countArr: Uint32Array){ + let x = TraceRow.rangeSelectObject!.startX! + (rangeSelectWidth / section) * i; + if (i !== section) { + this.context2D.moveTo(x, this.frame.y + 22); + this.context2D.lineTo(x, this.frame.y + 22 + 5); + } + // 每一格的数量的数字宽度 + let countTextWidth = this.context2D.measureText(String(countArr[i - 1])).width; + // 文本的开始位置 = 框选的开始位置 + 格数 + (一格的宽度 - 文本的宽度) / 2 + let textY = + TraceRow.rangeSelectObject!.startX! + + (rangeSelectWidth / section) * (i - 1) + + (rangeSelectWidth / section - countTextWidth) / 2; + this.context2D.fillText(String(countArr[i - 1]), textY, this.frame.y + 22 + 12); + } + + private freshInRange(j: number, startNS: number, sectionTime: number, i: number): boolean { + let inRange = false; + const itemTime = this.timeArray[j]; + // ebpf需要考虑dur + if (this.durArray && this.durArray.length > 0) { + const dur = this.durArray[j]; + if (itemTime === this.range.endNS) { + // 如果时间点刚好和时间轴结束时间一样会导致该时间点没有计数,所以此情况需要的判断条件要多个等号 + inRange = + itemTime >= startNS + sectionTime * (i - 1) && + itemTime <= startNS + sectionTime * i && + itemTime >= this.range.startNS && + itemTime <= this.range.endNS; + } else { + // 判断时间点是否在某时间段内时,一般情况下和左边界相同算在该时间段,和右边界相同算在下一段, + inRange = + itemTime + dur >= startNS + sectionTime * (i - 1) && + itemTime < startNS + sectionTime * i && + itemTime + dur >= this.range.startNS && + itemTime < this.range.endNS; + } + } else { + if (itemTime === this.range.endNS) { + inRange = + itemTime >= startNS + sectionTime * (i - 1) && + itemTime <= startNS + sectionTime * i && + itemTime >= this.range.startNS && + itemTime <= this.range.endNS; + } else { + inRange = + itemTime >= startNS + sectionTime * (i - 1) && + itemTime < startNS + sectionTime * i && + itemTime >= this.range.startNS && + itemTime < this.range.endNS; + } + } + return inRange; + } + drawTriangle(time: number, type: string) { if (time != null && typeof time != undefined) { let i = this.flagList.findIndex((it) => it.time == time); @@ -433,9 +446,7 @@ export class SportRuler extends Graph { } } - setSlicesMark( - startTime: number | null = null, - endTime: number | null = null, + setSlicesMark( startTime: number | null = null, endTime: number | null = null, shiftKey: boolean | null = null ): SlicesTime | null { let findSlicesTime = this.slicesTimeList.find((it) => it.startTime === startTime && it.endTime === endTime); @@ -453,8 +464,7 @@ export class SportRuler extends Graph { (this.rulerW * (startTime - this.range.startNS)) / (this.range.endNS - this.range.startNS) ); let endX = Math.round((this.rulerW * (endTime - this.range.startNS)) / (this.range.endNS - this.range.startNS)); - let color = randomRgbColor() || '#ff0000'; - this.slicesTime.color = color; + this.slicesTime.color = randomRgbColor() || '#ff0000'; let text = ''; newSlicestime = new SlicesTime( this.slicesTime.startTime || 0, @@ -463,13 +473,12 @@ export class SportRuler extends Graph { this.range.endNS, startX, endX, - color, + this.slicesTime.color, text, true ); if (!shiftKey) { this.clearTempSlicesTime(); // 清除临时对象 - // 如果没有按下shift键,则把当前slicestime对象的类型设为临时类型。 newSlicestime.type = StType.TEMP; } @@ -511,6 +520,57 @@ export class SportRuler extends Graph { this.hoverFlag.hidden = false; } + private drawSlicesTimeText(slicesTime: SlicesTime, startX: number, endX: number): number[] { + this.context2D.beginPath(); + this.context2D.strokeStyle = slicesTime.color; + this.context2D.fillStyle = slicesTime.color; + this.range.slicesTime.color = slicesTime.color; //紫色 + this.context2D.moveTo(startX + TRIWIDTH, 132); + this.context2D.lineTo(startX, 142); + this.context2D.lineTo(startX, 132); + this.context2D.lineTo(startX + TRIWIDTH, 132); + + this.context2D.lineTo(endX - TRIWIDTH, 132); + this.context2D.lineTo(endX, 132); + this.context2D.lineTo(endX, 142); + this.context2D.lineTo(endX - TRIWIDTH, 132); + this.context2D.closePath(); + slicesTime.selected && this.context2D.fill(); + this.context2D.stroke(); + this.context2D.beginPath(); + if (document.querySelector('sp-application')!.dark) { + this.context2D.strokeStyle = '#FFF'; + this.context2D.fillStyle = '#FFF'; + } else { + this.context2D.strokeStyle = '#000'; + this.context2D.fillStyle = '#000'; + } + let lineWidth = endX - startX; + let txt = ns2s((slicesTime.endTime || 0) - (slicesTime.startTime || 0)); + this.context2D.moveTo(startX, this.frame.y + 22); + this.context2D.lineTo(endX, this.frame.y + 22); + this.context2D.moveTo(startX, this.frame.y + 22 - 5); + this.context2D.lineTo(startX, this.frame.y + 22 + 5); + this.context2D.moveTo(endX, this.frame.y + 22 - 5); + this.context2D.lineTo(endX, this.frame.y + 22 + 5); + let txtWidth = this.context2D.measureText(txt).width; + this.context2D.fillStyle = '#FFF'; //为了解决文字重叠问题。在时间刻度的文字下面绘制一个小方块 + this.context2D.fillRect(startX + (lineWidth - txtWidth) / 2, this.frame.y + 10, txtWidth + 2, 10); + this.context2D.fillStyle = 'black'; + if (lineWidth > txtWidth) { + this.context2D.fillText(`${txt}`, startX + (lineWidth - txtWidth) / 2, this.frame.y + 20); + } else { + if (endX + txtWidth >= this.frame.width) { + this.context2D.fillText(`${txt}`, startX - 5 - txtWidth, this.frame.y + 20); + } else { + this.context2D.fillText(`${txt}`, endX + 5, this.frame.y + 20); + } + } + this.context2D.stroke(); + this.context2D.closePath(); + return [lineWidth, txtWidth]; + } + drawSlicesMarks(slicesTime: SlicesTime) { if ( slicesTime.startTime != null && @@ -527,57 +587,7 @@ export class SportRuler extends Graph { // 放大、缩小、左右移动之后重置小三角的x轴坐标 slicesTime.startX = startX; slicesTime.endX = endX; - - this.context2D.beginPath(); - this.context2D.strokeStyle = slicesTime.color; - this.context2D.fillStyle = slicesTime.color; - this.range.slicesTime.color = slicesTime.color; //紫色 - - this.context2D.moveTo(startX + TRIWIDTH, 132); - this.context2D.lineTo(startX, 142); - this.context2D.lineTo(startX, 132); - this.context2D.lineTo(startX + TRIWIDTH, 132); - - this.context2D.lineTo(endX - TRIWIDTH, 132); - this.context2D.lineTo(endX, 132); - this.context2D.lineTo(endX, 142); - this.context2D.lineTo(endX - TRIWIDTH, 132); - this.context2D.closePath(); - slicesTime.selected && this.context2D.fill(); - this.context2D.stroke(); - - this.context2D.beginPath(); - if (document.querySelector('sp-application')!.dark) { - this.context2D.strokeStyle = '#FFF'; - this.context2D.fillStyle = '#FFF'; - } else { - this.context2D.strokeStyle = '#000'; - this.context2D.fillStyle = '#000'; - } - let lineWidth = endX - startX; - let txt = ns2s((slicesTime.endTime || 0) - (slicesTime.startTime || 0)); - this.context2D.moveTo(startX, this.frame.y + 22); - this.context2D.lineTo(endX, this.frame.y + 22); - this.context2D.moveTo(startX, this.frame.y + 22 - 5); - this.context2D.lineTo(startX, this.frame.y + 22 + 5); - this.context2D.moveTo(endX, this.frame.y + 22 - 5); - this.context2D.lineTo(endX, this.frame.y + 22 + 5); - let txtWidth = this.context2D.measureText(txt).width; - this.context2D.fillStyle = '#FFF'; //为了解决文字重叠问题。在时间刻度的文字下面绘制一个小方块 - this.context2D.fillRect(startX + (lineWidth - txtWidth) / 2, this.frame.y + 10, txtWidth + 2, 10); - this.context2D.fillStyle = 'black'; - if (lineWidth > txtWidth) { - this.context2D.fillText(`${txt}`, startX + (lineWidth - txtWidth) / 2, this.frame.y + 20); - } else { - if (endX + txtWidth >= this.frame.width) { - this.context2D.fillText(`${txt}`, startX - 5 - txtWidth, this.frame.y + 20); - } else { - this.context2D.fillText(`${txt}`, endX + 5, this.frame.y + 20); - } - } - this.context2D.stroke(); - this.context2D.closePath(); - + let [lineWidth, txtWidth] = this.drawSlicesTimeText(slicesTime, startX, endX); // 画框选的备注文字---begin----------------- let text = slicesTime.text; if (text) { diff --git a/trace_streamer/sdk/demo_sdk/trace_data/demo_trace_data_db.cpp b/trace_streamer/sdk/demo_sdk/trace_data/demo_trace_data_db.cpp index 060613bf0dc596bc011264ab10e0844df4512e75..36dab256e4c49868769a0e987d5668b50d67fdef 100644 --- a/trace_streamer/sdk/demo_sdk/trace_data/demo_trace_data_db.cpp +++ b/trace_streamer/sdk/demo_sdk/trace_data/demo_trace_data_db.cpp @@ -201,7 +201,6 @@ int32_t DemoTraceDataDB::DemoSearchDatabase(const std::string& sql, bool print) TS_LOGE("sqlite3_prepare_v2(%s) failed: %d:%s", sql.c_str(), ret, sqlite3_errmsg(demoDb_)); return 0; } - int32_t demoColCount = sqlite3_column_count(demoStmt); if (demoColCount == 0) { TS_LOGI("sqlite3_column_count(%s) no column", sql.c_str()); @@ -214,7 +213,6 @@ int32_t DemoTraceDataDB::DemoSearchDatabase(const std::string& sql, bool print) } printf("\n"); } - while (sqlite3_step(demoStmt) == SQLITE_ROW) { demoRowCount++; for (int32_t i = 0; i < demoColCount; i++) { diff --git a/trace_streamer/src/base/index_map.h b/trace_streamer/src/base/index_map.h index 564de376dae9500083e8964b01b7802cf83c7bce..df5b9e068fe1c489f2f9db72a11b3ce40642bb8f 100644 --- a/trace_streamer/src/base/index_map.h +++ b/trace_streamer/src/base/index_map.h @@ -65,57 +65,53 @@ public: indexType_ = INDEX_TYPE_OUTER_INDEX; FixSize(); } - template - void MixRange(unsigned char op, T value, const std::deque& dataQueue) + void PrepMixRange(bool& remove) { filters_++; - auto invalidValue = std::numeric_limits::max(); - bool remove = false; if (HasData()) { CovertToIndexMap(); remove = true; } rowIndexBak_.clear(); + } + template + void MixRange(unsigned char op, T value, const std::deque& dataQueue) + { + auto invalidValue = std::numeric_limits::max(); + bool remove = false; + PrepMixRange(remove); switch (op) { case SQLITE_INDEX_CONSTRAINT_EQ: - ProcessData( - dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] != value; }, - [&](TableRowId id) -> bool { return dataQueue[id] == value; }); + ProcessData(dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] != value; }, + [&](TableRowId id) -> bool { return dataQueue[id] == value; }); break; case SQLITE_INDEX_CONSTRAINT_NE: - ProcessData( - dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] == value; }, - [&](TableRowId id) -> bool { return dataQueue[id] != value; }); + ProcessData(dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] == value; }, + [&](TableRowId id) -> bool { return dataQueue[id] != value; }); break; case SQLITE_INDEX_CONSTRAINT_ISNULL: - ProcessData( - dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] != invalidValue; }, - [&](TableRowId id) -> bool { return dataQueue[id] == invalidValue; }); + ProcessData(dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] != invalidValue; }, + [&](TableRowId id) -> bool { return dataQueue[id] == invalidValue; }); break; case SQLITE_INDEX_CONSTRAINT_ISNOTNULL: - ProcessData( - dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] == invalidValue; }, - [&](TableRowId id) -> bool { return dataQueue[id] != invalidValue; }); + ProcessData(dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] == invalidValue; }, + [&](TableRowId id) -> bool { return dataQueue[id] != invalidValue; }); break; case SQLITE_INDEX_CONSTRAINT_GT: - ProcessData( - dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] <= value; }, - [&](TableRowId id) -> bool { return dataQueue[id] > value; }); + ProcessData(dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] <= value; }, + [&](TableRowId id) -> bool { return dataQueue[id] > value; }); break; case SQLITE_INDEX_CONSTRAINT_GE: - ProcessData( - dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] < value; }, - [&](TableRowId id) -> bool { return dataQueue[id] >= value; }); + ProcessData(dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] < value; }, + [&](TableRowId id) -> bool { return dataQueue[id] >= value; }); break; case SQLITE_INDEX_CONSTRAINT_LE: - ProcessData( - dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] > value; }, - [&](TableRowId id) -> bool { return dataQueue[id] <= value; }); + ProcessData(dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] > value; }, + [&](TableRowId id) -> bool { return dataQueue[id] <= value; }); break; case SQLITE_INDEX_CONSTRAINT_LT: - ProcessData( - dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] >= value; }, - [&](TableRowId id) -> bool { return dataQueue[id] < value; }); + ProcessData(dataQueue, remove, [&](TableRowId id) -> bool { return dataQueue[id] >= value; }, + [&](TableRowId id) -> bool { return dataQueue[id] < value; }); break; default: break; diff --git a/trace_streamer/src/filter/hi_sysevent_measure_filter.cpp b/trace_streamer/src/filter/hi_sysevent_measure_filter.cpp index 40842110b561dd254cb929c07b31df751b593e74..682acd0021c5b2a43b94b2769f9ff1d016d23c17 100644 --- a/trace_streamer/src/filter/hi_sysevent_measure_filter.cpp +++ b/trace_streamer/src/filter/hi_sysevent_measure_filter.cpp @@ -94,45 +94,49 @@ bool HiSysEventMeasureFilter::FilterAllHiSysEvent(const json& jMessage, uint64_t } return true; } -bool HiSysEventMeasureFilter::SaveAllHiSysEvent(json jMessage, bool& haveSplitSeg) +void HiSysEventMeasureFilter::FillJsMessage(const json& jMessage, JsonMessage& jsMessage) { - JsonMessage jsMassage; for (auto item = jMessage.begin(); item != jMessage.end(); item++) { if (item.key() == "domain_") { std::string domainName = item.value(); - jsMassage.domainId = traceDataCache_->GetDataIndex(domainName.c_str()); + jsMessage.domainId = traceDataCache_->GetDataIndex(domainName.c_str()); } else if (item.key() == "name_") { std::string eventName = item.value(); - jsMassage.eventNameId = traceDataCache_->GetDataIndex(eventName.c_str()); + jsMessage.eventNameId = traceDataCache_->GetDataIndex(eventName.c_str()); } else if (item.key() == "type_") { - jsMassage.type = item.value(); + jsMessage.type = item.value(); } else if (item.key() == "time_") { - jsMassage.timeStamp = item.value(); - jsMassage.timeStamp *= MSEC_TO_NS; + jsMessage.timeStamp = item.value(); + jsMessage.timeStamp *= MSEC_TO_NS; } else if (item.key() == "tz_") { - jsMassage.timeZone = item.value(); + jsMessage.timeZone = item.value(); } else if (item.key() == "pid_") { - jsMassage.pid = item.value(); + jsMessage.pid = item.value(); } else if (item.key() == "tid_") { - jsMassage.tid = item.value(); + jsMessage.tid = item.value(); } else if (item.key() == "uid_") { - jsMassage.uid = item.value(); + jsMessage.uid = item.value(); } else if (item.key() == "id_") { - jsMassage.eventId = item.value(); + jsMessage.eventId = item.value(); } else if (item.key() == "info_") { - jsMassage.info = item.value(); + jsMessage.info = item.value(); } else if (item.key() == "tag_") { - jsMassage.tag = item.value(); + jsMessage.tag = item.value(); } else if (item.key() == "level_") { - jsMassage.level = item.value(); + jsMessage.level = item.value(); } else if (item.key() == "seq_") { - jsMassage.seq = item.value(); + jsMessage.seq = item.value(); } else { - jsMassage.content[item.key()] = item.value(); + jsMessage.content[item.key()] = item.value(); } } - auto newTimeStamp = streamFilters_->clockFilter_->ToPrimaryTraceTime(TS_CLOCK_REALTIME, jsMassage.timeStamp); - UpdatePluginTimeRange(TS_CLOCK_BOOTTIME, jsMassage.timeStamp, newTimeStamp); +} +bool HiSysEventMeasureFilter::SaveAllHiSysEvent(json jMessage, bool& haveSplitSeg) +{ + JsonMessage jsMessage; + FillJsMessage(jMessage, jsMessage); + auto newTimeStamp = streamFilters_->clockFilter_->ToPrimaryTraceTime(TS_CLOCK_REALTIME, jsMessage.timeStamp); + UpdatePluginTimeRange(TS_CLOCK_BOOTTIME, jsMessage.timeStamp, newTimeStamp); if (traceDataCache_->isSplitFile_) { if (newTimeStamp >= traceDataCache_->SplitFileMinTime() && newTimeStamp <= traceDataCache_->SplitFileMaxTime()) { @@ -140,15 +144,15 @@ bool HiSysEventMeasureFilter::SaveAllHiSysEvent(json jMessage, bool& haveSplitSe } return false; } - UpdataAllHiSysEvent(jsMassage, newTimeStamp); + UpdataAllHiSysEvent(jsMessage, newTimeStamp); return true; } -void HiSysEventMeasureFilter::UpdataAllHiSysEvent(const JsonMessage& jsMassage, uint64_t newTimeStamp) +void HiSysEventMeasureFilter::UpdataAllHiSysEvent(const JsonMessage& jsMessage, uint64_t newTimeStamp) { traceDataCache_->GetHiSysEventAllEventData()->AppendHiSysEventData( - jsMassage.domainId, jsMassage.eventNameId, newTimeStamp, jsMassage.type, jsMassage.timeZone, jsMassage.pid, - jsMassage.tid, jsMassage.uid, jsMassage.level, jsMassage.tag, jsMassage.eventId, jsMassage.seq, jsMassage.info, - jsMassage.content.dump()); + jsMessage.domainId, jsMessage.eventNameId, newTimeStamp, jsMessage.type, jsMessage.timeZone, jsMessage.pid, + jsMessage.tid, jsMessage.uid, jsMessage.level, jsMessage.tag, jsMessage.eventId, jsMessage.seq, jsMessage.info, + jsMessage.content.dump()); } bool HiSysEventMeasureFilter::JGetData(const json& jMessage, JsonData& jData, diff --git a/trace_streamer/src/filter/hi_sysevent_measure_filter.h b/trace_streamer/src/filter/hi_sysevent_measure_filter.h index ee2a87d4aa921d657bbadf3736cab3e2ff46a036..0b302697600cbbb410930256d37d2281508c59e3 100644 --- a/trace_streamer/src/filter/hi_sysevent_measure_filter.h +++ b/trace_streamer/src/filter/hi_sysevent_measure_filter.h @@ -118,7 +118,10 @@ private: DataIndex eventSourceIndex, DataIndex keyIndex, uint64_t timeStamp); - void UpdataAllHiSysEvent(const JsonMessage& jsMassage, uint64_t newTimeStamp); + void UpdataAllHiSysEvent(const JsonMessage& jsMessage, uint64_t newTimeStamp); + void FillJsMessage(const json& jMessage, JsonMessage& jsMessage); + +private: const uint64_t MSEC_TO_NS = 1000 * 1000; DataIndex GetOrCreateFilterIdInternal(DataIndex appNameId, DataIndex key); DoubleMap appKey_; diff --git a/trace_streamer/src/parser/ebpf_parser/ebpf_splitter.cpp b/trace_streamer/src/parser/ebpf_parser/ebpf_splitter.cpp index c391869a088934148a8d8e739aa95492b8c4a5bf..3c9eb8ea0d4487430067c6c1eb1cfcf0c3d228ff 100644 --- a/trace_streamer/src/parser/ebpf_parser/ebpf_splitter.cpp +++ b/trace_streamer/src/parser/ebpf_parser/ebpf_splitter.cpp @@ -82,29 +82,13 @@ bool EbpfSplitter::AddAndSplitEbpfData(std::deque& dequeBuffer) } return false; } - -template -void EbpfSplitter::StructWriteData(Structdata& structdata, DataLength datalegnth) -{ - structdata = {.type = (int32_t)SplitDataDataType::SPLIT_FILE_JSON, - .originSeg = {.offset = offsetOfEbpfDataInFile_ + splittedLen_, .size = datalegnth}}; - ebpfSplitResult_.emplace_back(structdata); - usefulDataLen_ += datalegnth; -} - -template -void EbpfSplitter::StructAddData(Structdata& structdata, - DataLength datalegnth, - std::deque& dequeBuffer, - StructDetermine& structdetermine) +void EbpfSplitter::AppendSplitOriginSegResult(uint32_t segLen) { - std::copy_n(dequeBuffer.begin() + EBPF_TITLE_SIZE, sizeof(StructDetermine), - reinterpret_cast(&structdetermine)); - if (structdetermine.endTime <= splitFileMaxTs_ && structdetermine.startTime >= splitFileMinTs_) { - StructWriteData(structdata, datalegnth); - } + HtraceSplitResult publicDataOffset{.type = (int32_t)SplitDataDataType::SPLIT_FILE_JSON, + .originSeg = {.offset = offsetOfEbpfDataInFile_ + splittedLen_, .size = segLen}}; + usefulDataLen_ += segLen; + ebpfSplitResult_.emplace_back(publicDataOffset); } - void EbpfSplitter::SplitEbpfBodyData(std::deque& dequeBuffer) { while (profilerHeader_.data.length - sizeof(ProfilerTraceFileHeader) - splittedLen_ > EBPF_TITLE_SIZE && @@ -120,23 +104,19 @@ void EbpfSplitter::SplitEbpfBodyData(std::deque& dequeBuffer) case ITEM_SYMBOL_INFO: case ITEM_EVENT_STR: case ITEM_EVENT_KENEL_SYMBOL_INFO: { - HtraceSplitResult publicDataOffset; - StructWriteData(publicDataOffset, segLen); + AppendSplitOriginSegResult(segLen); } break; case ITEM_EVENT_FS: { FsFixedHeader fsFixedHeader; - HtraceSplitResult fsDataOffset; - StructAddData(fsDataOffset, segLen, dequeBuffer, fsFixedHeader); + AppendSplitResultWithFixedHeader(segLen, dequeBuffer, fsFixedHeader); } break; case ITEM_EVENT_VM: { PagedMemoryFixedHeader pagedMemoryFixedHeader; - HtraceSplitResult pagedMemoryOffset; - StructAddData(pagedMemoryOffset, segLen, dequeBuffer, pagedMemoryFixedHeader); + AppendSplitResultWithFixedHeader(segLen, dequeBuffer, pagedMemoryFixedHeader); } break; case ITEM_EVENT_BIO: { BIOFixedHeader bioFixedHeader; - HtraceSplitResult bioDataOffset; - StructAddData(bioDataOffset, segLen, dequeBuffer, bioFixedHeader); + AppendSplitResultWithFixedHeader(segLen, dequeBuffer, bioFixedHeader); } break; default: TS_LOGI("Do not support EBPF type: %d, length: %d", dataTitle.type, dataTitle.length); diff --git a/trace_streamer/src/parser/ebpf_parser/ebpf_splitter.h b/trace_streamer/src/parser/ebpf_parser/ebpf_splitter.h index 2d100dc3c0bed33ea06361346bf65eafea574153..bdcb45c3ad7dfaf721f054df2f8e0f0857797704 100644 --- a/trace_streamer/src/parser/ebpf_parser/ebpf_splitter.h +++ b/trace_streamer/src/parser/ebpf_parser/ebpf_splitter.h @@ -62,15 +62,15 @@ public: private: bool SplitEbpfHeader(std::deque& dequeBuffer); void SplitEbpfBodyData(std::deque& dequeBuffer); - - template - void StructAddData(Structdata& structdata, - DataLength datalegnth, - std::deque& dequeBuffer, - StructDetermine& structdetermine); - - template - void StructWriteData(Structdata& structdata, DataLength datalegnth); + void AppendSplitOriginSegResult(uint32_t segLen); + template + void AppendSplitResultWithFixedHeader(uint32_t segLen, std::deque& dequeBuffer, FixedHeader& fixedHeader) + { + std::copy_n(dequeBuffer.begin() + EBPF_TITLE_SIZE, sizeof(FixedHeader), reinterpret_cast(&fixedHeader)); + if (fixedHeader.endTime <= splitFileMaxTs_ && fixedHeader.startTime >= splitFileMinTs_) { + AppendSplitOriginSegResult(segLen); + } + } uint64_t splittedLen_ = 0; uint64_t usefulDataLen_ = 0; std::deque ebpfBuffer_; diff --git a/trace_streamer/src/version.cpp b/trace_streamer/src/version.cpp index de59fe5e1d080ad1bee975fe0340464f11d6081c..851dacdf154972b439e0b4853014043b6f688297 100644 --- a/trace_streamer/src/version.cpp +++ b/trace_streamer/src/version.cpp @@ -17,7 +17,7 @@ namespace SysTuning { namespace TraceStreamer { size_t g_loadSize = 0; size_t g_fileSize = 0; -const std::string g_traceStreamerVersion = "3.5.14"; // version -const std::string g_traceStreamerPublishVersion = "2023/12/27"; // publish datetime +const std::string g_traceStreamerVersion = "3.5.19"; // version +const std::string g_traceStreamerPublishVersion = "2024/01/13"; // publish datetime } // namespace TraceStreamer } // namespace SysTuning diff --git a/trace_streamer/test/unittest/htrace/native_memory/native_hook_parser_test.cpp b/trace_streamer/test/unittest/htrace/native_memory/native_hook_parser_test.cpp index be3a837a9f6deb937983bccbddaf6a86281ae97b..9df02c12921ec571344a21742758a9fbe494ac58 100644 --- a/trace_streamer/test/unittest/htrace/native_memory/native_hook_parser_test.cpp +++ b/trace_streamer/test/unittest/htrace/native_memory/native_hook_parser_test.cpp @@ -237,12 +237,17 @@ public: nativeHookData->set_allocated_munmap_event(munmapEvent); } - BatchNativeHookData CreateBatchNativeHookData(std::string& hookStrMsg) + BatchNativeHookData CreateBatchNativeHookData(HtraceDataSegment& dataSeg) { + std::string hookStrMsg = ""; BatchNativeHookData batchNativeHookData; SetAllocEvent(batchNativeHookData, {TID_01, ADDR_01, SIZE_01, "", SEC_01, NSEC_01}, true); SetAllocEvent(batchNativeHookData, {TID_02, ADDR_02, SIZE_02, "", SEC_02, NSEC_02}, true); batchNativeHookData.SerializeToString(&hookStrMsg); + dataSeg.seg = std::make_shared(hookStrMsg); + ProtoReader::BytesView hookBytesView(reinterpret_cast(dataSeg.seg->data()), + dataSeg.seg->size()); + dataSeg.protoData = hookBytesView; return batchNativeHookData; } @@ -561,12 +566,8 @@ HWTEST_F(NativeHookParserTest, ParseBatchNativeHookWithOneMalloc, TestSize.Level HWTEST_F(NativeHookParserTest, ParseBatchNativeHookWithMultipleMalloc, TestSize.Level1) { TS_LOGI("test24-3"); - std::string hookStrMsg = ""; - BatchNativeHookData batchNativeHookData = CreateBatchNativeHookData(hookStrMsg); HtraceDataSegment dataSeg; - dataSeg.seg = std::make_shared(hookStrMsg); - ProtoReader::BytesView hookBytesView(reinterpret_cast(hookStrMsg.data()), hookStrMsg.size()); - dataSeg.protoData = hookBytesView; + BatchNativeHookData batchNativeHookData = CreateBatchNativeHookData(dataSeg); HtraceNativeHookParser htraceNativeHookParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get()); bool hasSplit = false; htraceNativeHookParser.Parse(dataSeg, hasSplit);