Skip to content

Commit b958328

Browse files
Follow-up cleanups from Runtime Tracing Upstream
1 parent d60b6e5 commit b958328

File tree

11 files changed

+63
-63
lines changed

11 files changed

+63
-63
lines changed

workflow-runtime/api/workflow-runtime.api

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ public final class com/squareup/workflow1/WorkflowInterceptor$RenderingProduced
108108
public fun toString ()Ljava/lang/String;
109109
}
110110

111-
public final class com/squareup/workflow1/WorkflowInterceptor$RuntimeLoopTick : com/squareup/workflow1/WorkflowInterceptor$RuntimeUpdate {
112-
public static final field INSTANCE Lcom/squareup/workflow1/WorkflowInterceptor$RuntimeLoopTick;
111+
public final class com/squareup/workflow1/WorkflowInterceptor$RuntimeSettled : com/squareup/workflow1/WorkflowInterceptor$RuntimeUpdate {
112+
public static final field INSTANCE Lcom/squareup/workflow1/WorkflowInterceptor$RuntimeSettled;
113113
public fun equals (Ljava/lang/Object;)Z
114114
public fun hashCode ()I
115115
public fun toString ()Ljava/lang/String;

workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/RenderWorkflow.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import com.squareup.workflow1.RuntimeConfigOptions.RENDER_ONLY_WHEN_STATE_CHANGE
66
import com.squareup.workflow1.WorkflowInterceptor.RenderPassSkipped
77
import com.squareup.workflow1.WorkflowInterceptor.RenderingConflated
88
import com.squareup.workflow1.WorkflowInterceptor.RenderingProduced
9-
import com.squareup.workflow1.WorkflowInterceptor.RuntimeLoopTick
9+
import com.squareup.workflow1.WorkflowInterceptor.RuntimeSettled
1010
import com.squareup.workflow1.internal.WorkStealingDispatcher
1111
import com.squareup.workflow1.internal.WorkflowRunner
1212
import com.squareup.workflow1.internal.chained
@@ -176,7 +176,7 @@ public fun <PropsT, OutputT, RenderingT> renderWorkflowIn(
176176
try {
177177
runner.nextRendering().also {
178178
chainedInterceptor.onRuntimeUpdate(RenderingProduced)
179-
chainedInterceptor.onRuntimeUpdate(RuntimeLoopTick)
179+
chainedInterceptor.onRuntimeUpdate(RuntimeSettled)
180180
}
181181
} catch (e: Throwable) {
182182
// If any part of the workflow runtime fails, the scope should be cancelled. We're not in a
@@ -239,7 +239,7 @@ public fun <PropsT, OutputT, RenderingT> renderWorkflowIn(
239239

240240
if (shouldShortCircuitForUnchangedState(actionResult)) {
241241
chainedInterceptor.onRuntimeUpdate(RenderPassSkipped)
242-
chainedInterceptor.onRuntimeUpdate(RuntimeLoopTick)
242+
chainedInterceptor.onRuntimeUpdate(RuntimeSettled)
243243
sendOutput(actionResult, onOutput)
244244
continue@outer
245245
}
@@ -295,7 +295,7 @@ public fun <PropsT, OutputT, RenderingT> renderWorkflowIn(
295295
// in case it is the last update!
296296
break@conflate
297297
}
298-
chainedInterceptor.onRuntimeUpdate(RuntimeLoopTick)
298+
chainedInterceptor.onRuntimeUpdate(RuntimeSettled)
299299
sendOutput(actionResult, onOutput)
300300
continue@outer
301301
}
@@ -310,7 +310,7 @@ public fun <PropsT, OutputT, RenderingT> renderWorkflowIn(
310310
renderingsAndSnapshots.value = nextRenderAndSnapshot.also {
311311
chainedInterceptor.onRuntimeUpdate(RenderingProduced)
312312
}
313-
chainedInterceptor.onRuntimeUpdate(RuntimeLoopTick)
313+
chainedInterceptor.onRuntimeUpdate(RuntimeSettled)
314314

315315
// Emit the Output
316316
sendOutput(actionResult, onOutput)

workflow-runtime/src/commonMain/kotlin/com/squareup/workflow1/WorkflowInterceptor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public interface WorkflowInterceptor {
188188
* The runtime has finished its work and is stable again - either skipping rendering because
189189
* of no change ([RenderPassSkipped]), or having passed a new rendering ([RenderingProduced]).
190190
*/
191-
public data object RuntimeLoopTick : RuntimeUpdate
191+
public data object RuntimeSettled : RuntimeUpdate
192192

193193
/**
194194
* Information about the session of a workflow in the runtime that a [WorkflowInterceptor] method

workflow-tracing-papa/src/main/java/com/squareup/workflow1/tracing/papa/WorkflowPapaTracer.kt

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import com.squareup.workflow1.Workflow
1010
import com.squareup.workflow1.WorkflowAction
1111
import com.squareup.workflow1.WorkflowInterceptor.RenderContextInterceptor
1212
import com.squareup.workflow1.WorkflowInterceptor.RenderPassSkipped
13-
import com.squareup.workflow1.WorkflowInterceptor.RuntimeLoopTick
13+
import com.squareup.workflow1.WorkflowInterceptor.RuntimeSettled
1414
import com.squareup.workflow1.WorkflowInterceptor.RuntimeUpdate
1515
import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession
1616
import com.squareup.workflow1.applyTo
@@ -154,26 +154,11 @@ class WorkflowPapaTracer(
154154
// Skipping, end the section started when renderIncomingCause was set.
155155
safeTrace.endSection()
156156
}
157-
if (runtimeUpdate == RuntimeLoopTick) {
157+
if (runtimeUpdate == RuntimeSettled) {
158158
// Build and add the summary!
159159
val summary = buildString {
160160
append("SUM${renderPassNumber()} ")
161-
append("Config:")
162-
if (configSnapshot.shortCircuitConfig) {
163-
append("ROWSC, ")
164-
}
165-
if (configSnapshot.csrConfig) {
166-
append("CSR, ")
167-
}
168-
if (configSnapshot.ptrConfig) {
169-
append("PTR, ")
170-
}
171-
if (!configSnapshot.shortCircuitConfig &&
172-
!configSnapshot.csrConfig &&
173-
!configSnapshot.ptrConfig
174-
) {
175-
append("Base, ")
176-
}
161+
append(configSnapshot.shortConfigAsString)
177162
append("StateChange:")
178163
if (currentActionHandlingChangedState) {
179164
append("Y, ")

workflow-tracing-papa/src/test/java/com/squareup/workflow1/tracing/papa/WorkflowPapaTracerTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import com.squareup.workflow1.Snapshot
77
import com.squareup.workflow1.StatefulWorkflow
88
import com.squareup.workflow1.TreeSnapshot
99
import com.squareup.workflow1.WorkflowInterceptor.RenderPassSkipped
10-
import com.squareup.workflow1.WorkflowInterceptor.RuntimeLoopTick
10+
import com.squareup.workflow1.WorkflowInterceptor.RuntimeSettled
1111
import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession
1212
import com.squareup.workflow1.identifier
1313
import com.squareup.workflow1.tracing.ConfigSnapshot
@@ -175,8 +175,8 @@ internal class WorkflowPapaTracerTest {
175175
// Should not throw for RenderPassSkipped
176176
papaTracer.onRuntimeUpdateEnhanced(RenderPassSkipped, false, configSnapshot)
177177

178-
// Should not throw for RuntimeLoopTick
179-
papaTracer.onRuntimeUpdateEnhanced(RuntimeLoopTick, true, configSnapshot)
178+
// Should not throw for RuntimeLoopSettled
179+
papaTracer.onRuntimeUpdateEnhanced(RuntimeSettled, true, configSnapshot)
180180
}
181181

182182
@Test

workflow-tracing-papa/src/test/java/com/squareup/workflow1/tracing/papa/WorkflowTracingIntegrationTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ internal class WorkflowTracingIntegrationTest {
330330
runtimeLoopMutex.lock()
331331

332332
// Verify that runtime loop listener was called
333-
assertTrue(runtimeListener.onRuntimeLoopTickCalled)
333+
assertTrue(runtimeListener.onRuntimeLoopSettledCalled)
334334
assertNotNull(runtimeListener.runtimeUpdatesReceived)
335335

336336
val traceCalls = fakeTrace.traceCalls
@@ -505,15 +505,15 @@ internal class WorkflowTracingIntegrationTest {
505505
private class TestWorkflowRuntimeLoopListener(
506506
val runtimeLoopMutex: Mutex,
507507
) : WorkflowRuntimeLoopListener {
508-
var onRuntimeLoopTickCalled = false
508+
var onRuntimeLoopSettledCalled = false
509509
var runtimeUpdatesReceived: RuntimeUpdates? = null
510510

511-
override fun onRuntimeLoopTick(
511+
override fun onRuntimeLoopSettled(
512512
configSnapshot: ConfigSnapshot,
513513
runtimeUpdates: RuntimeUpdates
514514
) {
515515
runtimeLoopMutex.unlock()
516-
onRuntimeLoopTickCalled = true
516+
onRuntimeLoopSettledCalled = true
517517
runtimeUpdatesReceived = runtimeUpdates
518518
}
519519
}

workflow-tracing/api/workflow-tracing.api

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ public final class com/squareup/workflow1/tracing/ChainedWorkflowRuntimeTracerKt
2727
public final class com/squareup/workflow1/tracing/ConfigSnapshot {
2828
public fun <init> (Ljava/util/Set;)V
2929
public final fun getConfigAsString ()Ljava/lang/String;
30-
public final fun getCsrConfig ()Z
31-
public final fun getDeaConfig ()Z
32-
public final fun getPtrConfig ()Z
33-
public final fun getSehConfig ()Z
34-
public final fun getShortCircuitConfig ()Z
35-
public final fun getWsdConfig ()Z
30+
public final fun getShortConfigAsString ()Ljava/lang/String;
3631
}
3732

3833
public abstract interface class com/squareup/workflow1/tracing/Loggable {
@@ -148,7 +143,7 @@ public abstract interface class com/squareup/workflow1/tracing/WorkflowRenderPas
148143
}
149144

150145
public abstract interface class com/squareup/workflow1/tracing/WorkflowRuntimeLoopListener {
151-
public abstract fun onRuntimeLoopTick (Lcom/squareup/workflow1/tracing/ConfigSnapshot;Lcom/squareup/workflow1/tracing/RuntimeUpdates;)V
146+
public abstract fun onRuntimeLoopSettled (Lcom/squareup/workflow1/tracing/ConfigSnapshot;Lcom/squareup/workflow1/tracing/RuntimeUpdates;)V
152147
}
153148

154149
public final class com/squareup/workflow1/tracing/WorkflowRuntimeMonitor : com/squareup/workflow1/WorkflowInterceptor, com/squareup/workflow1/tracing/RuntimeTraceContext {

workflow-tracing/src/main/java/com/squareup/workflow1/tracing/ConfigSnapshot.kt

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,32 @@ import com.squareup.workflow1.WorkflowExperimentalRuntime
1414
*/
1515
@OptIn(WorkflowExperimentalRuntime::class)
1616
public class ConfigSnapshot(config: RuntimeConfig) {
17-
val shortCircuitConfig = config.contains(RENDER_ONLY_WHEN_STATE_CHANGES)
18-
val csrConfig = config.contains(CONFLATE_STALE_RENDERINGS)
19-
val ptrConfig = config.contains(PARTIAL_TREE_RENDERING)
20-
val deaConfig = config.contains(DRAIN_EXCLUSIVE_ACTIONS)
21-
val sehConfig = config.contains(STABLE_EVENT_HANDLERS)
22-
val wsdConfig = config.contains(WORK_STEALING_DISPATCHER)
23-
2417
val configAsString = config.toString()
18+
19+
val shortConfigAsString by lazy {
20+
buildString {
21+
append("Config:")
22+
if (config.contains(RENDER_ONLY_WHEN_STATE_CHANGES)) {
23+
append("ROWSC, ")
24+
}
25+
if (config.contains(CONFLATE_STALE_RENDERINGS)) {
26+
append("CSR, ")
27+
}
28+
if (config.contains(PARTIAL_TREE_RENDERING)) {
29+
append("PTR, ")
30+
}
31+
if (config.contains(DRAIN_EXCLUSIVE_ACTIONS)) {
32+
append("DEA, ")
33+
}
34+
if (config.contains(STABLE_EVENT_HANDLERS)) {
35+
append("SEH, ")
36+
}
37+
if (config.contains(WORK_STEALING_DISPATCHER)) {
38+
append("SEH, ")
39+
}
40+
if (config.isEmpty()) {
41+
append("Base, ")
42+
}
43+
}
44+
}
2545
}

workflow-tracing/src/main/java/com/squareup/workflow1/tracing/WorkflowRuntimeLoopListener.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public fun interface WorkflowRuntimeLoopListener {
1313
* Called whenever the runtime loop completes with all the update events that have happened in
1414
* that loop.
1515
*/
16-
public fun onRuntimeLoopTick(
16+
public fun onRuntimeLoopSettled(
1717
configSnapshot: ConfigSnapshot,
1818
runtimeUpdates: RuntimeUpdates
1919
)

workflow-tracing/src/main/java/com/squareup/workflow1/tracing/WorkflowRuntimeMonitor.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import com.squareup.workflow1.WorkflowInterceptor.RenderContextInterceptor
1414
import com.squareup.workflow1.WorkflowInterceptor.RenderPassSkipped
1515
import com.squareup.workflow1.WorkflowInterceptor.RenderingConflated
1616
import com.squareup.workflow1.WorkflowInterceptor.RenderingProduced
17-
import com.squareup.workflow1.WorkflowInterceptor.RuntimeLoopTick
17+
import com.squareup.workflow1.WorkflowInterceptor.RuntimeSettled
1818
import com.squareup.workflow1.WorkflowInterceptor.RuntimeUpdate
1919
import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession
2020
import com.squareup.workflow1.applyTo
@@ -293,8 +293,8 @@ public class WorkflowRuntimeMonitor(
293293
// runtimeUpdates.logUpdate(ProducedLogLine)
294294
}
295295

296-
RuntimeLoopTick -> {
297-
runtimeLoopListener?.onRuntimeLoopTick(
296+
RuntimeSettled -> {
297+
runtimeLoopListener?.onRuntimeLoopSettled(
298298
configSnapshot,
299299
runtimeUpdates
300300
)

0 commit comments

Comments
 (0)