Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the wrong thread name in the trace profiling function. #385

Merged
merged 4 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
10 changes: 4 additions & 6 deletions collector/pkg/component/analyzer/cpuanalyzer/cpu_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand All @@ -225,8 +224,7 @@ func (ca *CpuAnalyzer) PutEventToSegments(pid uint32, tid uint32, threadName str
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,
dxsup marked this conversation as resolved.
Show resolved Hide resolved
(newTimeSegments.BaseTime+uint64(i+1))*nanoToSeconds)
newTimeSegments.Segments.UpdateByIndex(i, segment)
}
Expand Down
29 changes: 14 additions & 15 deletions collector/pkg/component/analyzer/cpuanalyzer/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -28,16 +29,14 @@ 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"`
}

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"`
Expand All @@ -47,11 +46,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),
Expand All @@ -61,6 +57,9 @@ func newSegment(pid uint32, tid uint32, threadName string, startTime uint64, end
IndexTimestamp: "",
}
}
func (t *TimeSegments) updateThreadName(threadName string) {
t.ThreadName = threadName
}
dxsup marked this conversation as resolved.
Show resolved Hide resolved
func (s *Segment) putTimedEvent(event TimedEvent) {
switch event.Kind() {
case TimedCpuEventKind:
Expand All @@ -72,12 +71,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions probe/src/cgo/kindling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{
dxsup marked this conversation as resolved.
Show resolved Hide resolved
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;
Expand Down Expand Up @@ -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;
Expand Down