-
Notifications
You must be signed in to change notification settings - Fork 6
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
Rename threads for more compact tracy visualization #49
Merged
ethercrow
merged 4 commits into
master
from
rename-threads-for-more-compact-presentation
Apr 13, 2021
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
66f40e5
More compact thread presentation for Tracy
ethercrow e7a5d79
When observing a second half-span reuse the thread id and display id …
ethercrow a8fabd1
Memoize nextFreeDisplayThread to avoid excessive calls to HashMap.size
ethercrow 05a67bc
Fix CI job using GHC 8.6
ethercrow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,8 @@ jobs: | |
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
ghc: ['8.6', '8.8', '8.10', '9.0'] | ||
ghc: ['8.6', '8.8', '8.10'] | ||
fail-fast: false | ||
steps: | ||
- uses: actions/[email protected] | ||
- uses: actions/[email protected] | ||
|
@@ -48,6 +49,7 @@ jobs: | |
strategy: | ||
matrix: | ||
stack-yaml: ['stack-8.10.yaml'] | ||
fail-fast: false | ||
steps: | ||
- uses: actions/[email protected] | ||
- uses: actions/[email protected] | ||
|
@@ -75,6 +77,7 @@ jobs: | |
strategy: | ||
matrix: | ||
stack-yaml: ['stack-8.10.yaml'] | ||
fail-fast: false | ||
steps: | ||
- uses: actions/[email protected] | ||
- uses: actions/[email protected] | ||
|
@@ -101,7 +104,8 @@ jobs: | |
runs-on: windows-latest | ||
strategy: | ||
matrix: | ||
ghc: ['8.10', '9.0.1'] | ||
ghc: ['8.10'] | ||
fail-fast: false | ||
steps: | ||
- uses: actions/[email protected] | ||
- uses: actions/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,12 +35,13 @@ data WatDoOnEOF = StopOnEOF | SleepAndRetryOnEOF | |
|
||
data State = S | ||
{ originTimestamp :: !Timestamp, | ||
threadMap :: IM.IntMap ThreadId, | ||
cap2thread :: IM.IntMap ThreadId, | ||
spans :: HM.HashMap SpanId Span, | ||
instrumentMap :: HM.HashMap InstrumentId CaptureInstrument, | ||
traceMap :: HM.HashMap ThreadId TraceId, | ||
serial2sid :: HM.HashMap Word64 SpanId, | ||
thread2sid :: HM.HashMap ThreadId SpanId, | ||
thread2displayThread :: HM.HashMap ThreadId ThreadId, -- https://github.com/ethercrow/opentelemetry-haskell/issues/40 | ||
gcRequestedAt :: !Timestamp, | ||
gcStartedAt :: !Timestamp, | ||
gcGeneration :: !Int, | ||
|
@@ -52,7 +53,7 @@ data State = S | |
deriving (Show) | ||
|
||
initialState :: Word64 -> R.SMGen -> State | ||
initialState timestamp = S timestamp mempty mempty mempty mempty mempty mempty 0 0 0 0 0 0 | ||
initialState timestamp = S timestamp mempty mempty mempty mempty mempty mempty mempty 0 0 0 0 0 0 | ||
|
||
data EventSource | ||
= EventLogHandle Handle WatDoOnEOF | ||
|
@@ -142,9 +143,9 @@ parseOpenTelemetry UserBinaryMessage {payload} = parseByteString payload | |
parseOpenTelemetry _ = Nothing | ||
|
||
processEvent :: Event -> State -> (State, [Span], [Metric]) | ||
processEvent (Event ts ev m_cap) st@(S {..}) = | ||
processEvent (Event ts ev m_cap) st@S {..} = | ||
let now = originTimestamp + ts | ||
m_thread_id = m_cap >>= flip IM.lookup threadMap | ||
m_thread_id = m_cap >>= flip IM.lookup cap2thread | ||
m_trace_id = m_thread_id >>= flip HM.lookup traceMap | ||
in case (ev, m_cap, m_thread_id) of | ||
(WallClockTime {sec, nsec}, _, _) -> | ||
|
@@ -158,12 +159,13 @@ processEvent (Event ts ev m_cap) st@(S {..}) = | |
[Metric threadsI [MetricDatapoint now 1]] | ||
) | ||
(RunThread tid, Just cap, _) -> | ||
(st {threadMap = IM.insert cap tid threadMap}, [], []) | ||
(st {cap2thread = IM.insert cap tid cap2thread}, [], []) | ||
(StopThread tid tstatus, Just cap, _) | ||
| isTerminalThreadStatus tstatus -> | ||
( st | ||
{ threadMap = IM.delete cap threadMap, | ||
traceMap = HM.delete tid traceMap | ||
{ cap2thread = IM.delete cap cap2thread, | ||
traceMap = HM.delete tid traceMap, | ||
thread2displayThread = HM.delete tid thread2displayThread | ||
}, | ||
[], | ||
[Metric threadsI [MetricDatapoint now (-1)]] | ||
|
@@ -187,6 +189,7 @@ processEvent (Event ts ev m_cap) st@(S {..}) = | |
spanStartedAt = gcStartedAt, | ||
spanFinishedAt = now, | ||
spanThreadId = maxBound, | ||
spanDisplayThreadId = maxBound, | ||
spanTags = mempty, | ||
spanEvents = [], | ||
spanParentId = Nothing, | ||
|
@@ -200,6 +203,7 @@ processEvent (Event ts ev m_cap) st@(S {..}) = | |
spanStartedAt = gcRequestedAt, | ||
spanFinishedAt = gcStartedAt, | ||
spanThreadId = maxBound, | ||
spanDisplayThreadId = maxBound, | ||
spanTags = mempty, | ||
spanEvents = [], | ||
spanParentId = Nothing, | ||
|
@@ -284,12 +288,14 @@ handleOpenTelemetryEventlogEvent m st (tid, now, m_trace_id) = | |
case HM.lookup serial $ serial2sid st of | ||
Nothing -> | ||
let (st', span_id) = inventSpanId serial st | ||
(st'', display_tid) = inventDisplayTid tid st' | ||
parent = HM.lookup tid (thread2sid st) | ||
sp = | ||
Span | ||
{ spanContext = SpanContext span_id (fromMaybe (TId 42) m_trace_id), | ||
spanOperation = "", | ||
spanThreadId = tid, | ||
spanDisplayThreadId = display_tid, | ||
spanStartedAt = 0, | ||
spanFinishedAt = now, | ||
spanTags = mempty, | ||
|
@@ -298,20 +304,23 @@ handleOpenTelemetryEventlogEvent m st (tid, now, m_trace_id) = | |
spanNanosecondsSpentInGC = 0, | ||
spanParentId = parent | ||
} | ||
in (createSpan span_id sp st', [], []) | ||
in (createSpan span_id sp st'', [], []) | ||
Just span_id -> | ||
let (st', sp) = emitSpan serial span_id st | ||
in (st', [sp {spanFinishedAt = now}], []) | ||
(st'', display_tid) = inventDisplayTid tid st' | ||
in (st'', [sp {spanFinishedAt = now, spanDisplayThreadId = display_tid}], []) | ||
BeginSpanEv (SpanInFlight serial) (SpanName operation) -> | ||
case HM.lookup serial (serial2sid st) of | ||
Nothing -> | ||
let (st', span_id) = inventSpanId serial st | ||
parent = HM.lookup tid (thread2sid st) | ||
(st'', display_tid) = inventDisplayTid tid st' | ||
sp = | ||
Span | ||
{ spanContext = SpanContext span_id (fromMaybe (TId 42) m_trace_id), | ||
spanOperation = operation, | ||
spanThreadId = tid, | ||
spanDisplayThreadId = display_tid, | ||
spanStartedAt = now, | ||
spanFinishedAt = 0, | ||
spanTags = mempty, | ||
|
@@ -320,10 +329,11 @@ handleOpenTelemetryEventlogEvent m st (tid, now, m_trace_id) = | |
spanNanosecondsSpentInGC = 0, | ||
spanParentId = parent | ||
} | ||
in (createSpan span_id sp st', [], []) | ||
in (createSpan span_id sp st'', [], []) | ||
Just span_id -> | ||
let (st', sp) = emitSpan serial span_id st | ||
in (st', [sp {spanOperation = operation, spanStartedAt = now, spanThreadId = tid}], []) | ||
(st'', display_tid) = inventDisplayTid tid st' | ||
in (st'', [sp {spanOperation = operation, spanStartedAt = now, spanThreadId = tid, spanDisplayThreadId = display_tid}], []) | ||
DeclareInstrumentEv iType iId iName -> | ||
(st {instrumentMap = HM.insert iId (CaptureInstrument iType iName) (instrumentMap st)}, [], []) | ||
MetricCaptureEv instrumentId val -> case HM.lookup instrumentId (instrumentMap st) of | ||
|
@@ -396,6 +406,14 @@ inventSpanId serial st = (st', sid) | |
(SId -> sid, randomGen') = R.nextWord64 randomGen | ||
st' = st {serial2sid = HM.insert serial sid serial2sid, randomGen = randomGen'} | ||
|
||
inventDisplayTid :: ThreadId -> State -> (State, ThreadId) | ||
inventDisplayTid tid st@(S {thread2displayThread}) = | ||
case HM.lookup tid thread2displayThread of | ||
Nothing -> | ||
let new_dtid = fromIntegral (HM.size thread2displayThread) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed surprising, I didn't realize that. |
||
in (st {thread2displayThread = HM.insert tid new_dtid thread2displayThread}, new_dtid) | ||
Just dtid -> (st, dtid) | ||
|
||
parseText :: [T.Text] -> Maybe OpenTelemetryEventlogEvent | ||
parseText = | ||
\case | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I comment out line 310 (and fix the result state) my trace no longer crashes tracy.
Why invent a new
displayTid
instead of reusing the same one used in theBeginSpan
frame? If the events are slightly out of order and theStopThread
event is processed before theEndSpan
event, thedisplayTid
used here will be completely wrong and crash Tracy.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.