Skip to content

Commit 45fe6f3

Browse files
authored
feat: DH-19382: add server side timing to JsCommandResult (#7145)
Server side PR for DH-19382 Adds server side timing to `JsCommandResult` for query execution time Tested in deephaven/web-client-ui#2526
1 parent 664c402 commit 45fe6f3

File tree

7 files changed

+1203
-1133
lines changed

7 files changed

+1203
-1133
lines changed

go/internal/proto/console/console.pb.go

Lines changed: 1029 additions & 1006 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/proto-backplane-grpc/src/main/proto/deephaven_core/proto/console.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ message ExecuteCommandRequest {
121121
message ExecuteCommandResponse {
122122
string error_message = 1;
123123
io.deephaven.proto.backplane.grpc.FieldsChangeUpdate changes = 2;
124+
125+
// Start timestamp for command execution, in nanoseconds since the unix epoch.
126+
int64 start_timestamp = 3 [jstype=JS_STRING];
127+
// End timestamp for command execution, in nanoseconds since the unix epoch.
128+
int64 end_timestamp = 4 [jstype=JS_STRING];
124129
}
125130
message BindTableToVariableRequest {
126131
io.deephaven.proto.backplane.grpc.Ticket console_id = 1;

py/client/deephaven_core/proto/console_pb2.py

Lines changed: 127 additions & 123 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/src/main/java/io/deephaven/server/console/ConsoleServiceGrpcImpl.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.google.common.base.Throwables;
77
import com.google.rpc.Code;
88
import io.deephaven.base.LockFreeArrayQueue;
9+
import io.deephaven.base.clock.Clock;
910
import io.deephaven.configuration.Configuration;
1011
import io.deephaven.engine.context.ExecutionContext;
1112
import io.deephaven.engine.context.QueryScope;
@@ -197,6 +198,7 @@ public void executeCommand(
197198

198199
// If not set, we'll use defaults, otherwise we will explicitly set the systemicness.
199200
final ScriptSession.Changes changes;
201+
long startTimestamp = Clock.system().currentTimeNanos();
200202
switch (systemicOption) {
201203
case NOT_SET_SYSTEMIC:
202204
changes = scriptSession.evaluateScript(request.getCode());
@@ -213,6 +215,7 @@ public void executeCommand(
213215
throw new UnsupportedOperationException(
214216
"Unrecognized systemic option: " + systemicOption);
215217
}
218+
long endTimestamp = Clock.system().currentTimeNanos();
216219

217220
final ExecuteCommandResponse.Builder diff = ExecuteCommandResponse.newBuilder();
218221
final FieldsChangeUpdate.Builder fieldChanges = FieldsChangeUpdate.newBuilder();
@@ -226,7 +229,11 @@ public void executeCommand(
226229
diff.setErrorMessage(Throwables.getStackTraceAsString(changes.error));
227230
log.error().append("Error running script: ").append(changes.error).endl();
228231
}
229-
return diff.setChanges(fieldChanges).build();
232+
233+
return diff.setChanges(fieldChanges)
234+
.setStartTimestamp(startTimestamp)
235+
.setEndTimestamp(endTimestamp)
236+
.build();
230237
});
231238
}
232239
}

web/client-api/src/main/java/io/deephaven/web/client/api/console/JsCommandResult.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.vertispan.tsdefs.annotations.TsInterface;
77
import com.vertispan.tsdefs.annotations.TsName;
8+
import io.deephaven.web.client.api.DateWrapper;
89
import jsinterop.annotations.JsProperty;
910

1011
/**
@@ -15,10 +16,14 @@
1516
public class JsCommandResult {
1617
private final JsVariableChanges changes;
1718
private final String error;
19+
private final String startTimestamp;
20+
private final String endTimestamp;
1821

19-
public JsCommandResult(JsVariableChanges changes, String error) {
22+
public JsCommandResult(JsVariableChanges changes, String error, String startTimestamp, String endTimestamp) {
2023
this.changes = changes;
2124
this.error = error;
25+
this.startTimestamp = startTimestamp;
26+
this.endTimestamp = endTimestamp;
2227
}
2328

2429
/**
@@ -41,6 +46,26 @@ public String getError() {
4146
return error;
4247
}
4348

49+
/**
50+
* The timestamp when the command started running.
51+
*
52+
* @return DateWrapper
53+
*/
54+
@JsProperty
55+
public DateWrapper getStartTimestamp() {
56+
return DateWrapper.of(Long.parseLong(startTimestamp));
57+
}
58+
59+
/**
60+
* The timestamp when the command finished running.
61+
*
62+
* @return DateWrapper
63+
*/
64+
@JsProperty
65+
public DateWrapper getEndTimestamp() {
66+
return DateWrapper.of(Long.parseLong(endTimestamp));
67+
}
68+
4469
@Override
4570
public String toString() {
4671
if (error != null && !error.isEmpty()) {

web/client-api/src/main/java/io/deephaven/web/client/ide/IdeSession.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,12 @@ public CancellablePromise<JsCommandResult> runCode(String code) {
261261
});
262262
runCodePromise.then(response -> {
263263
JsVariableChanges changes = JsVariableChanges.from(response.getChanges());
264+
final String startTimestamp = response.getStartTimestamp();
265+
final String endTimestamp = response.getEndTimestamp();
264266
if (response.getErrorMessage() == null || response.getErrorMessage().isEmpty()) {
265-
promise.succeed(new JsCommandResult(changes, null));
267+
promise.succeed(new JsCommandResult(changes, null, startTimestamp, endTimestamp));
266268
} else {
267-
promise.succeed(new JsCommandResult(changes, response.getErrorMessage()));
269+
promise.succeed(new JsCommandResult(changes, response.getErrorMessage(), startTimestamp, endTimestamp));
268270
}
269271
return null;
270272
}, err -> {

web/client-backplane/src/main/java/io/deephaven/javascript/proto/dhinternal/io/deephaven_core/proto/console_pb/ExecuteCommandResponse.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@ public static native ExecuteCommandResponse.ToObjectReturnType toObject(
410410

411411
public native void setErrorMessage(String value);
412412

413+
public native String getStartTimestamp();
414+
415+
public native String getEndTimestamp();
416+
413417
public native ExecuteCommandResponse.ToObjectReturnType0 toObject();
414418

415419
public native ExecuteCommandResponse.ToObjectReturnType0 toObject(boolean includeInstance);

0 commit comments

Comments
 (0)