|
1 | | -/** Creates a new `RTrace` instance, tracking allocations, frees and reference counts. */ |
2 | | -declare function rtrace( |
| 1 | +/** Block information. */ |
| 2 | +export declare interface BlockInfo { |
| 3 | + /** Pointer to the block. */ |
| 4 | + ptr: number, |
| 5 | + /** Block size. */ |
| 6 | + size: number, |
| 7 | + /** Runtime header. */ |
| 8 | + header: { |
| 9 | + /** Memory manager info bits. */ |
| 10 | + mmInfo: number, |
| 11 | + /** Garbage collector info bits. */ |
| 12 | + gcInfo: number, |
| 13 | + /** Runtime id. */ |
| 14 | + rtId: number, |
| 15 | + /** Runtime size. */ |
| 16 | + rtSize: number |
| 17 | + }, |
| 18 | + toString(): string |
| 19 | +} |
| 20 | + |
| 21 | +export declare interface RtraceOptions { |
3 | 22 | /** Function being called when a problem is detected. */ |
4 | | - onerror?: (error: Error) => void, |
| 23 | + onerror?: (error: Error, info: BlockInfo) => void, |
5 | 24 | /** Function being called with information messages. */ |
6 | | - oninfo?: (info: string) => void |
7 | | -): rtrace.RTrace; |
8 | | - |
9 | | -declare namespace rtrace { |
10 | | - /** The rtrace instance used as the `rtrace` import to the Wasm module. */ |
11 | | - export interface RTrace { |
12 | | - /** Number of allocations so far. */ |
13 | | - allocCount: number; |
14 | | - /** Number of reallocations so far. */ |
15 | | - reallocCount: number; |
16 | | - /** Number of frees so far. */ |
17 | | - freeCount: number; |
18 | | - /** Number of RC increments (retains) so far. */ |
19 | | - incrementCount: number; |
20 | | - /** Number of RC decrements (releases) so far. */ |
21 | | - decrementCount: number; |
22 | | - |
23 | | - /** Called when a new block is allocated. */ |
24 | | - onalloc( |
25 | | - /** New block being allocated. */ |
26 | | - block: number |
27 | | - ): void; |
28 | | - |
29 | | - /** Called when a block is reallocated and must be moved. */ |
30 | | - onrealloc( |
31 | | - /** Block being moved. */ |
32 | | - oldBlock: number, |
33 | | - /** New block used from now on. */ |
34 | | - newBlock: number |
35 | | - ): void; |
36 | | - |
37 | | - /** Called when a block is freed, implicitly or explicitly. */ |
38 | | - onfree( |
39 | | - /** Block being freed. */ |
40 | | - block: number |
41 | | - ): void; |
| 25 | + oninfo?: (msg: string) => void, |
| 26 | + /** Obtains the module's memory instance. */ |
| 27 | + getMemory() |
| 28 | +} |
42 | 29 |
|
43 | | - /** Called when a reference to a block is retained (RC incremented by one). */ |
44 | | - onincrement( |
45 | | - /** Block a reference to is being retained. */ |
46 | | - block: number |
47 | | - ): void; |
| 30 | +export declare class Rtrace { |
| 31 | + [key: string]: unknown; // can be used as a Wasm import |
48 | 32 |
|
49 | | - /** Called when a reference to a block is released (RC decremented by one). */ |
50 | | - ondecrement( |
51 | | - /** Block a reference to is being released. */ |
52 | | - block: number |
53 | | - ): void; |
| 33 | + /** Creates a new `RTrace` instance. */ |
| 34 | + constructor(options: RtraceOptions); |
54 | 35 |
|
55 | | - /** Checks if rtrace is active, i.e. at least one event has occurred. */ |
56 | | - readonly active: boolean; |
| 36 | + /** Checks if rtrace is active, i.e. at least one event has occurred. */ |
| 37 | + readonly active: boolean; |
57 | 38 |
|
58 | | - /** Checks if there are any leaks and emits them via `oninfo`. Returns the number of live blocks. */ |
59 | | - check(): number; |
60 | | - } |
| 39 | + /** Checks if there are any leaks and emits them via `oninfo`. Returns the number of live blocks. */ |
| 40 | + check(): number; |
61 | 41 | } |
62 | | - |
63 | | -export = rtrace; |
0 commit comments