Skip to content

Commit

Permalink
Log visualization expressions generated by IDE (#7756)
Browse files Browse the repository at this point in the history
close #7608

Changelog:
- update: log separately the evaluation of visualization expression and its arguments
- update: add visualization expression, its arguments, and the value type to the log

# Important Notes
Example

```
[TRACE] [2023-09-06T20:41:45+03:00] [enso] Executing visualization [VisualizationConfiguration(d195fdd8-d4e8-400f-a0d4-e50417eddd0a,ModuleMethod(MethodPointer(Standard.Visualization.Table.Visualization,Standard.Visualization.Table.Visualization,prepare_visualization),Vector(1000)),local.New_Project_1.Main)] on expression [ddc060df-9b59-48e5-bc61-aca849347343] of [class org.enso.interpreter.runtime.data.vector.Vector$Generic]...
```
  • Loading branch information
4e6 authored Sep 12, 2023
1 parent 8b6e70b commit e5425d3
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,8 @@ object Runtime {
)
)
sealed trait VisualizationExpression extends ToLogString {
def module: String
def module: String
def positionalArgumentsExpressions: Vector[String]
}
object VisualizationExpression {

Expand All @@ -619,11 +620,13 @@ object Runtime {
case class Text(module: String, expression: String)
extends VisualizationExpression {

override val positionalArgumentsExpressions: Vector[String] =
Vector()

/** @inheritdoc */
override def toLogString(shouldMask: Boolean): String =
s"Text(module=$module" +
s",expression=" +
(if (shouldMask) STUB else expression) +
s",expression=$expression" +
")"
}

Expand All @@ -644,9 +647,9 @@ object Runtime {
/** @inheritdoc */
override def toLogString(shouldMask: Boolean): String =
s"ModuleMethod(methodPointer=$methodPointer," +
s"positionalArgumentsExpressions=" +
(if (shouldMask) STUB else positionalArgumentsExpressions) +
s")"
"positionalArgumentsExpressions=" +
positionalArgumentsExpressions.mkString("[", ",", "]") +
")"
}
}

Expand All @@ -667,7 +670,7 @@ object Runtime {
s"VisualizationConfiguration(" +
s"executionContextId=$executionContextId," +
s"expression=${expression.toLogString(shouldMask)})" +
s"visualizationModule=${visualizationModule})"
s"visualizationModule=$visualizationModule)"
}

/** An operation applied to the suggestion argument. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ModifyVisualizationCmd(
existingVisualization.map(_.expressionId).orElse {
val jobFilter: PartialFunction[Job[_], Option[ExpressionId]] = {
case upsert: UpsertVisualizationJob
if upsert.getVisualizationId() == request.visualizationId =>
if upsert.visualizationId == request.visualizationId =>
Some(upsert.key)
}
ctx.jobControlPlane.jobInProgress(jobFilter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.enso.interpreter.instrument.execution.{
import org.enso.interpreter.instrument.profiling.ExecutionTime
import org.enso.interpreter.instrument._
import org.enso.interpreter.node.callable.FunctionCallInstrumentationNode.FunctionCall
import org.enso.interpreter.node.expression.builtin.meta.TypeOfNode
import org.enso.interpreter.runtime.`type`.Types
import org.enso.interpreter.runtime.callable.function.Function
import org.enso.interpreter.runtime.control.ThreadInterruptedException
Expand All @@ -34,7 +35,9 @@ import java.io.File
import java.util.UUID
import java.util.function.Consumer
import java.util.logging.Level

import scala.jdk.OptionConverters._
import scala.util.Try

/** Provides support for executing Enso code. Adds convenient methods to
* run Enso programs in a Truffle context.
Expand Down Expand Up @@ -483,8 +486,14 @@ object ProgramExecutionSupport {
Either
.catchNonFatal {
ctx.executionService.getLogger.log(
Level.FINE,
s"Executing visualization ${visualization.expressionId}"
Level.FINEST,
"Executing visualization [{0}] on expression [{1}] of [{2}]...",
Array[Object](
visualization.config,
expressionId,
Try(TypeOfNode.getUncached.execute(expressionValue))
.getOrElse(expressionValue.getClass)
)
)
ctx.executionService.callFunctionWithInstrument(
visualization.cache,
Expand All @@ -496,18 +505,21 @@ object ProgramExecutionSupport {
.flatMap(visualizationResultToBytes)
val result = errorOrVisualizationData match {
case Left(_: ThreadInterruptedException) =>
ctx.executionService.getLogger.log(
Level.FINE,
s"Visualization thread interrupted ${visualization.expressionId}."
)
Completion.Interrupted

case Left(error) =>
val message =
Option(error.getMessage).getOrElse(error.getClass.getSimpleName)
ctx.executionService.getLogger.log(
Level.WARNING,
s"Visualization evaluation failed: $message."
"Execution of visualization [{0}] on value [{1}] of [{2}] failed.",
Array[Object](
visualization.config,
expressionId,
Try(TypeOfNode.getUncached.execute(expressionValue))
.getOrElse(expressionValue.getClass),
error
)
)
ctx.endpoint.sendToClient(
Api.Response(
Expand All @@ -525,7 +537,8 @@ object ProgramExecutionSupport {
case Right(data) =>
ctx.executionService.getLogger.log(
Level.FINEST,
s"Visualization computed ${visualization.expressionId}."
s"Visualization executed [{0}].",
expressionId
)
ctx.endpoint.sendToClient(
Api.Response(
Expand Down
Loading

0 comments on commit e5425d3

Please sign in to comment.