Skip to content

Commit

Permalink
streaming profiling (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity authored Oct 17, 2023
1 parent 5be80b9 commit 3b25ba0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tools/ui/src/candid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export async function fetchActor(canisterId: Principal): Promise<ActorSubclass>

export function getProfilerActor(canisterId: Principal): ActorSubclass {
const profiler_interface: IDL.InterfaceFactory = ({ IDL }) => IDL.Service({
__get_profiling: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Int32, IDL.Int64))], ['query']),
__get_profiling: IDL.Func([IDL.Int32], [IDL.Vec(IDL.Tuple(IDL.Int32, IDL.Int64)), IDL.Opt(IDL.Int32)], ['query']),
__get_cycles: IDL.Func([], [IDL.Int64], ['query']),
});
return Actor.createActor(profiler_interface, { agent, canisterId });
Expand Down Expand Up @@ -155,7 +155,19 @@ async function getDidJsFromMetadata(canisterId: Principal): Promise<undefined |
export async function getProfiling(canisterId: Principal): Promise<Array<[number, bigint]>|undefined> {
try {
const actor = getProfilerActor(canisterId);
const info = await actor.__get_profiling() as Array<[number, bigint]>;
let info: Array<[number, bigint]> = [];
let idx = 0;
let cnt = 0;
while (cnt < 50) {
const [res, next] = await actor.__get_profiling(idx) as [Array<[number, bigint]>, [number]|[]];
info = info.concat(res);
if (next.length === 1) {
idx = next[0];
cnt++;
} else {
break;
}
}
return info;
} catch(err) {
console.log(err);
Expand Down

0 comments on commit 3b25ba0

Please sign in to comment.