Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions workflow-runtime/api/workflow-runtime.api
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public final class com/squareup/workflow1/WorkflowInterceptor$RenderingProduced
public fun toString ()Ljava/lang/String;
}

public final class com/squareup/workflow1/WorkflowInterceptor$RuntimeLoopTick : com/squareup/workflow1/WorkflowInterceptor$RuntimeUpdate {
public static final field INSTANCE Lcom/squareup/workflow1/WorkflowInterceptor$RuntimeLoopTick;
public final class com/squareup/workflow1/WorkflowInterceptor$RuntimeSettled : com/squareup/workflow1/WorkflowInterceptor$RuntimeUpdate {
public static final field INSTANCE Lcom/squareup/workflow1/WorkflowInterceptor$RuntimeSettled;
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.squareup.workflow1.RuntimeConfigOptions.RENDER_ONLY_WHEN_STATE_CHANGE
import com.squareup.workflow1.WorkflowInterceptor.RenderPassSkipped
import com.squareup.workflow1.WorkflowInterceptor.RenderingConflated
import com.squareup.workflow1.WorkflowInterceptor.RenderingProduced
import com.squareup.workflow1.WorkflowInterceptor.RuntimeLoopTick
import com.squareup.workflow1.WorkflowInterceptor.RuntimeSettled
import com.squareup.workflow1.internal.WorkStealingDispatcher
import com.squareup.workflow1.internal.WorkflowRunner
import com.squareup.workflow1.internal.chained
Expand Down Expand Up @@ -176,7 +176,7 @@ public fun <PropsT, OutputT, RenderingT> renderWorkflowIn(
try {
runner.nextRendering().also {
chainedInterceptor.onRuntimeUpdate(RenderingProduced)
chainedInterceptor.onRuntimeUpdate(RuntimeLoopTick)
chainedInterceptor.onRuntimeUpdate(RuntimeSettled)
}
} catch (e: Throwable) {
// If any part of the workflow runtime fails, the scope should be cancelled. We're not in a
Expand Down Expand Up @@ -239,7 +239,7 @@ public fun <PropsT, OutputT, RenderingT> renderWorkflowIn(

if (shouldShortCircuitForUnchangedState(actionResult)) {
chainedInterceptor.onRuntimeUpdate(RenderPassSkipped)
chainedInterceptor.onRuntimeUpdate(RuntimeLoopTick)
chainedInterceptor.onRuntimeUpdate(RuntimeSettled)
sendOutput(actionResult, onOutput)
continue@outer
}
Expand Down Expand Up @@ -295,7 +295,7 @@ public fun <PropsT, OutputT, RenderingT> renderWorkflowIn(
// in case it is the last update!
break@conflate
}
chainedInterceptor.onRuntimeUpdate(RuntimeLoopTick)
chainedInterceptor.onRuntimeUpdate(RuntimeSettled)
sendOutput(actionResult, onOutput)
continue@outer
}
Expand All @@ -310,7 +310,7 @@ public fun <PropsT, OutputT, RenderingT> renderWorkflowIn(
renderingsAndSnapshots.value = nextRenderAndSnapshot.also {
chainedInterceptor.onRuntimeUpdate(RenderingProduced)
}
chainedInterceptor.onRuntimeUpdate(RuntimeLoopTick)
chainedInterceptor.onRuntimeUpdate(RuntimeSettled)

// Emit the Output
sendOutput(actionResult, onOutput)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public interface WorkflowInterceptor {
* The runtime has finished its work and is stable again - either skipping rendering because
* of no change ([RenderPassSkipped]), or having passed a new rendering ([RenderingProduced]).
*/
public data object RuntimeLoopTick : RuntimeUpdate
public data object RuntimeSettled : RuntimeUpdate

/**
* Information about the session of a workflow in the runtime that a [WorkflowInterceptor] method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.squareup.workflow1.Workflow
import com.squareup.workflow1.WorkflowAction
import com.squareup.workflow1.WorkflowInterceptor.RenderContextInterceptor
import com.squareup.workflow1.WorkflowInterceptor.RenderPassSkipped
import com.squareup.workflow1.WorkflowInterceptor.RuntimeLoopTick
import com.squareup.workflow1.WorkflowInterceptor.RuntimeSettled
import com.squareup.workflow1.WorkflowInterceptor.RuntimeUpdate
import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession
import com.squareup.workflow1.applyTo
Expand Down Expand Up @@ -154,26 +154,11 @@ class WorkflowPapaTracer(
// Skipping, end the section started when renderIncomingCause was set.
safeTrace.endSection()
}
if (runtimeUpdate == RuntimeLoopTick) {
if (runtimeUpdate == RuntimeSettled) {
// Build and add the summary!
val summary = buildString {
append("SUM${renderPassNumber()} ")
append("Config:")
if (configSnapshot.shortCircuitConfig) {
append("ROWSC, ")
}
if (configSnapshot.csrConfig) {
append("CSR, ")
}
if (configSnapshot.ptrConfig) {
append("PTR, ")
}
if (!configSnapshot.shortCircuitConfig &&
!configSnapshot.csrConfig &&
!configSnapshot.ptrConfig
) {
append("Base, ")
}
append(configSnapshot.shortConfigAsString)
append("StateChange:")
if (currentActionHandlingChangedState) {
append("Y, ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.squareup.workflow1.Snapshot
import com.squareup.workflow1.StatefulWorkflow
import com.squareup.workflow1.TreeSnapshot
import com.squareup.workflow1.WorkflowInterceptor.RenderPassSkipped
import com.squareup.workflow1.WorkflowInterceptor.RuntimeLoopTick
import com.squareup.workflow1.WorkflowInterceptor.RuntimeSettled
import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession
import com.squareup.workflow1.identifier
import com.squareup.workflow1.tracing.ConfigSnapshot
Expand Down Expand Up @@ -175,8 +175,8 @@ internal class WorkflowPapaTracerTest {
// Should not throw for RenderPassSkipped
papaTracer.onRuntimeUpdateEnhanced(RenderPassSkipped, false, configSnapshot)

// Should not throw for RuntimeLoopTick
papaTracer.onRuntimeUpdateEnhanced(RuntimeLoopTick, true, configSnapshot)
// Should not throw for RuntimeLoopSettled
papaTracer.onRuntimeUpdateEnhanced(RuntimeSettled, true, configSnapshot)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ internal class WorkflowTracingIntegrationTest {
runtimeLoopMutex.lock()

// Verify that runtime loop listener was called
assertTrue(runtimeListener.onRuntimeLoopTickCalled)
assertTrue(runtimeListener.onRuntimeLoopSettledCalled)
assertNotNull(runtimeListener.runtimeUpdatesReceived)

val traceCalls = fakeTrace.traceCalls
Expand Down Expand Up @@ -505,15 +505,15 @@ internal class WorkflowTracingIntegrationTest {
private class TestWorkflowRuntimeLoopListener(
val runtimeLoopMutex: Mutex,
) : WorkflowRuntimeLoopListener {
var onRuntimeLoopTickCalled = false
var onRuntimeLoopSettledCalled = false
var runtimeUpdatesReceived: RuntimeUpdates? = null

override fun onRuntimeLoopTick(
override fun onRuntimeLoopSettled(
configSnapshot: ConfigSnapshot,
runtimeUpdates: RuntimeUpdates
) {
runtimeLoopMutex.unlock()
onRuntimeLoopTickCalled = true
onRuntimeLoopSettledCalled = true
runtimeUpdatesReceived = runtimeUpdates
}
}
Expand Down
9 changes: 2 additions & 7 deletions workflow-tracing/api/workflow-tracing.api
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ public final class com/squareup/workflow1/tracing/ChainedWorkflowRuntimeTracerKt
public final class com/squareup/workflow1/tracing/ConfigSnapshot {
public fun <init> (Ljava/util/Set;)V
public final fun getConfigAsString ()Ljava/lang/String;
public final fun getCsrConfig ()Z
public final fun getDeaConfig ()Z
public final fun getPtrConfig ()Z
public final fun getSehConfig ()Z
public final fun getShortCircuitConfig ()Z
public final fun getWsdConfig ()Z
public final fun getShortConfigAsString ()Ljava/lang/String;
}

public abstract interface class com/squareup/workflow1/tracing/Loggable {
Expand Down Expand Up @@ -148,7 +143,7 @@ public abstract interface class com/squareup/workflow1/tracing/WorkflowRenderPas
}

public abstract interface class com/squareup/workflow1/tracing/WorkflowRuntimeLoopListener {
public abstract fun onRuntimeLoopTick (Lcom/squareup/workflow1/tracing/ConfigSnapshot;Lcom/squareup/workflow1/tracing/RuntimeUpdates;)V
public abstract fun onRuntimeLoopSettled (Lcom/squareup/workflow1/tracing/ConfigSnapshot;Lcom/squareup/workflow1/tracing/RuntimeUpdates;)V
}

public final class com/squareup/workflow1/tracing/WorkflowRuntimeMonitor : com/squareup/workflow1/WorkflowInterceptor, com/squareup/workflow1/tracing/RuntimeTraceContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,32 @@ import com.squareup.workflow1.WorkflowExperimentalRuntime
*/
@OptIn(WorkflowExperimentalRuntime::class)
public class ConfigSnapshot(config: RuntimeConfig) {
val shortCircuitConfig = config.contains(RENDER_ONLY_WHEN_STATE_CHANGES)
val csrConfig = config.contains(CONFLATE_STALE_RENDERINGS)
val ptrConfig = config.contains(PARTIAL_TREE_RENDERING)
val deaConfig = config.contains(DRAIN_EXCLUSIVE_ACTIONS)
val sehConfig = config.contains(STABLE_EVENT_HANDLERS)
val wsdConfig = config.contains(WORK_STEALING_DISPATCHER)
public val configAsString: String = config.toString()

val configAsString = config.toString()
public val shortConfigAsString: String by lazy {
buildString {
append("Config:")
if (config.contains(RENDER_ONLY_WHEN_STATE_CHANGES)) {
append("ROWSC, ")
}
if (config.contains(CONFLATE_STALE_RENDERINGS)) {
append("CSR, ")
}
if (config.contains(PARTIAL_TREE_RENDERING)) {
append("PTR, ")
}
if (config.contains(DRAIN_EXCLUSIVE_ACTIONS)) {
append("DEA, ")
}
if (config.contains(STABLE_EVENT_HANDLERS)) {
append("SEH, ")
}
if (config.contains(WORK_STEALING_DISPATCHER)) {
append("WSD, ")
}
if (config.isEmpty()) {
append("Base, ")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ package com.squareup.workflow1.tracing
/**
* Interface abstracting tracing functionality to allow for testing with fake implementations.
*/
interface SafeTraceInterface {
val isTraceable: Boolean
val isCurrentlyTracing: Boolean
public interface SafeTraceInterface {
public val isTraceable: Boolean
public val isCurrentlyTracing: Boolean

fun beginSection(label: String)
fun endSection()
fun beginAsyncSection(
public fun beginSection(label: String)
public fun endSection()
public fun beginAsyncSection(
name: String,
cookie: Int
)

fun endAsyncSection(
public fun endAsyncSection(
name: String,
cookie: Int
)

fun logSection(info: String)
public fun logSection(info: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import kotlin.time.Duration
* Can be passed to a [WorkflowRuntimeMonitor] to track each render pass as it happens, and the
* cause of it.
*/
fun interface WorkflowRenderPassTracker {
public fun interface WorkflowRenderPassTracker {

/**
* Records that a render pass happened.
*/
fun recordRenderPass(renderPass: RenderPassInfo)
public fun recordRenderPass(renderPass: RenderPassInfo)
}

/**
* A bundle of little info about a render pass.
*/
class RenderPassInfo(
val runnerName: String,
val renderCause: RenderCause,
val durationUptime: Duration
public class RenderPassInfo(
public val runnerName: String,
public val renderCause: RenderCause,
public val durationUptime: Duration
)

/**
Expand All @@ -43,8 +43,8 @@ public sealed interface RenderCause {
* First creation of the root workflow for the runtime.
*/
public class RootCreation(
val runnerName: String,
val workflowName: String,
public val runnerName: String,
public val workflowName: String,
) : RenderCause {
override fun toString(): String {
return "Creation of $runnerName root workflow $workflowName"
Expand All @@ -55,9 +55,9 @@ public sealed interface RenderCause {
* An action was handled.
*/
public class Action(
val actionName: String,
val workerIncomingName: String?,
val workflowName: String,
public val actionName: String,
public val workerIncomingName: String?,
public val workflowName: String,
) : RenderCause {
override fun toString(): String {
return "Output:A($actionName)/R($workerIncomingName)/W($workflowName)"
Expand All @@ -78,8 +78,8 @@ public sealed interface RenderCause {
* A rendering callback was invoked.
*/
public class Callback(
val actionName: String,
val workflowName: String,
public val actionName: String,
public val workflowName: String,
) : RenderCause {
override fun toString(): String {
return "Callback:A($actionName)/W($workflowName)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public fun interface WorkflowRuntimeLoopListener {
* Called whenever the runtime loop completes with all the update events that have happened in
* that loop.
*/
public fun onRuntimeLoopTick(
public fun onRuntimeLoopSettled(
configSnapshot: ConfigSnapshot,
runtimeUpdates: RuntimeUpdates
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.squareup.workflow1.WorkflowInterceptor.RenderContextInterceptor
import com.squareup.workflow1.WorkflowInterceptor.RenderPassSkipped
import com.squareup.workflow1.WorkflowInterceptor.RenderingConflated
import com.squareup.workflow1.WorkflowInterceptor.RenderingProduced
import com.squareup.workflow1.WorkflowInterceptor.RuntimeLoopTick
import com.squareup.workflow1.WorkflowInterceptor.RuntimeSettled
import com.squareup.workflow1.WorkflowInterceptor.RuntimeUpdate
import com.squareup.workflow1.WorkflowInterceptor.WorkflowSession
import com.squareup.workflow1.applyTo
Expand Down Expand Up @@ -293,8 +293,8 @@ public class WorkflowRuntimeMonitor(
// runtimeUpdates.logUpdate(ProducedLogLine)
}

RuntimeLoopTick -> {
runtimeLoopListener?.onRuntimeLoopTick(
RuntimeSettled -> {
runtimeLoopListener?.onRuntimeLoopSettled(
configSnapshot,
runtimeUpdates
)
Expand Down
Loading
Loading