diff --git a/CHANGELOG.md b/CHANGELOG.md index d0d41edf9..23e2ccdd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ ### Bug fixes +- Fix the wrong thread name in the trace profiling function. ([#385])(https://github.com/KindlingProject/kindling/pull/385) - Remove "reset" method of ScheduledTaskRoutine to fix a potential dead-lock issue. ([#369])(https://github.com/KindlingProject/kindling/pull/369) - Fix the bug where the pod metadata with persistent IP in the map is deleted incorrectly due to the deleting mechanism with a delay. ([#374](https://github.com/KindlingProject/kindling/pull/374)) - Fix the bug that when the response is nil, the NAT IP and port are not added to the labels of the "DataGroup". ([#378](https://github.com/KindlingProject/kindling/pull/378)) diff --git a/collector/pkg/component/analyzer/cpuanalyzer/cpu_analyzer.go b/collector/pkg/component/analyzer/cpuanalyzer/cpu_analyzer.go index 13e059688..c15fc56fa 100644 --- a/collector/pkg/component/analyzer/cpuanalyzer/cpu_analyzer.go +++ b/collector/pkg/component/analyzer/cpuanalyzer/cpu_analyzer.go @@ -181,8 +181,7 @@ func (ca *CpuAnalyzer) PutEventToSegments(pid uint32, tid uint32, threadName str endOffset = endOffset - startOffset startOffset = 0 for i := 0; i < maxSegmentSize; i++ { - segment := newSegment(pid, tid, threadName, - (timeSegments.BaseTime+uint64(i))*nanoToSeconds, + segment := newSegment((timeSegments.BaseTime+uint64(i))*nanoToSeconds, (timeSegments.BaseTime+uint64(i+1))*nanoToSeconds) timeSegments.Segments.UpdateByIndex(i, segment) } @@ -201,14 +200,14 @@ func (ca *CpuAnalyzer) PutEventToSegments(pid uint32, tid uint32, threadName str movedIndex := i + clearSize val := timeSegments.Segments.GetByIndex(movedIndex) timeSegments.Segments.UpdateByIndex(i, val) - segmentTmp := newSegment(pid, tid, threadName, - (timeSegments.BaseTime+uint64(movedIndex))*nanoToSeconds, + segmentTmp := newSegment((timeSegments.BaseTime+uint64(movedIndex))*nanoToSeconds, (timeSegments.BaseTime+uint64(movedIndex+1))*nanoToSeconds) timeSegments.Segments.UpdateByIndex(movedIndex, segmentTmp) } } } + timeSegments.updateThreadName(threadName) //update the thread name immediatly for i := startOffset; i <= endOffset && i < maxSegmentSize; i++ { val := timeSegments.Segments.GetByIndex(i) segment := val.(*Segment) @@ -219,14 +218,14 @@ func (ca *CpuAnalyzer) PutEventToSegments(pid uint32, tid uint32, threadName str } else { newTimeSegments := &TimeSegments{ - Pid: pid, - Tid: tid, - BaseTime: event.StartTimestamp() / nanoToSeconds, - Segments: NewCircleQueue(maxSegmentSize), + Pid: pid, + Tid: tid, + ThreadName: threadName, + BaseTime: event.StartTimestamp() / nanoToSeconds, + Segments: NewCircleQueue(maxSegmentSize), } for i := 0; i < maxSegmentSize; i++ { - segment := newSegment(pid, tid, threadName, - (newTimeSegments.BaseTime+uint64(i))*nanoToSeconds, + segment := newSegment((newTimeSegments.BaseTime+uint64(i))*nanoToSeconds, (newTimeSegments.BaseTime+uint64(i+1))*nanoToSeconds) newTimeSegments.Segments.UpdateByIndex(i, segment) } diff --git a/collector/pkg/component/analyzer/cpuanalyzer/model.go b/collector/pkg/component/analyzer/cpuanalyzer/model.go index 712350034..52e853074 100644 --- a/collector/pkg/component/analyzer/cpuanalyzer/model.go +++ b/collector/pkg/component/analyzer/cpuanalyzer/model.go @@ -2,6 +2,7 @@ package cpuanalyzer import ( "encoding/json" + "github.com/Kindling-project/kindling/collector/pkg/model" "github.com/Kindling-project/kindling/collector/pkg/model/constlabels" "github.com/Kindling-project/kindling/collector/pkg/model/constnames" @@ -28,16 +29,18 @@ type TimedEvent interface { } type TimeSegments struct { - Pid uint32 `json:"pid"` - Tid uint32 `json:"tid"` - BaseTime uint64 `json:"baseTime"` - Segments *CircleQueue `json:"segments"` + Pid uint32 `json:"pid"` + Tid uint32 `json:"tid"` + ThreadName string `json:"threadName"` + BaseTime uint64 `json:"baseTime"` + Segments *CircleQueue `json:"segments"` +} + +func (t *TimeSegments) updateThreadName(threadName string) { + t.ThreadName = threadName } type Segment struct { - Pid uint32 `json:"pid"` - Tid uint32 `json:"tid"` - ThreadName string `json:"threadName"` StartTime uint64 `json:"startTime"` EndTime uint64 `json:"endTime"` CpuEvents []TimedEvent `json:"cpuEvents"` @@ -47,11 +50,8 @@ type Segment struct { IndexTimestamp string `json:"indexTimestamp"` } -func newSegment(pid uint32, tid uint32, threadName string, startTime uint64, endTime uint64) *Segment { +func newSegment(startTime uint64, endTime uint64) *Segment { return &Segment{ - Pid: pid, - Tid: tid, - ThreadName: threadName, StartTime: startTime, EndTime: endTime, CpuEvents: make([]TimedEvent, 0), @@ -61,6 +61,7 @@ func newSegment(pid uint32, tid uint32, threadName string, startTime uint64, end IndexTimestamp: "", } } + func (s *Segment) putTimedEvent(event TimedEvent) { switch event.Kind() { case TimedCpuEventKind: @@ -72,12 +73,12 @@ func (s *Segment) putTimedEvent(event TimedEvent) { } } -func (s *Segment) toDataGroup() *model.DataGroup { +func (s *Segment) toDataGroup(parent *TimeSegments) *model.DataGroup { labels := model.NewAttributeMap() - labels.AddIntValue(constlabels.Pid, int64(s.Pid)) - labels.AddIntValue(constlabels.Tid, int64(s.Tid)) + labels.AddIntValue(constlabels.Pid, int64(parent.Pid)) + labels.AddIntValue(constlabels.Tid, int64(parent.Tid)) labels.AddIntValue(constlabels.IsSent, int64(s.IsSend)) - labels.AddStringValue(constlabels.ThreadName, s.ThreadName) + labels.AddStringValue(constlabels.ThreadName, parent.ThreadName) labels.AddIntValue(constlabels.StartTime, int64(s.StartTime)) labels.AddIntValue(constlabels.EndTime, int64(s.EndTime)) cpuEventString, err := json.Marshal(s.CpuEvents) diff --git a/collector/pkg/component/analyzer/cpuanalyzer/send_trigger.go b/collector/pkg/component/analyzer/cpuanalyzer/send_trigger.go index 071ab5be4..2ee7824e0 100644 --- a/collector/pkg/component/analyzer/cpuanalyzer/send_trigger.go +++ b/collector/pkg/component/analyzer/cpuanalyzer/send_trigger.go @@ -128,7 +128,7 @@ func (ca *CpuAnalyzer) sendEvents(keyElements *model.AttributeMap, pid uint32, s if len(segment.CpuEvents) != 0 { // Don't remove the duplicated one segment.IndexTimestamp = time.Now().String() - dataGroup := segment.toDataGroup() + dataGroup := segment.toDataGroup(timeSegments) dataGroup.Labels.Merge(keyElements) for _, nexConsumer := range ca.nextConsumers { _ = nexConsumer.Consume(dataGroup) diff --git a/probe/src/cgo/kindling.cpp b/probe/src/cgo/kindling.cpp index 77e457b62..acf295325 100644 --- a/probe/src/cgo/kindling.cpp +++ b/probe/src/cgo/kindling.cpp @@ -430,6 +430,8 @@ void parse_jf(char* data_val, sinsp_evt_param data_param, kindling_event_t_for_g ptid_comm.find(threadInfo->m_pid << 32 | (threadInfo->m_tid & 0xFFFFFFFF)); if (key != ptid_comm.end()) { strcpy(p_kindling_event->context.tinfo.comm, key->second); + } else { + strcpy(p_kindling_event->context.tinfo.comm, (char*)threadInfo->m_comm.data()); } p_kindling_event->context.tinfo.pid = threadInfo->m_pid; p_kindling_event->paramsNumber = userAttNumber; @@ -478,6 +480,8 @@ void parse_xtid(sinsp_evt* s_evt, char* data_val, sinsp_evt_param data_param, ptid_comm.find(threadInfo->m_pid << 32 | (threadInfo->m_tid & 0xFFFFFFFF)); if (key != ptid_comm.end()) { strcpy(p_kindling_event->context.tinfo.comm, key->second); + } else { + strcpy(p_kindling_event->context.tinfo.comm, (char*)threadInfo->m_comm.data()); } p_kindling_event->context.tinfo.pid = threadInfo->m_pid; p_kindling_event->paramsNumber = userAttNumber;