Skip to content

Commit f80c9f3

Browse files
committed
Adds concurrency protection to BPTrace to prevent nasty issues. Currently very conservative and broad. Might slow down tracing somewhat.
1 parent e31a204 commit f80c9f3

File tree

11 files changed

+32
-23
lines changed

11 files changed

+32
-23
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
private
22
addTracedValue: aTraceValue forAssertion: anAssertionId
33

4-
(self assertions at: anAssertionId ifAbsentPut: [OrderedCollection new]) add: aTraceValue.
4+
mutex critical: [
5+
(self assertions at: anAssertionId ifAbsentPut: [OrderedCollection new]) add: aTraceValue].
56
self addChronologicalPositionTo: aTraceValue forAnnotation: anAssertionId.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
private
22
addTracedValue: aTraceValue forProbe: aProbeId
33

4-
(self probes at: aProbeId ifAbsentPut: [OrderedCollection new]) add: aTraceValue.
4+
mutex critical: [
5+
(self probes at: aProbeId ifAbsentPut: [OrderedCollection new]) add: aTraceValue].
56
self addChronologicalPositionTo: aTraceValue forAnnotation: aProbeId.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
testing
22
includesValuesForProbeId: aProbeId
33

4-
^ (self probes at: aProbeId ifAbsent: [#()]) notEmpty
4+
^ mutex critical: [(self probes at: aProbeId ifAbsent: [#()]) notEmpty]

packages/Babylonian-Core.package/BPTrace.class/instance/initialize.st

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ initialize
77
exampleErrored := false.
88
hasTraceCompleted := false.
99
blockRecord := Dictionary new.
10-
chronologicallyTrackedTraceValuesCount := 0.
10+
chronologicallyTrackedTraceValuesCount := 0.
11+
mutex := Mutex new.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
accessing
22
resultsForAssertionId: anAssertionId
33

4-
^ self assertions at: anAssertionId ifAbsent: [#()]
4+
^ mutex critical: [self assertions at: anAssertionId ifAbsent: [#()]]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
accessing
22
runsForBlockId: aBlockId
33

4-
^ blockRecord at: aBlockId ifAbsent: [#()]
4+
^ mutex critical: [blockRecord at: aBlockId ifAbsent: [#()]]
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
recording
22
traceBlock: id enteredInContext: aContext
33

4-
(blockRecord at: id ifAbsentPut: [OrderedCollection new]) add: (self newTracedValue: nil expression: '' stackFrom: aContext).
4+
| value |
5+
value := self newTracedValue: nil expression: '' stackFrom: aContext.
6+
mutex critical: [
7+
(blockRecord at: id ifAbsentPut: [OrderedCollection new]) add: value].

packages/Babylonian-Core.package/BPTrace.class/instance/traceValues.st

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ traceValues
33

44
"Reduce does not work for empty collections, so we have to add an extra conditional"
55
| probesAndAssertions |
6-
probesAndAssertions := self probes asCollection.
7-
probesAndAssertions addAll: self assertions asCollection.
6+
mutex critical: [
7+
probesAndAssertions := self probes asCollection.
8+
probesAndAssertions addAll: self assertions asCollection].
89
probesAndAssertions ifEmpty: [^ probesAndAssertions values ].
910
^ (probesAndAssertions values fold: [:a :b | a , b]) sorted: [:a | a chronologicalPosition] ascending.
1011

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
accessing
22
valuesForProbeId: aProbeId
33

4-
^ self probes at: aProbeId ifAbsent: [
5-
self exampleErrored
6-
ifTrue: [{BPFailedTrace new}]
7-
ifFalse: [#()]]
4+
mutex critical: [
5+
^ self probes at: aProbeId ifAbsent: [
6+
self exampleErrored
7+
ifTrue: [{BPFailedTrace new}]
8+
ifFalse: [#()]]]

packages/Babylonian-Core.package/BPTrace.class/methodProperties.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"maxStackSize" : "jb 6/30/2021 01:13" },
44
"instance" : {
55
"addChronologicalPositionTo:forAnnotation:" : "lu 11/21/2021 18:56",
6-
"addTracedValue:forAssertion:" : "lu 11/21/2021 18:47",
7-
"addTracedValue:forProbe:" : "lu 11/21/2021 18:47",
6+
"addTracedValue:forAssertion:" : "pre 1/11/2023 16:24",
7+
"addTracedValue:forProbe:" : "pre 1/11/2023 16:25",
88
"assertions" : "pre 5/10/2019 10:09",
99
"chronologicallyTrackedTraceValuesCount" : "lu 11/22/2021 22:03",
1010
"example" : "pre 5/8/2019 16:26",
@@ -15,23 +15,23 @@
1515
"executionResult" : "jb 12/30/2021 21:09",
1616
"hasTraceCompleted" : "pre 8/17/2020 09:55",
1717
"hasTraceCompleted:" : "jb 12/7/2020 18:54",
18-
"includesValuesForProbeId:" : "pre 7/24/2019 11:30",
19-
"initialize" : "lu 11/21/2021 18:55",
18+
"includesValuesForProbeId:" : "pre 1/11/2023 16:27",
19+
"initialize" : "pre 1/11/2023 16:23",
2020
"mementoFor:" : "jb 6/11/2021 00:47",
2121
"newTracedAssignmentValue:previousValues:expression:stackFrom:" : "pre 10/12/2020 17:58",
2222
"newTracedValue:expression:stackFrom:" : "pre 10/12/2020 17:57",
2323
"probes" : "pre 5/8/2019 16:44",
2424
"recordedException" : "pre 7/25/2019 12:28",
2525
"recordedException:" : "jb 12/7/2020 18:54",
26-
"resultsForAssertionId:" : "pre 11/18/2019 12:55",
27-
"runsForBlockId:" : "pre 9/25/2020 17:08",
26+
"resultsForAssertionId:" : "pre 1/11/2023 16:27",
27+
"runsForBlockId:" : "pre 1/11/2023 16:26",
2828
"stackFrom:" : "pre 11/29/2022 16:24",
2929
"trace:forAssertion:inContext:" : "jb 12/7/2020 18:54",
3030
"trace:forId:inContext:" : "jb 12/7/2020 18:54",
3131
"traceAssignment:previousValues:forId:inContext:" : "jb 12/7/2020 18:54",
32-
"traceBlock:enteredInContext:" : "jb 12/7/2020 18:54",
32+
"traceBlock:enteredInContext:" : "pre 1/11/2023 16:25",
3333
"traceException:" : "jb 12/7/2020 18:54",
3434
"traceException:forId:" : "jb 12/30/2021 21:10",
3535
"traceExecutionResult:" : "jb 12/30/2021 21:15",
36-
"traceValues" : "lu 11/22/2021 23:20",
37-
"valuesForProbeId:" : "lu 11/22/2021 23:25" } }
36+
"traceValues" : "pre 1/11/2023 16:26",
37+
"valuesForProbeId:" : "pre 1/11/2023 16:26" } }

0 commit comments

Comments
 (0)