ic-mops 0.31.1 → 0.31.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/bench/bench-canister.mo +94 -0
- package/dist/commands/bench/user-bench.mo +14 -0
- package/dist/commands/bench.d.ts +11 -0
- package/dist/commands/bench.js +268 -0
- package/dist/declarations/bench/bench.did +26 -0
- package/dist/declarations/bench/bench.did.d.ts +26 -0
- package/dist/declarations/bench/bench.did.js +26 -0
- package/dist/declarations/bench/index.d.ts +50 -0
- package/dist/declarations/bench/index.js +41 -0
- package/dist/helpers/get-dfx-version.d.ts +1 -0
- package/dist/helpers/get-dfx-version.js +9 -0
- package/dist/helpers/get-moc-path.d.ts +1 -0
- package/dist/helpers/get-moc-path.js +11 -0
- package/dist/helpers/get-moc-version.d.ts +1 -0
- package/dist/helpers/get-moc-version.js +7 -0
- package/dist/package.json +1 -1
- package/dist/resolve-packages.js +1 -1
- package/dist/vessel.d.ts +2 -1
- package/dist/vessel.js +9 -7
- package/package.json +1 -1
- package/resolve-packages.ts +1 -1
- package/vessel.ts +10 -8
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import Nat64 "mo:base/Nat64";
|
|
2
|
+
import Nat "mo:base/Nat";
|
|
3
|
+
import Debug "mo:base/Debug";
|
|
4
|
+
import ExperimentalInternetComputer "mo:base/ExperimentalInternetComputer";
|
|
5
|
+
import Prim "mo:prim";
|
|
6
|
+
import Bench "mo:bench";
|
|
7
|
+
|
|
8
|
+
import UserBench "./user-bench";
|
|
9
|
+
|
|
10
|
+
actor class() {
|
|
11
|
+
var benchOpt : ?Bench.Bench = null;
|
|
12
|
+
|
|
13
|
+
public func init() : async Bench.BenchSchema {
|
|
14
|
+
let bench = UserBench.init();
|
|
15
|
+
benchOpt := ?bench;
|
|
16
|
+
bench.getSchema();
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
public query func getSchema() : async Bench.BenchSchema {
|
|
20
|
+
let ?bench = benchOpt else Debug.trap("bench not initialized");
|
|
21
|
+
bench.getSchema();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
func _getStats() : Bench.BenchResult {
|
|
25
|
+
{
|
|
26
|
+
instructions = 0;
|
|
27
|
+
rts_heap_size = Prim.rts_heap_size();
|
|
28
|
+
rts_memory_size = Prim.rts_memory_size();
|
|
29
|
+
rts_total_allocation = Prim.rts_total_allocation();
|
|
30
|
+
rts_mutator_instructions = Prim.rts_mutator_instructions();
|
|
31
|
+
rts_collector_instructions = Prim.rts_collector_instructions();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
func _runCell(rowIndex : Nat, colIndex : Nat) : Bench.BenchResult {
|
|
36
|
+
let ?bench = benchOpt else Debug.trap("bench not initialized");
|
|
37
|
+
let statsBefore = _getStats();
|
|
38
|
+
|
|
39
|
+
let instructions = ExperimentalInternetComputer.countInstructions(func() {
|
|
40
|
+
bench.runCell(rowIndex, colIndex);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// await (func() : async () {})();
|
|
44
|
+
|
|
45
|
+
let statsAfter = _getStats();
|
|
46
|
+
|
|
47
|
+
{
|
|
48
|
+
instructions = Nat64.toNat(instructions);
|
|
49
|
+
rts_heap_size = statsAfter.rts_heap_size - statsBefore.rts_heap_size;
|
|
50
|
+
rts_memory_size = statsAfter.rts_memory_size - statsBefore.rts_memory_size;
|
|
51
|
+
rts_total_allocation = statsAfter.rts_total_allocation - statsBefore.rts_total_allocation;
|
|
52
|
+
rts_mutator_instructions = statsAfter.rts_mutator_instructions - statsBefore.rts_mutator_instructions;
|
|
53
|
+
rts_collector_instructions = statsAfter.rts_collector_instructions - statsBefore.rts_collector_instructions;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
func _runCellAwait(rowIndex : Nat, colIndex : Nat) : async Bench.BenchResult {
|
|
58
|
+
let ?bench = benchOpt else Debug.trap("bench not initialized");
|
|
59
|
+
let statsBefore = _getStats();
|
|
60
|
+
|
|
61
|
+
let instructions = ExperimentalInternetComputer.countInstructions(func() {
|
|
62
|
+
bench.runCell(rowIndex, colIndex);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
await (func() : async () {})();
|
|
66
|
+
|
|
67
|
+
let statsAfter = _getStats();
|
|
68
|
+
|
|
69
|
+
{
|
|
70
|
+
instructions = Nat64.toNat(instructions);
|
|
71
|
+
rts_heap_size = statsAfter.rts_heap_size - statsBefore.rts_heap_size;
|
|
72
|
+
rts_memory_size = statsAfter.rts_memory_size - statsBefore.rts_memory_size;
|
|
73
|
+
rts_total_allocation = statsAfter.rts_total_allocation - statsBefore.rts_total_allocation;
|
|
74
|
+
rts_mutator_instructions = statsAfter.rts_mutator_instructions - statsBefore.rts_mutator_instructions;
|
|
75
|
+
rts_collector_instructions = statsAfter.rts_collector_instructions - statsBefore.rts_collector_instructions;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
public query func getStats() : async Bench.BenchResult {
|
|
80
|
+
_getStats();
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
public query func runCellQuery(rowIndex : Nat, colIndex : Nat) : async Bench.BenchResult {
|
|
84
|
+
_runCell(rowIndex, colIndex);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
public func runCellUpdate(rowIndex : Nat, colIndex : Nat) : async Bench.BenchResult {
|
|
88
|
+
await _runCellAwait(rowIndex, colIndex);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
public func runCellUpdateAwait(rowIndex : Nat, colIndex : Nat) : async Bench.BenchResult {
|
|
92
|
+
_runCell(rowIndex, colIndex);
|
|
93
|
+
};
|
|
94
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Nat "mo:base/Nat";
|
|
2
|
+
import Iter "mo:base/Iter";
|
|
3
|
+
import Buffer "mo:base/Buffer";
|
|
4
|
+
import Vector "mo:vector/Class";
|
|
5
|
+
import Bench "mo:bench";
|
|
6
|
+
|
|
7
|
+
// placeholder file that will be replaced with the *.bench.mo file
|
|
8
|
+
module {
|
|
9
|
+
public func init() : Bench.Bench {
|
|
10
|
+
let bench = Bench.Bench();
|
|
11
|
+
// benchmark code goes here...
|
|
12
|
+
bench;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type BenchOptions = {
|
|
2
|
+
dfx?: string;
|
|
3
|
+
moc?: string;
|
|
4
|
+
gc?: 'copying' | 'compacting' | 'generational' | 'incremental';
|
|
5
|
+
forceGc?: boolean;
|
|
6
|
+
save?: boolean;
|
|
7
|
+
compare?: boolean;
|
|
8
|
+
verbose?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function bench(filter?: string, options?: BenchOptions): Promise<boolean>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import { globSync } from 'glob';
|
|
7
|
+
import { markdownTable } from 'markdown-table';
|
|
8
|
+
import logUpdate from 'log-update';
|
|
9
|
+
import { getRootDir } from '../mops.js';
|
|
10
|
+
import { parallel } from '../parallel.js';
|
|
11
|
+
import { createActor } from '../declarations/bench/index.js';
|
|
12
|
+
import { absToRel } from './test/utils.js';
|
|
13
|
+
import { getMocVersion } from '../helpers/get-moc-version.js';
|
|
14
|
+
import { getDfxVersion } from '../helpers/get-dfx-version.js';
|
|
15
|
+
import { getMocPath } from '../helpers/get-moc-path.js';
|
|
16
|
+
import { sources } from './sources.js';
|
|
17
|
+
import { execaCommand } from 'execa';
|
|
18
|
+
let ignore = [
|
|
19
|
+
'**/node_modules/**',
|
|
20
|
+
'**/.mops/**',
|
|
21
|
+
'**/.vessel/**',
|
|
22
|
+
'**/.git/**',
|
|
23
|
+
];
|
|
24
|
+
let globConfig = {
|
|
25
|
+
nocase: true,
|
|
26
|
+
ignore: ignore,
|
|
27
|
+
};
|
|
28
|
+
export async function bench(filter = '', options = {}) {
|
|
29
|
+
let defaultOptions = {
|
|
30
|
+
moc: getMocVersion(),
|
|
31
|
+
dfx: getDfxVersion(),
|
|
32
|
+
gc: 'incremental',
|
|
33
|
+
forceGc: true,
|
|
34
|
+
save: false,
|
|
35
|
+
compare: false,
|
|
36
|
+
verbose: false,
|
|
37
|
+
};
|
|
38
|
+
options = { ...defaultOptions, ...options };
|
|
39
|
+
console.log(options);
|
|
40
|
+
let rootDir = getRootDir();
|
|
41
|
+
let globStr = '**/bench?(mark)/**/*.bench.mo';
|
|
42
|
+
if (filter) {
|
|
43
|
+
globStr = `**/bench?(mark)/**/*${filter}*.mo`;
|
|
44
|
+
}
|
|
45
|
+
let files = globSync(path.join(rootDir, globStr), globConfig);
|
|
46
|
+
if (!files.length) {
|
|
47
|
+
if (filter) {
|
|
48
|
+
console.log(`No benchmark files found for filter '${filter}'`);
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
console.log('No *.bench.mo files found');
|
|
52
|
+
console.log('Put your benchmark code in \'bench\' directory in *.bench.mo files');
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
files.sort();
|
|
56
|
+
let benchDir = `${getRootDir()}/.mops/.bench/`;
|
|
57
|
+
fs.rmSync(benchDir, { recursive: true, force: true });
|
|
58
|
+
fs.mkdirSync(benchDir, { recursive: true });
|
|
59
|
+
console.log('Benchmark files:');
|
|
60
|
+
for (let file of files) {
|
|
61
|
+
console.log(chalk.gray(`• ${absToRel(file)}`));
|
|
62
|
+
}
|
|
63
|
+
console.log('');
|
|
64
|
+
console.log('='.repeat(50));
|
|
65
|
+
console.log('');
|
|
66
|
+
console.log('Starting dfx replica...');
|
|
67
|
+
startDfx(options.verbose);
|
|
68
|
+
console.log('Deploying canisters...');
|
|
69
|
+
await parallel(os.cpus().length, files, async (file) => {
|
|
70
|
+
await deployBenchFile(file, options);
|
|
71
|
+
});
|
|
72
|
+
await parallel(1, files, async (file) => {
|
|
73
|
+
console.log('\n' + '—'.repeat(50));
|
|
74
|
+
console.log(`\nRunning ${chalk.gray(absToRel(file))}...`);
|
|
75
|
+
console.log('');
|
|
76
|
+
try {
|
|
77
|
+
await runBenchFile(file, options);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
console.error('Unexpected error. Stopping dfx replica...');
|
|
81
|
+
stopDfx(options.verbose);
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
console.log('Stopping dfx replica...');
|
|
86
|
+
stopDfx(options.verbose);
|
|
87
|
+
fs.rmSync(benchDir, { recursive: true, force: true });
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
function getMocArgs(options) {
|
|
91
|
+
let args = '';
|
|
92
|
+
if (options.forceGc) {
|
|
93
|
+
args += ' --force-gc';
|
|
94
|
+
}
|
|
95
|
+
if (options.gc) {
|
|
96
|
+
args += ` --${options.gc}-gc`;
|
|
97
|
+
}
|
|
98
|
+
return args;
|
|
99
|
+
}
|
|
100
|
+
function dfxJson(canisterName, options = {}) {
|
|
101
|
+
options || console.log(options);
|
|
102
|
+
let canisters = {};
|
|
103
|
+
if (canisterName) {
|
|
104
|
+
canisters[canisterName] = {
|
|
105
|
+
type: 'custom',
|
|
106
|
+
wasm: 'canister.wasm',
|
|
107
|
+
candid: 'canister.did',
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
version: 1,
|
|
112
|
+
canisters,
|
|
113
|
+
defaults: {
|
|
114
|
+
build: {
|
|
115
|
+
packtool: 'mops sources',
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
networks: {
|
|
119
|
+
local: {
|
|
120
|
+
type: 'ephemeral',
|
|
121
|
+
bind: '127.0.0.1:4947',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function startDfx(verbose = false) {
|
|
127
|
+
stopDfx(verbose);
|
|
128
|
+
let dir = path.join(getRootDir(), '.mops/.bench');
|
|
129
|
+
fs.writeFileSync(path.join(dir, 'dfx.json'), JSON.stringify(dfxJson(''), null, 2));
|
|
130
|
+
execSync('dfx start --background --clean' + (verbose ? '' : ' -qqqq'), { cwd: dir, stdio: ['inherit', verbose ? 'inherit' : 'ignore', 'inherit'] });
|
|
131
|
+
}
|
|
132
|
+
function stopDfx(verbose = false) {
|
|
133
|
+
let dir = path.join(getRootDir(), '.mops/.bench');
|
|
134
|
+
execSync('dfx stop' + (verbose ? '' : ' -qqqq'), { cwd: dir, stdio: ['pipe', verbose ? 'inherit' : 'ignore', 'pipe'] });
|
|
135
|
+
}
|
|
136
|
+
async function deployBenchFile(file, options = {}) {
|
|
137
|
+
let rootDir = getRootDir();
|
|
138
|
+
let tempDir = path.join(rootDir, '.mops/.bench/', path.parse(file).name);
|
|
139
|
+
let canisterName = path.parse(file).name;
|
|
140
|
+
// prepare temp files
|
|
141
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
142
|
+
fs.writeFileSync(path.join(tempDir, 'dfx.json'), JSON.stringify(dfxJson(canisterName, options), null, 2));
|
|
143
|
+
fs.cpSync(new URL('./bench/bench-canister.mo', import.meta.url), path.join(tempDir, 'canister.mo'));
|
|
144
|
+
fs.cpSync(file, path.join(tempDir, 'user-bench.mo'));
|
|
145
|
+
// build canister
|
|
146
|
+
let mocPath = getMocPath();
|
|
147
|
+
let mocArgs = getMocArgs(options);
|
|
148
|
+
options.verbose && console.time(`build ${canisterName}`);
|
|
149
|
+
await execaCommand(`${mocPath} -c --idl canister.mo ${mocArgs} ${(await sources({ cwd: tempDir })).join(' ')}`, { cwd: tempDir, stdio: options.verbose ? 'pipe' : ['pipe', 'ignore', 'pipe'] });
|
|
150
|
+
options.verbose && console.timeEnd(`build ${canisterName}`);
|
|
151
|
+
// deploy canister
|
|
152
|
+
options.verbose && console.time(`deploy ${canisterName}`);
|
|
153
|
+
await execaCommand(`dfx deploy ${canisterName} --mode reinstall --yes --identity anonymous`, { cwd: tempDir, stdio: options.verbose ? 'pipe' : ['pipe', 'ignore', 'pipe'] });
|
|
154
|
+
options.verbose && console.timeEnd(`deploy ${canisterName}`);
|
|
155
|
+
// init bench
|
|
156
|
+
options.verbose && console.time(`init ${canisterName}`);
|
|
157
|
+
let canisterId = execSync(`dfx canister id ${canisterName}`, { cwd: tempDir }).toString().trim();
|
|
158
|
+
let actor = await createActor(canisterId, {
|
|
159
|
+
agentOptions: {
|
|
160
|
+
host: 'http://127.0.0.1:4947',
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
await actor.init();
|
|
164
|
+
options.verbose && console.timeEnd(`init ${canisterName}`);
|
|
165
|
+
}
|
|
166
|
+
async function runBenchFile(file, options = {}) {
|
|
167
|
+
let rootDir = getRootDir();
|
|
168
|
+
let tempDir = path.join(rootDir, '.mops/.bench/', path.parse(file).name);
|
|
169
|
+
let canisterName = path.parse(file).name;
|
|
170
|
+
let canisterId = execSync(`dfx canister id ${canisterName}`, { cwd: tempDir }).toString().trim();
|
|
171
|
+
let actor = await createActor(canisterId, {
|
|
172
|
+
agentOptions: {
|
|
173
|
+
host: 'http://127.0.0.1:4947',
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
let schema = await actor.getSchema();
|
|
177
|
+
// load previous results
|
|
178
|
+
let prevResults;
|
|
179
|
+
let resultsJsonFile = path.join(rootDir, '.bench', `${path.parse(file).name}.json`);
|
|
180
|
+
if (options.compare) {
|
|
181
|
+
if (fs.existsSync(resultsJsonFile)) {
|
|
182
|
+
let prevResultsJson = JSON.parse(fs.readFileSync(resultsJsonFile).toString());
|
|
183
|
+
prevResults = new Map(prevResultsJson.results);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
console.log(chalk.yellow(`No previous results found "${resultsJsonFile}"`));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
let results = new Map();
|
|
190
|
+
let formatNumber = (n) => {
|
|
191
|
+
return n.toLocaleString('en-US').replaceAll(',', '_');
|
|
192
|
+
};
|
|
193
|
+
let getTable = (prop) => {
|
|
194
|
+
let resArr = [['', ...schema.cols]];
|
|
195
|
+
for (let [_rowIndex, row] of schema.rows.entries()) {
|
|
196
|
+
let curRow = [row];
|
|
197
|
+
for (let [_colIndex, col] of schema.cols.entries()) {
|
|
198
|
+
let res = results.get(`${row}:${col}`);
|
|
199
|
+
if (res) {
|
|
200
|
+
// compare with previous results
|
|
201
|
+
let diff = '';
|
|
202
|
+
if (options.compare && prevResults) {
|
|
203
|
+
let prevRes = prevResults.get(`${row}:${col}`);
|
|
204
|
+
if (prevRes) {
|
|
205
|
+
let percent = (Number(res[prop]) - Number(prevRes[prop])) / Number(prevRes[prop]) * 100;
|
|
206
|
+
let sign = percent > 0 ? '+' : '';
|
|
207
|
+
let percentText = percent == 0 ? '0%' : sign + percent.toFixed(2) + '%';
|
|
208
|
+
// diff = ' (' + (percent > 0 ? chalk.red(percentText) : chalk.green(percentText)) + ')'; // alignment is broken
|
|
209
|
+
diff = ' (' + percentText + ')';
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
diff = chalk.yellow(' (no previous results)');
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// add to table
|
|
216
|
+
curRow.push(formatNumber(res[prop]) + diff);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
curRow.push('');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
resArr.push(curRow);
|
|
223
|
+
}
|
|
224
|
+
return markdownTable(resArr, { align: ['l', ...'r'.repeat(schema.cols.length)] });
|
|
225
|
+
};
|
|
226
|
+
let printResults = () => {
|
|
227
|
+
logUpdate(`
|
|
228
|
+
\n${chalk.bold(schema.name)}
|
|
229
|
+
${schema.description ? '\n' + chalk.gray(schema.description) : ''}
|
|
230
|
+
\n\n${chalk.blue('Instructions')}\n\n${getTable('instructions')}
|
|
231
|
+
\n\n${chalk.blue('Heap')}\n\n${getTable('rts_heap_size')}
|
|
232
|
+
`);
|
|
233
|
+
};
|
|
234
|
+
printResults();
|
|
235
|
+
// run all cells
|
|
236
|
+
for (let [rowIndex, row] of schema.rows.entries()) {
|
|
237
|
+
for (let [colIndex, col] of schema.cols.entries()) {
|
|
238
|
+
let res = await actor.runCellQuery(BigInt(rowIndex), BigInt(colIndex));
|
|
239
|
+
// let res = await actor.runCellUpdate(BigInt(rowIndex), BigInt(colIndex));
|
|
240
|
+
// let res = await actor.runCellUpdateAwait(BigInt(rowIndex), BigInt(colIndex));
|
|
241
|
+
results.set(`${row}:${col}`, res);
|
|
242
|
+
printResults();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
logUpdate.done();
|
|
246
|
+
// save results
|
|
247
|
+
if (options.save) {
|
|
248
|
+
console.log(`Saving results to ${chalk.gray(absToRel(resultsJsonFile))}`);
|
|
249
|
+
let json = {
|
|
250
|
+
version: 1,
|
|
251
|
+
moc: options.moc,
|
|
252
|
+
dfx: options.dfx,
|
|
253
|
+
gc: options.gc,
|
|
254
|
+
forceGc: options.forceGc,
|
|
255
|
+
results: Array.from(results.entries()),
|
|
256
|
+
};
|
|
257
|
+
fs.mkdirSync(path.dirname(resultsJsonFile), { recursive: true });
|
|
258
|
+
fs.writeFileSync(resultsJsonFile, JSON.stringify(json, (_, val) => {
|
|
259
|
+
if (typeof val === 'bigint') {
|
|
260
|
+
return Number(val);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
return val;
|
|
264
|
+
}
|
|
265
|
+
}, 2));
|
|
266
|
+
}
|
|
267
|
+
return { schema, results };
|
|
268
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
type anon_class_10_1 =
|
|
2
|
+
service {
|
|
3
|
+
getSchema: () -> (BenchSchema) query;
|
|
4
|
+
getStats: () -> (BenchResult) query;
|
|
5
|
+
init: () -> (BenchSchema);
|
|
6
|
+
runCellQuery: (nat, nat) -> (BenchResult) query;
|
|
7
|
+
runCellUpdate: (nat, nat) -> (BenchResult);
|
|
8
|
+
runCellUpdateAwait: (nat, nat) -> (BenchResult);
|
|
9
|
+
};
|
|
10
|
+
type BenchSchema =
|
|
11
|
+
record {
|
|
12
|
+
cols: vec text;
|
|
13
|
+
description: text;
|
|
14
|
+
name: text;
|
|
15
|
+
rows: vec text;
|
|
16
|
+
};
|
|
17
|
+
type BenchResult =
|
|
18
|
+
record {
|
|
19
|
+
instructions: int;
|
|
20
|
+
rts_collector_instructions: int;
|
|
21
|
+
rts_heap_size: int;
|
|
22
|
+
rts_memory_size: int;
|
|
23
|
+
rts_mutator_instructions: int;
|
|
24
|
+
rts_total_allocation: int;
|
|
25
|
+
};
|
|
26
|
+
service : () -> anon_class_10_1
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Principal } from '@dfinity/principal';
|
|
2
|
+
import type { ActorMethod } from '@dfinity/agent';
|
|
3
|
+
|
|
4
|
+
export interface BenchResult {
|
|
5
|
+
'instructions' : bigint,
|
|
6
|
+
'rts_memory_size' : bigint,
|
|
7
|
+
'rts_total_allocation' : bigint,
|
|
8
|
+
'rts_collector_instructions' : bigint,
|
|
9
|
+
'rts_mutator_instructions' : bigint,
|
|
10
|
+
'rts_heap_size' : bigint,
|
|
11
|
+
}
|
|
12
|
+
export interface BenchSchema {
|
|
13
|
+
'cols' : Array<string>,
|
|
14
|
+
'name' : string,
|
|
15
|
+
'rows' : Array<string>,
|
|
16
|
+
'description' : string,
|
|
17
|
+
}
|
|
18
|
+
export interface anon_class_10_1 {
|
|
19
|
+
'getSchema' : ActorMethod<[], BenchSchema>,
|
|
20
|
+
'getStats' : ActorMethod<[], BenchResult>,
|
|
21
|
+
'init' : ActorMethod<[], BenchSchema>,
|
|
22
|
+
'runCellQuery' : ActorMethod<[bigint, bigint], BenchResult>,
|
|
23
|
+
'runCellUpdate' : ActorMethod<[bigint, bigint], BenchResult>,
|
|
24
|
+
'runCellUpdateAwait' : ActorMethod<[bigint, bigint], BenchResult>,
|
|
25
|
+
}
|
|
26
|
+
export interface _SERVICE extends anon_class_10_1 {}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const idlFactory = ({ IDL }) => {
|
|
2
|
+
const BenchSchema = IDL.Record({
|
|
3
|
+
'cols' : IDL.Vec(IDL.Text),
|
|
4
|
+
'name' : IDL.Text,
|
|
5
|
+
'rows' : IDL.Vec(IDL.Text),
|
|
6
|
+
'description' : IDL.Text,
|
|
7
|
+
});
|
|
8
|
+
const BenchResult = IDL.Record({
|
|
9
|
+
'instructions' : IDL.Int,
|
|
10
|
+
'rts_memory_size' : IDL.Int,
|
|
11
|
+
'rts_total_allocation' : IDL.Int,
|
|
12
|
+
'rts_collector_instructions' : IDL.Int,
|
|
13
|
+
'rts_mutator_instructions' : IDL.Int,
|
|
14
|
+
'rts_heap_size' : IDL.Int,
|
|
15
|
+
});
|
|
16
|
+
const anon_class_10_1 = IDL.Service({
|
|
17
|
+
'getSchema' : IDL.Func([], [BenchSchema], ['query']),
|
|
18
|
+
'getStats' : IDL.Func([], [BenchResult], ['query']),
|
|
19
|
+
'init' : IDL.Func([], [BenchSchema], []),
|
|
20
|
+
'runCellQuery' : IDL.Func([IDL.Nat, IDL.Nat], [BenchResult], ['query']),
|
|
21
|
+
'runCellUpdate' : IDL.Func([IDL.Nat, IDL.Nat], [BenchResult], []),
|
|
22
|
+
'runCellUpdateAwait' : IDL.Func([IDL.Nat, IDL.Nat], [BenchResult], []),
|
|
23
|
+
});
|
|
24
|
+
return anon_class_10_1;
|
|
25
|
+
};
|
|
26
|
+
export const init = ({ IDL }) => { return []; };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ActorSubclass,
|
|
3
|
+
HttpAgentOptions,
|
|
4
|
+
ActorConfig,
|
|
5
|
+
Agent,
|
|
6
|
+
} from "@dfinity/agent";
|
|
7
|
+
import type { Principal } from "@dfinity/principal";
|
|
8
|
+
import type { IDL } from "@dfinity/candid";
|
|
9
|
+
|
|
10
|
+
import { _SERVICE } from './bench.did';
|
|
11
|
+
|
|
12
|
+
export declare const idlFactory: IDL.InterfaceFactory;
|
|
13
|
+
export declare const canisterId: string;
|
|
14
|
+
|
|
15
|
+
export declare interface CreateActorOptions {
|
|
16
|
+
/**
|
|
17
|
+
* @see {@link Agent}
|
|
18
|
+
*/
|
|
19
|
+
agent?: Agent;
|
|
20
|
+
/**
|
|
21
|
+
* @see {@link HttpAgentOptions}
|
|
22
|
+
*/
|
|
23
|
+
agentOptions?: HttpAgentOptions;
|
|
24
|
+
/**
|
|
25
|
+
* @see {@link ActorConfig}
|
|
26
|
+
*/
|
|
27
|
+
actorOptions?: ActorConfig;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Intializes an {@link ActorSubclass}, configured with the provided SERVICE interface of a canister.
|
|
32
|
+
* @constructs {@link ActorSubClass}
|
|
33
|
+
* @param {string | Principal} canisterId - ID of the canister the {@link Actor} will talk to
|
|
34
|
+
* @param {CreateActorOptions} options - see {@link CreateActorOptions}
|
|
35
|
+
* @param {CreateActorOptions["agent"]} options.agent - a pre-configured agent you'd like to use. Supercedes agentOptions
|
|
36
|
+
* @param {CreateActorOptions["agentOptions"]} options.agentOptions - options to set up a new agent
|
|
37
|
+
* @see {@link HttpAgentOptions}
|
|
38
|
+
* @param {CreateActorOptions["actorOptions"]} options.actorOptions - options for the Actor
|
|
39
|
+
* @see {@link ActorConfig}
|
|
40
|
+
*/
|
|
41
|
+
export declare const createActor: (
|
|
42
|
+
canisterId: string | Principal,
|
|
43
|
+
options?: CreateActorOptions
|
|
44
|
+
) => ActorSubclass<_SERVICE>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Intialized Actor using default settings, ready to talk to a canister using its candid interface
|
|
48
|
+
* @constructs {@link ActorSubClass}
|
|
49
|
+
*/
|
|
50
|
+
export declare const bench: ActorSubclass<_SERVICE>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Actor, HttpAgent } from "@dfinity/agent";
|
|
2
|
+
|
|
3
|
+
// Imports and re-exports candid interface
|
|
4
|
+
import { idlFactory } from "./bench.did.js";
|
|
5
|
+
export { idlFactory } from "./bench.did.js";
|
|
6
|
+
|
|
7
|
+
/* CANISTER_ID is replaced by webpack based on node environment
|
|
8
|
+
* Note: canister environment variable will be standardized as
|
|
9
|
+
* process.env.CANISTER_ID_<CANISTER_NAME_UPPERCASE>
|
|
10
|
+
* beginning in dfx 0.15.0
|
|
11
|
+
*/
|
|
12
|
+
export const canisterId =
|
|
13
|
+
process.env.CANISTER_ID_BENCH ||
|
|
14
|
+
process.env.BENCH_CANISTER_ID;
|
|
15
|
+
|
|
16
|
+
export const createActor = (canisterId, options = {}) => {
|
|
17
|
+
const agent = options.agent || new HttpAgent({ ...options.agentOptions });
|
|
18
|
+
|
|
19
|
+
if (options.agent && options.agentOptions) {
|
|
20
|
+
console.warn(
|
|
21
|
+
"Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent."
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Fetch root key for certificate validation during development
|
|
26
|
+
if (process.env.DFX_NETWORK !== "ic") {
|
|
27
|
+
agent.fetchRootKey().catch((err) => {
|
|
28
|
+
console.warn(
|
|
29
|
+
"Unable to fetch root key. Check to ensure that your local replica is running"
|
|
30
|
+
);
|
|
31
|
+
console.error(err);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Creates an actor with using the candid interface and the HttpAgent
|
|
36
|
+
return Actor.createActor(idlFactory, {
|
|
37
|
+
agent,
|
|
38
|
+
canisterId,
|
|
39
|
+
...options.actorOptions,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getDfxVersion(): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getMocPath(): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
export function getMocPath() {
|
|
3
|
+
let mocPath = process.env.DFX_MOC_PATH;
|
|
4
|
+
if (!mocPath) {
|
|
5
|
+
mocPath = execSync('dfx cache show').toString().trim() + '/moc';
|
|
6
|
+
}
|
|
7
|
+
if (!mocPath) {
|
|
8
|
+
mocPath = 'moc';
|
|
9
|
+
}
|
|
10
|
+
return mocPath;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getMocVersion(): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
import { getMocPath } from './get-moc-path.js';
|
|
3
|
+
export function getMocVersion() {
|
|
4
|
+
let mocPath = getMocPath();
|
|
5
|
+
let match = execSync(mocPath).toString().trim().match(/Motoko compiler ([^\s]+) .*/);
|
|
6
|
+
return match?.[1] || '';
|
|
7
|
+
}
|
package/dist/package.json
CHANGED
package/dist/resolve-packages.js
CHANGED
|
@@ -57,7 +57,7 @@ export async function resolvePackages({ verbose = false } = {}) {
|
|
|
57
57
|
let nestedConfig;
|
|
58
58
|
if (repo) {
|
|
59
59
|
const dir = formatGithubDir(name, repo);
|
|
60
|
-
nestedConfig = await readVesselConfig(dir) || {};
|
|
60
|
+
nestedConfig = await readVesselConfig(dir, { silent: true }) || {};
|
|
61
61
|
}
|
|
62
62
|
else if (!pkgDetails.path && version) {
|
|
63
63
|
const file = formatDir(name, version) + '/mops.toml';
|
package/dist/vessel.d.ts
CHANGED
|
@@ -8,8 +8,9 @@ export type VesselDependencies = Array<{
|
|
|
8
8
|
repo?: string;
|
|
9
9
|
path?: string;
|
|
10
10
|
}>;
|
|
11
|
-
export declare const readVesselConfig: (dir: string, { cache }?: {
|
|
11
|
+
export declare const readVesselConfig: (dir: string, { cache, silent }?: {
|
|
12
12
|
cache?: boolean | undefined;
|
|
13
|
+
silent?: boolean | undefined;
|
|
13
14
|
}) => Promise<VesselConfig | null>;
|
|
14
15
|
export declare const downloadFromGithub: (repo: string, dest: string, onProgress: any) => Promise<unknown>;
|
|
15
16
|
export declare const installFromGithub: (name: string, repo: string, { verbose, dep, silent }?: {
|
package/dist/vessel.js
CHANGED
|
@@ -9,7 +9,7 @@ import decompress from 'decompress';
|
|
|
9
9
|
import { pipeline } from 'stream';
|
|
10
10
|
import { formatGithubDir, parseGithubURL, progressBar } from './mops.js';
|
|
11
11
|
import { addCache, copyCache, isCached } from './cache.js';
|
|
12
|
-
const dhallFileToJson = async (filePath) => {
|
|
12
|
+
const dhallFileToJson = async (filePath, silent) => {
|
|
13
13
|
if (existsSync(filePath)) {
|
|
14
14
|
let cwd = new URL(path.dirname(import.meta.url)).pathname;
|
|
15
15
|
let res;
|
|
@@ -17,7 +17,7 @@ const dhallFileToJson = async (filePath) => {
|
|
|
17
17
|
res = await execaCommand(`dhall-to-json --file ${filePath}`, { preferLocal: true, cwd });
|
|
18
18
|
}
|
|
19
19
|
catch (err) {
|
|
20
|
-
console.error('dhall-to-json error:', err);
|
|
20
|
+
silent || console.error('dhall-to-json error:', err.message?.split('Message:')[0]);
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
23
|
if (res.exitCode === 0) {
|
|
@@ -29,15 +29,15 @@ const dhallFileToJson = async (filePath) => {
|
|
|
29
29
|
}
|
|
30
30
|
return null;
|
|
31
31
|
};
|
|
32
|
-
export const readVesselConfig = async (dir, { cache = true } = {}) => {
|
|
32
|
+
export const readVesselConfig = async (dir, { cache = true, silent = false } = {}) => {
|
|
33
33
|
const cachedFile = (dir || process.cwd()) + '/vessel.json';
|
|
34
34
|
if (existsSync(cachedFile)) {
|
|
35
35
|
let cachedConfig = readFileSync(cachedFile).toString();
|
|
36
36
|
return JSON.parse(cachedConfig);
|
|
37
37
|
}
|
|
38
38
|
const [vessel, packageSetArray] = await Promise.all([
|
|
39
|
-
dhallFileToJson((dir || process.cwd()) + '/vessel.dhall'),
|
|
40
|
-
dhallFileToJson((dir || process.cwd()) + '/package-set.dhall')
|
|
39
|
+
dhallFileToJson((dir || process.cwd()) + '/vessel.dhall', silent),
|
|
40
|
+
dhallFileToJson((dir || process.cwd()) + '/package-set.dhall', silent)
|
|
41
41
|
]);
|
|
42
42
|
if (!vessel || !packageSetArray) {
|
|
43
43
|
return null;
|
|
@@ -64,6 +64,8 @@ export const downloadFromGithub = async (repo, dest, onProgress) => {
|
|
|
64
64
|
const readStream = got.stream(zipFile);
|
|
65
65
|
const promise = new Promise((resolve, reject) => {
|
|
66
66
|
readStream.on('error', (err) => {
|
|
67
|
+
console.error(chalk.red(`Error: failed to download from GitHub: ${zipFile}`));
|
|
68
|
+
console.error(err.message);
|
|
67
69
|
reject(err);
|
|
68
70
|
});
|
|
69
71
|
readStream.on('downloadProgress', ({ transferred, total }) => {
|
|
@@ -135,7 +137,7 @@ export const installFromGithub = async (name, repo, { verbose = false, dep = fal
|
|
|
135
137
|
}
|
|
136
138
|
catch (err) {
|
|
137
139
|
deleteSync([dir]);
|
|
138
|
-
|
|
140
|
+
process.exit(1);
|
|
139
141
|
}
|
|
140
142
|
// add to cache
|
|
141
143
|
await addCache(cacheName, dir);
|
|
@@ -143,7 +145,7 @@ export const installFromGithub = async (name, repo, { verbose = false, dep = fal
|
|
|
143
145
|
if (verbose) {
|
|
144
146
|
silent || logUpdate.done();
|
|
145
147
|
}
|
|
146
|
-
const config = await readVesselConfig(dir);
|
|
148
|
+
const config = await readVesselConfig(dir, { silent });
|
|
147
149
|
if (config) {
|
|
148
150
|
for (const { name, repo } of config.dependencies) {
|
|
149
151
|
if (repo) {
|
package/package.json
CHANGED
package/resolve-packages.ts
CHANGED
|
@@ -71,7 +71,7 @@ export async function resolvePackages({verbose = false} = {}): Promise<Record<st
|
|
|
71
71
|
|
|
72
72
|
if (repo) {
|
|
73
73
|
const dir = formatGithubDir(name, repo);
|
|
74
|
-
nestedConfig = await readVesselConfig(dir) || {};
|
|
74
|
+
nestedConfig = await readVesselConfig(dir, {silent: true}) || {};
|
|
75
75
|
}
|
|
76
76
|
else if (!pkgDetails.path && version) {
|
|
77
77
|
const file = formatDir(name, version) + '/mops.toml';
|
package/vessel.ts
CHANGED
|
@@ -10,15 +10,15 @@ import {pipeline} from 'stream';
|
|
|
10
10
|
import {formatGithubDir, parseGithubURL, progressBar} from './mops.js';
|
|
11
11
|
import {addCache, copyCache, isCached} from './cache.js';
|
|
12
12
|
|
|
13
|
-
const dhallFileToJson = async (filePath: string) => {
|
|
13
|
+
const dhallFileToJson = async (filePath: string, silent: boolean) => {
|
|
14
14
|
if (existsSync(filePath)) {
|
|
15
15
|
let cwd = new URL(path.dirname(import.meta.url)).pathname;
|
|
16
16
|
let res;
|
|
17
17
|
try {
|
|
18
18
|
res = await execaCommand(`dhall-to-json --file ${filePath}`, {preferLocal:true, cwd});
|
|
19
19
|
}
|
|
20
|
-
catch (err) {
|
|
21
|
-
console.error('dhall-to-json error:', err);
|
|
20
|
+
catch (err: any) {
|
|
21
|
+
silent || console.error('dhall-to-json error:', err.message?.split('Message:')[0]);
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -45,7 +45,7 @@ export type VesselDependencies = Array<{
|
|
|
45
45
|
path?: string; // local package
|
|
46
46
|
}>;
|
|
47
47
|
|
|
48
|
-
export const readVesselConfig = async (dir: string, {cache = true} = {}): Promise<VesselConfig | null> => {
|
|
48
|
+
export const readVesselConfig = async (dir: string, {cache = true, silent = false} = {}): Promise<VesselConfig | null> => {
|
|
49
49
|
const cachedFile = (dir || process.cwd()) + '/vessel.json';
|
|
50
50
|
|
|
51
51
|
if (existsSync(cachedFile)) {
|
|
@@ -54,8 +54,8 @@ export const readVesselConfig = async (dir: string, {cache = true} = {}): Promis
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
const [vessel, packageSetArray] = await Promise.all([
|
|
57
|
-
dhallFileToJson((dir || process.cwd()) + '/vessel.dhall'),
|
|
58
|
-
dhallFileToJson((dir || process.cwd()) + '/package-set.dhall')
|
|
57
|
+
dhallFileToJson((dir || process.cwd()) + '/vessel.dhall', silent),
|
|
58
|
+
dhallFileToJson((dir || process.cwd()) + '/package-set.dhall', silent)
|
|
59
59
|
]);
|
|
60
60
|
|
|
61
61
|
if (!vessel || !packageSetArray) {
|
|
@@ -90,6 +90,8 @@ export const downloadFromGithub = async (repo: string, dest: string, onProgress:
|
|
|
90
90
|
|
|
91
91
|
const promise = new Promise((resolve, reject) => {
|
|
92
92
|
readStream.on('error', (err) => {
|
|
93
|
+
console.error(chalk.red(`Error: failed to download from GitHub: ${zipFile}`));
|
|
94
|
+
console.error(err.message);
|
|
93
95
|
reject(err);
|
|
94
96
|
});
|
|
95
97
|
|
|
@@ -172,7 +174,7 @@ export const installFromGithub = async (name: string, repo: string, {verbose = f
|
|
|
172
174
|
}
|
|
173
175
|
catch (err) {
|
|
174
176
|
deleteSync([dir]);
|
|
175
|
-
|
|
177
|
+
process.exit(1);
|
|
176
178
|
}
|
|
177
179
|
|
|
178
180
|
// add to cache
|
|
@@ -183,7 +185,7 @@ export const installFromGithub = async (name: string, repo: string, {verbose = f
|
|
|
183
185
|
silent || logUpdate.done();
|
|
184
186
|
}
|
|
185
187
|
|
|
186
|
-
const config = await readVesselConfig(dir);
|
|
188
|
+
const config = await readVesselConfig(dir, {silent});
|
|
187
189
|
|
|
188
190
|
if (config) {
|
|
189
191
|
for (const {name, repo} of config.dependencies) {
|