ic-mops 1.7.2 → 1.8.1
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/CHANGELOG.md +7 -0
- package/bundle/bench/bench-canister.mo +113 -0
- package/bundle/bench/user-bench.mo +14 -0
- package/bundle/bin/moc-wrapper.sh +40 -0
- package/bundle/bin/mops.js +3 -0
- package/bundle/cli.js +14 -14
- package/bundle/cli.tgz +0 -0
- package/bundle/declarations/bench/bench.did +30 -0
- package/bundle/declarations/bench/bench.did.d.ts +33 -0
- package/bundle/declarations/bench/bench.did.js +30 -0
- package/bundle/declarations/bench/index.d.ts +50 -0
- package/bundle/declarations/bench/index.js +40 -0
- package/bundle/declarations/main/index.d.ts +50 -0
- package/bundle/declarations/main/index.js +40 -0
- package/bundle/declarations/main/main.did +465 -0
- package/bundle/declarations/main/main.did.d.ts +392 -0
- package/bundle/declarations/main/main.did.js +454 -0
- package/bundle/declarations/storage/index.d.ts +50 -0
- package/bundle/declarations/storage/index.js +30 -0
- package/bundle/declarations/storage/storage.did +46 -0
- package/bundle/declarations/storage/storage.did.d.ts +40 -0
- package/bundle/declarations/storage/storage.did.js +38 -0
- package/bundle/package.json +35 -0
- package/bundle/templates/README.md +13 -0
- package/bundle/templates/licenses/Apache-2.0 +202 -0
- package/bundle/templates/licenses/Apache-2.0-NOTICE +13 -0
- package/bundle/templates/licenses/MIT +21 -0
- package/bundle/templates/mops-publish.yml +17 -0
- package/bundle/templates/mops-test.yml +24 -0
- package/bundle/templates/src/lib.mo +15 -0
- package/bundle/templates/test/lib.test.mo +4 -0
- package/bundle/wasm_bg.wasm +0 -0
- package/cli.ts +16 -0
- package/commands/format.ts +169 -0
- package/commands/publish.ts +1 -0
- package/commands/watch/formatter.ts +74 -0
- package/commands/watch/watch.ts +23 -2
- package/dist/cli.js +15 -0
- package/dist/commands/format.d.ts +14 -0
- package/dist/commands/format.js +131 -0
- package/dist/commands/publish.js +1 -0
- package/dist/commands/watch/formatter.d.ts +19 -0
- package/dist/commands/watch/formatter.js +57 -0
- package/dist/commands/watch/watch.d.ts +1 -0
- package/dist/commands/watch/watch.js +19 -1
- package/dist/package.json +4 -2
- package/package.json +6 -4
- package/types.ts +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Mops CLI Changelog
|
|
2
2
|
|
|
3
|
+
## 1.8.1
|
|
4
|
+
- Exclude `node_modules` from publish command file patterns
|
|
5
|
+
|
|
6
|
+
## 1.8.0
|
|
7
|
+
- Add `mops format` command for formatting Motoko source files with Prettier and Motoko plugin ([docs](https://docs.mops.one/cli/mops-format))
|
|
8
|
+
- Add `--format` flag to `mops watch` command to enable automatic formatting during watch mode ([docs](https://docs.mops.one/cli/mops-watch#--format))
|
|
9
|
+
|
|
3
10
|
## 1.7.2
|
|
4
11
|
- Fix replica termination in `mops test` command
|
|
5
12
|
|
|
@@ -0,0 +1,113 @@
|
|
|
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 ExperimentalStableMemory "mo:base/ExperimentalStableMemory";
|
|
6
|
+
import Int64 "mo:base/Int64";
|
|
7
|
+
import Region "mo:base/Region";
|
|
8
|
+
import Prim "mo:prim";
|
|
9
|
+
import Bench "mo:bench";
|
|
10
|
+
|
|
11
|
+
import UserBench "./user-bench"; // file path will be replaced with the *.bench.mo file path
|
|
12
|
+
|
|
13
|
+
actor class() {
|
|
14
|
+
type BenchResult = {
|
|
15
|
+
instructions : Int;
|
|
16
|
+
rts_mutator_instructions : Int;
|
|
17
|
+
stable_memory_size : Int;
|
|
18
|
+
rts_stable_memory_size : Int;
|
|
19
|
+
rts_logical_stable_memory_size : Int;
|
|
20
|
+
rts_collector_instructions : Int;
|
|
21
|
+
rts_heap_size : Int;
|
|
22
|
+
rts_memory_size : Int;
|
|
23
|
+
rts_total_allocation : Int;
|
|
24
|
+
rts_reclaimed : Int;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
var benchOpt : ?Bench.Bench = null;
|
|
28
|
+
|
|
29
|
+
public func init() : async Bench.BenchSchema {
|
|
30
|
+
let bench = UserBench.init();
|
|
31
|
+
benchOpt := ?bench;
|
|
32
|
+
// ignore ExperimentalStableMemory.grow(1);
|
|
33
|
+
ignore Region.grow(Region.new(), 1);
|
|
34
|
+
bench.getSchema();
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
public query func getSchema() : async Bench.BenchSchema {
|
|
38
|
+
let ?bench = benchOpt else Debug.trap("bench not initialized");
|
|
39
|
+
bench.getSchema();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
func _getStats() : BenchResult {
|
|
43
|
+
{
|
|
44
|
+
instructions = 0;
|
|
45
|
+
rts_heap_size = Prim.rts_heap_size();
|
|
46
|
+
stable_memory_size = Int64.toInt(Int64.fromNat64(ExperimentalStableMemory.size())) * 65536;
|
|
47
|
+
rts_stable_memory_size = Prim.rts_stable_memory_size();
|
|
48
|
+
rts_logical_stable_memory_size = Prim.rts_logical_stable_memory_size();
|
|
49
|
+
rts_memory_size = Prim.rts_memory_size();
|
|
50
|
+
rts_total_allocation = Prim.rts_total_allocation();
|
|
51
|
+
rts_reclaimed = Prim.rts_reclaimed();
|
|
52
|
+
rts_mutator_instructions = Prim.rts_mutator_instructions();
|
|
53
|
+
rts_collector_instructions = Prim.rts_collector_instructions();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
func _diffStats(before : BenchResult, after : BenchResult) : BenchResult {
|
|
58
|
+
{
|
|
59
|
+
instructions = after.instructions - before.instructions;
|
|
60
|
+
rts_heap_size = after.rts_heap_size - before.rts_heap_size;
|
|
61
|
+
stable_memory_size = after.stable_memory_size - before.stable_memory_size;
|
|
62
|
+
rts_stable_memory_size = after.rts_stable_memory_size - before.rts_stable_memory_size;
|
|
63
|
+
rts_logical_stable_memory_size = after.rts_logical_stable_memory_size - before.rts_logical_stable_memory_size;
|
|
64
|
+
rts_memory_size = after.rts_memory_size - before.rts_memory_size;
|
|
65
|
+
rts_total_allocation = after.rts_total_allocation - before.rts_total_allocation;
|
|
66
|
+
rts_reclaimed = after.rts_reclaimed - before.rts_reclaimed;
|
|
67
|
+
rts_mutator_instructions = after.rts_mutator_instructions - before.rts_mutator_instructions;
|
|
68
|
+
rts_collector_instructions = after.rts_collector_instructions - before.rts_collector_instructions;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
func _runCell(rowIndex : Nat, colIndex : Nat) : BenchResult {
|
|
73
|
+
let ?bench = benchOpt else Debug.trap("bench not initialized");
|
|
74
|
+
let statsBefore = _getStats();
|
|
75
|
+
|
|
76
|
+
let instructions = Nat64.toNat(ExperimentalInternetComputer.countInstructions(func() {
|
|
77
|
+
bench.runCell(rowIndex, colIndex);
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
let statsAfter = _getStats();
|
|
81
|
+
_diffStats(statsBefore, { statsAfter with instructions });
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
func _runCellAwait(rowIndex : Nat, colIndex : Nat) : async BenchResult {
|
|
85
|
+
let ?bench = benchOpt else Debug.trap("bench not initialized");
|
|
86
|
+
let statsBefore = _getStats();
|
|
87
|
+
|
|
88
|
+
let instructions = Nat64.toNat(ExperimentalInternetComputer.countInstructions(func() {
|
|
89
|
+
bench.runCell(rowIndex, colIndex);
|
|
90
|
+
}));
|
|
91
|
+
|
|
92
|
+
await (func() : async () {})();
|
|
93
|
+
|
|
94
|
+
let statsAfter = _getStats();
|
|
95
|
+
_diffStats(statsBefore, { statsAfter with instructions });
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
public query func getStats() : async BenchResult {
|
|
99
|
+
_getStats();
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
public query func runCellQuery(rowIndex : Nat, colIndex : Nat) : async BenchResult {
|
|
103
|
+
_runCell(rowIndex, colIndex);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
public func runCellUpdate(rowIndex : Nat, colIndex : Nat) : async BenchResult {
|
|
107
|
+
_runCell(rowIndex, colIndex);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
public func runCellUpdateAwait(rowIndex : Nat, colIndex : Nat) : async BenchResult {
|
|
111
|
+
await _runCellAwait(rowIndex, colIndex);
|
|
112
|
+
};
|
|
113
|
+
};
|
|
@@ -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,40 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# set -e
|
|
4
|
+
|
|
5
|
+
findRootDir() {
|
|
6
|
+
dir="$(pwd)"
|
|
7
|
+
while [[ "$dir" != "" && ! -e "$dir/mops.toml" ]]; do
|
|
8
|
+
dir=${dir%/*}
|
|
9
|
+
done
|
|
10
|
+
echo "$dir"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
rootDir=$(findRootDir)
|
|
14
|
+
mopsToml="$rootDir/mops.toml"
|
|
15
|
+
|
|
16
|
+
if [[ $rootDir == "" ]] || [[ ! -f $mopsToml ]]; then
|
|
17
|
+
mocPath="$(mops toolchain bin moc --fallback)"
|
|
18
|
+
else
|
|
19
|
+
if command -v openssl >/dev/null 2>&1; then
|
|
20
|
+
mopsTomlHash=$(openssl sha256 $mopsToml | awk -F'= ' '{print $2}')
|
|
21
|
+
else
|
|
22
|
+
mopsTomlHash=$(shasum $mopsToml -a 256 | awk -F' ' '{print $1}')
|
|
23
|
+
fi;
|
|
24
|
+
|
|
25
|
+
cached="$rootDir/.mops/moc-$(uname -n)-$mopsTomlHash"
|
|
26
|
+
|
|
27
|
+
if [ -f $cached ]; then
|
|
28
|
+
mocPath=$(cat $cached)
|
|
29
|
+
if [[ "$mocPath" != *"/moc" ]] ; then
|
|
30
|
+
mocPath="$(mops toolchain bin moc --fallback)"
|
|
31
|
+
echo -n $mocPath > "$cached"
|
|
32
|
+
fi;
|
|
33
|
+
else
|
|
34
|
+
mkdir -p "$(dirname $cached)"
|
|
35
|
+
mocPath="$(mops toolchain bin moc --fallback)"
|
|
36
|
+
echo -n $mocPath > "$cached"
|
|
37
|
+
fi;
|
|
38
|
+
fi;
|
|
39
|
+
|
|
40
|
+
$mocPath "$@"
|