@@ -42,6 +42,7 @@ data State = S
42
42
serial2sid :: HM. HashMap Word64 SpanId ,
43
43
thread2sid :: HM. HashMap ThreadId SpanId ,
44
44
thread2displayThread :: HM. HashMap ThreadId ThreadId , -- https://github.com/ethercrow/opentelemetry-haskell/issues/40
45
+ nextFreeDisplayThread :: ThreadId ,
45
46
gcRequestedAt :: ! Timestamp ,
46
47
gcStartedAt :: ! Timestamp ,
47
48
gcGeneration :: ! Int ,
@@ -53,7 +54,7 @@ data State = S
53
54
deriving (Show )
54
55
55
56
initialState :: Word64 -> R. SMGen -> State
56
- initialState timestamp = S timestamp mempty mempty mempty mempty mempty mempty mempty 0 0 0 0 0 0
57
+ initialState timestamp = S timestamp mempty mempty mempty mempty mempty mempty mempty 1 0 0 0 0 0 0
57
58
58
59
data EventSource
59
60
= EventLogHandle Handle WatDoOnEOF
@@ -162,14 +163,18 @@ processEvent (Event ts ev m_cap) st@S {..} =
162
163
(st {cap2thread = IM. insert cap tid cap2thread}, [] , [] )
163
164
(StopThread tid tstatus, Just cap, _)
164
165
| isTerminalThreadStatus tstatus ->
165
- ( st
166
- { cap2thread = IM. delete cap cap2thread,
167
- traceMap = HM. delete tid traceMap,
168
- thread2displayThread = HM. delete tid thread2displayThread
169
- },
170
- [] ,
171
- [Metric threadsI [MetricDatapoint now (- 1 )]]
172
- )
166
+ let (t2dt, nfdt) = case HM. lookup tid thread2displayThread of
167
+ Nothing -> (thread2displayThread, nextFreeDisplayThread)
168
+ Just _ -> (HM. delete tid thread2displayThread, nextFreeDisplayThread - 1 )
169
+ in ( st
170
+ { cap2thread = IM. delete cap cap2thread,
171
+ traceMap = HM. delete tid traceMap,
172
+ thread2displayThread = t2dt,
173
+ nextFreeDisplayThread = nfdt
174
+ },
175
+ [] ,
176
+ [Metric threadsI [MetricDatapoint now (- 1 )]]
177
+ )
173
178
(RequestSeqGC , _, _) ->
174
179
(st {gcRequestedAt = now}, [] , [] )
175
180
(RequestParGC , _, _) ->
@@ -405,11 +410,11 @@ inventSpanId serial st = (st', sid)
405
410
st' = st {serial2sid = HM. insert serial sid serial2sid, randomGen = randomGen'}
406
411
407
412
inventDisplayTid :: ThreadId -> State -> (State , ThreadId )
408
- inventDisplayTid tid st@ (S {thread2displayThread}) =
413
+ inventDisplayTid tid st@ (S {thread2displayThread, nextFreeDisplayThread }) =
409
414
case HM. lookup tid thread2displayThread of
410
415
Nothing ->
411
- let new_dtid = fromIntegral ( HM. size thread2displayThread)
412
- in (st {thread2displayThread = HM. insert tid new_dtid thread2displayThread}, new_dtid)
416
+ let new_dtid = nextFreeDisplayThread
417
+ in (st {thread2displayThread = HM. insert tid new_dtid thread2displayThread, nextFreeDisplayThread = new_dtid + 1 }, new_dtid)
413
418
Just dtid -> (st, dtid)
414
419
415
420
parseText :: [T. Text ] -> Maybe OpenTelemetryEventlogEvent
0 commit comments