Skip to content

Commit cca80c9

Browse files
Merge pull request #1407 from square/sedwards/runtime-trace-cleanup
Follow-up cleanups from Runtime Tracing Upstream
2 parents d60b6e5 + 2d83cc4 commit cca80c9

File tree

13 files changed

+84
-84
lines changed

13 files changed

+84
-84
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)
17+
public val configAsString: String = config.toString()
2318

24-
val configAsString = config.toString()
19+
public val shortConfigAsString: String 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("WSD, ")
39+
}
40+
if (config.isEmpty()) {
41+
append("Base, ")
42+
}
43+
}
44+
}
2545
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ package com.squareup.workflow1.tracing
33
/**
44
* Interface abstracting tracing functionality to allow for testing with fake implementations.
55
*/
6-
interface SafeTraceInterface {
7-
val isTraceable: Boolean
8-
val isCurrentlyTracing: Boolean
6+
public interface SafeTraceInterface {
7+
public val isTraceable: Boolean
8+
public val isCurrentlyTracing: Boolean
99

10-
fun beginSection(label: String)
11-
fun endSection()
12-
fun beginAsyncSection(
10+
public fun beginSection(label: String)
11+
public fun endSection()
12+
public fun beginAsyncSection(
1313
name: String,
1414
cookie: Int
1515
)
1616

17-
fun endAsyncSection(
17+
public fun endAsyncSection(
1818
name: String,
1919
cookie: Int
2020
)
2121

22-
fun logSection(info: String)
22+
public fun logSection(info: String)
2323
}

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ import kotlin.time.Duration
66
* Can be passed to a [WorkflowRuntimeMonitor] to track each render pass as it happens, and the
77
* cause of it.
88
*/
9-
fun interface WorkflowRenderPassTracker {
9+
public fun interface WorkflowRenderPassTracker {
1010

1111
/**
1212
* Records that a render pass happened.
1313
*/
14-
fun recordRenderPass(renderPass: RenderPassInfo)
14+
public fun recordRenderPass(renderPass: RenderPassInfo)
1515
}
1616

1717
/**
1818
* A bundle of little info about a render pass.
1919
*/
20-
class RenderPassInfo(
21-
val runnerName: String,
22-
val renderCause: RenderCause,
23-
val durationUptime: Duration
20+
public class RenderPassInfo(
21+
public val runnerName: String,
22+
public val renderCause: RenderCause,
23+
public val durationUptime: Duration
2424
)
2525

2626
/**
@@ -43,8 +43,8 @@ public sealed interface RenderCause {
4343
* First creation of the root workflow for the runtime.
4444
*/
4545
public class RootCreation(
46-
val runnerName: String,
47-
val workflowName: String,
46+
public val runnerName: String,
47+
public val workflowName: String,
4848
) : RenderCause {
4949
override fun toString(): String {
5050
return "Creation of $runnerName root workflow $workflowName"
@@ -55,9 +55,9 @@ public sealed interface RenderCause {
5555
* An action was handled.
5656
*/
5757
public class Action(
58-
val actionName: String,
59-
val workerIncomingName: String?,
60-
val workflowName: String,
58+
public val actionName: String,
59+
public val workerIncomingName: String?,
60+
public val workflowName: String,
6161
) : RenderCause {
6262
override fun toString(): String {
6363
return "Output:A($actionName)/R($workerIncomingName)/W($workflowName)"
@@ -78,8 +78,8 @@ public sealed interface RenderCause {
7878
* A rendering callback was invoked.
7979
*/
8080
public class Callback(
81-
val actionName: String,
82-
val workflowName: String,
81+
public val actionName: String,
82+
public val workflowName: String,
8383
) : RenderCause {
8484
override fun toString(): String {
8585
return "Callback:A($actionName)/W($workflowName)"

0 commit comments

Comments
 (0)