Skip to content

Commit b217cbe

Browse files
committed
[RFC] Starting the debugging API
1 parent c62fb93 commit b217cbe

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

skipruntime-ts/native/src/Debug.sk

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Functions used by the debugging API
3+
*/
4+
5+
module SkipRuntime;
6+
7+
private fun dirInfo(
8+
dirNameDir: readonly (SKStore.DirName, SKStore.Dir),
9+
): SKJSON.CJSON {
10+
(dirName, dir) = dirNameDir;
11+
fields = mutable Vector<(.String, SKJSON.CJSON)>[];
12+
fields.push(("name", SKJSON.CJString(dirName.toString())));
13+
fields.push(("isInput", SKJSON.CJBool(dir.isInput())));
14+
fields.push(("time", SKJSON.CJInt(dir.getTime().value)));
15+
dir match {
16+
| SKStore.EagerDir{totalSize, creator} ->
17+
fields.push(("kind", SKJSON.CJString("eager")));
18+
fields.push(("totalSize", SKJSON.CJInt(totalSize)));
19+
creator match {
20+
| None() -> void
21+
| Some(SKStore.ArrowKey(parentName, childName, key)) ->
22+
fields.push(
23+
(
24+
"creator",
25+
SKJSON.CJObject(
26+
SKJSON.CJFields::create(
27+
Array[
28+
("key", SKJSON.CJString(key.toString())),
29+
("parent", SKJSON.CJString(parentName.toString())),
30+
("child", SKJSON.CJString(childName.toString())),
31+
],
32+
x -> x,
33+
),
34+
),
35+
),
36+
)
37+
}
38+
| SKStore.LazyDir _ -> fields.push(("kind", SKJSON.CJString("lazy")))
39+
| SKStore.DeletedDir _ -> fields.push(("kind", SKJSON.CJString("deleted")))
40+
};
41+
SKJSON.CJObject(SKJSON.CJFields::create(fields.toArray(), x -> x))
42+
}
43+
44+
private fun contextDirList(
45+
context: readonly SKStore.Context,
46+
): Array<SKJSON.CJSON> {
47+
context.dirs.state.items().map(dirInfo).collect(Array)
48+
}
49+
50+
module end;

skipruntime-ts/native/src/Extern.sk

+10
Original file line numberDiff line numberDiff line change
@@ -764,4 +764,14 @@ fun closeSkipRuntimeService(): Float {
764764
};
765765
}
766766

767+
/************ debugging ****************/
768+
769+
@export("SkipRuntime_Debug__dirList")
770+
fun dirList(): SKJSON.CJSON {
771+
SKStore.runWithResult(contextDirList) match {
772+
| Success(result) -> SKJSON.CJArray(result)
773+
| Failure(err) -> SKJSON.CJFloat(getErrorHdl(err))
774+
}
775+
}
776+
767777
module end;

skipruntime-ts/server/src/rest.ts

+11
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ export function controlService(service: ServiceInstance): express.Express {
109109
}
110110
});
111111

112+
// DEBUGGING
113+
app.get("/v1/debug/row/dirs", (_req, res) => {
114+
try {
115+
const result = service.dirList();
116+
res.status(200).json(result);
117+
} catch (e: unknown) {
118+
console.log(e);
119+
res.status(500).json(e instanceof Error ? e.message : e);
120+
}
121+
});
122+
112123
return app;
113124
}
114125

skipruntime-ts/wasm/src/internals/skipruntime_module.ts

+32
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,12 @@ export interface FromWasm {
373373
): ptr<Internal.Request>;
374374

375375
SkipRuntime_createChecker(ref: Handle<Checker>): ptr<Internal.Request>;
376+
377+
// Debug
378+
379+
SkipRuntime_Debug__dirList(): ptr<
380+
Internal.CJFloat | Internal.CJArray<Internal.CJObject>
381+
>;
376382
}
377383

378384
interface ToWasm {
@@ -1442,6 +1448,22 @@ export class ServiceInstance {
14421448
throw this.refs.handles.deleteAsError(result);
14431449
}
14441450
}
1451+
1452+
/**
1453+
* Debugging
1454+
*/
1455+
1456+
dirList(): DirList {
1457+
const result = this.refs.skjson.runWithGC(() => {
1458+
return this.refs.skjson.importJSON(
1459+
this.refs.fromWasm.SkipRuntime_Debug__dirList(),
1460+
);
1461+
});
1462+
if (typeof result == "number") {
1463+
throw this.refs.handles.deleteAsError(result as Handle<ErrorObject>);
1464+
}
1465+
return result as DirList;
1466+
}
14451467
}
14461468

14471469
class NonEmptyIteratorImpl<T> implements NonEmptyIterator<T> {
@@ -1489,6 +1511,16 @@ class NonEmptyIteratorImpl<T> implements NonEmptyIterator<T> {
14891511
}
14901512
}
14911513

1514+
type DirList = ({ name: string; isInput: boolean; time: int } & (
1515+
| {
1516+
kind: "eager";
1517+
totalSize: int;
1518+
creator?: { parent: string; child: string; key: string };
1519+
}
1520+
| { kind: "lazy" }
1521+
| { kind: "deleted" }
1522+
))[];
1523+
14921524
class Manager implements ToWasmManager {
14931525
constructor(private readonly env: Environment) {}
14941526

0 commit comments

Comments
 (0)