Skip to content

Commit

Permalink
Fix IPC span reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
TejasQ committed Nov 21, 2023
1 parent 5fc19ae commit 5787e70
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 27 deletions.
14 changes: 2 additions & 12 deletions web-client/src/components/span/span-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ import { processFieldValue } from "~/lib/span/process-field-value";
import { getChildrenList } from "~/lib/span/get-children-list";
import { SpanDetailTrace } from "./span-detail-trace";
import { SpanDetailArgs } from "./span-detail-args";

const ipcSpans = [
"ipc::request",
"ipc::request::deserialize_arg",
"ipc::request::run",
"ipc::request::respond",
"ipc::request::response",
"wry::eval",
];
import { isIpcSpanName } from "~/lib/span/isIpcSpanName";

export function SpanDetail() {
const [searchParams] = useSearchParams();
Expand All @@ -28,9 +20,7 @@ export function SpanDetail() {
return {
...s,
children: getChildrenList(monitorData.spans, s, (span) =>
ipcSpans.includes(
monitorData.metadata.get(span.metadataId)?.name ?? ""
)
isIpcSpanName(monitorData.metadata.get(span.metadataId)?.name ?? "")
),
};
}
Expand Down
17 changes: 2 additions & 15 deletions web-client/src/lib/span/get-ipc-request-value.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
import { Field, Metadata } from "../proto/common";
import { findSpansByName } from "./find-spans-by-name";
import { IpcSpanName } from "./ipc-spans";
import { SpanWithChildren } from "./types";

type SpanName =
/* tracks the whole duration of a req. fields: id = invoke ID and kind = "postmessage" */
| "ipc::request"
/* = the time it takes to deserialize the arguments. fields: id = invoke ID and args = string repo of the unparsed data */
| "ipc::request::deserialize_arg"
/* this gets emitted when we have found the right handler and are processing the request. fields: id= Invoke ID, cmd = the command name, kind the kind of command, loc.line the source code line of the handler, loc.col the source code column of the handler, is_internal = whether the command is internal to tauri or user defined */
| "ipc::request::handler"
/* this tracks the duration of the user written code that handles the request */
| "ipc::request::run"
/* tracks how much time it took to respond to the request (from the rust side) */
| "ipc::request::respond"
/* shows the actual response */
| "ipc::request::response";

type Options = {
metadata: Map<bigint, Metadata>;
rootSpan: SpanWithChildren;
};

export function getIpcRequestValues({ metadata, rootSpan }: Options) {
return function (name: SpanName) {
return function (name: IpcSpanName) {
const spans = findSpansByName({ span: rootSpan, metadata }, name);

if (!spans) {
Expand Down
34 changes: 34 additions & 0 deletions web-client/src/lib/span/ipc-spans.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export type IpcSpanName =
/* tracks the whole duration of a req. fields: id = invoke ID and kind = "postmessage" */
| "ipc::request"
/* = the time it takes to deserialize the arguments. fields: id = invoke ID and args = string repo of the unparsed data */
| "ipc::request::deserialize_arg"
/* this gets emitted when we have found the right handler and are processing the request. fields: id= Invoke ID, cmd = the command name, kind the kind of command, loc.line the source code line of the handler, loc.col the source code column of the handler, is_internal = whether the command is internal to tauri or user defined */
| "ipc::request::handler"
/* this tracks the duration of the user written code that handles the request */
| "ipc::request::run"
/* tracks how much time it took to respond to the request (from the rust side) */
| "ipc::request::respond"
/* shows the actual response */
| "ipc::request::response"
/* @todo describe 👇 */
| "wry::eval";

export const ipcSpans: IpcSpanName[] = [
"ipc::request",
"ipc::request::deserialize_arg",
"ipc::request::run",
"ipc::request::respond",
"ipc::request::response",
"wry::eval",
]

export const ipcSpanNameMap: Record<IpcSpanName, string> = {
"ipc::request": "Request",
"ipc::request::run": "Command Run",
"ipc::request::respond": "Response",
"wry::eval": "Eval Response",
"ipc::request::deserialize_arg": "Deserialize Args",
"ipc::request::handler": "Command Handler",
"ipc::request::response": "Response",
};
5 changes: 5 additions & 0 deletions web-client/src/lib/span/isIpcSpanName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { IpcSpanName, ipcSpans } from "./ipc-spans";

export const isIpcSpanName = (name: string): name is IpcSpanName => {
return ipcSpans.includes(name as unknown as IpcSpanName);
}

0 comments on commit 5787e70

Please sign in to comment.