whet 0.1.1 → 0.2.0
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/bin/haxe/ds/IntMap.d.ts +6 -0
- package/bin/haxe/ds/IntMap.js +25 -0
- package/bin/haxe/ds/Vector.d.ts +2 -0
- package/bin/minimatch/MinimatchOptions.d.ts +28 -0
- package/bin/whet/Project.d.ts +8 -0
- package/bin/whet/Project.js +14 -0
- package/bin/whet/Stone.d.ts +21 -0
- package/bin/whet/Stone.js +70 -6
- package/bin/whet/Whet.js +20 -1
- package/bin/whet/cache/BaseCache.d.ts +2 -0
- package/bin/whet/cache/BaseCache.js +96 -7
- package/bin/whet/cache/CacheManager.js +89 -7
- package/bin/whet/profiler/Profiler.d.ts +65 -0
- package/bin/whet/profiler/Profiler.js +351 -0
- package/bin/whet/profiler/Span.d.ts +90 -0
- package/bin/whet/profiler/Span.js +56 -0
- package/bin/whet/profiler/SpanRecorder.d.ts +20 -0
- package/bin/whet/profiler/SpanRecorder.js +63 -0
- package/bin/whet/profiler/SpanStats.d.ts +15 -0
- package/bin/whet/profiler/SpanStats.js +49 -0
- package/package.json +2 -2
- package/bin/haxe/Log.d.ts +0 -33
- package/bin/haxe/Log.js +0 -61
- package/bin/pino_pretty/PrettyOptions.d.ts +0 -98
- package/bin/pino_pretty/default_/MessageFormatFunc.d.ts +0 -2
- package/bin/pino_pretty/default_/Prettifier.d.ts +0 -2
- package/bin/whet/extern/Minimatch.d.ts +0 -77
- package/bin/whet/stones/Server.d.ts +0 -59
- package/bin/whet/stones/Server.js +0 -261
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {IMap} from "../Constraints.js"
|
|
2
|
+
import {EsMap} from "../../genes/util/EsMap.js"
|
|
3
|
+
import {Register} from "../../genes/Register.js"
|
|
4
|
+
|
|
5
|
+
const $global = Register.$global
|
|
6
|
+
|
|
7
|
+
export const IntMap = Register.global("$hxClasses")["haxe.ds.IntMap"] =
|
|
8
|
+
class IntMap extends Register.inherits(EsMap) {
|
|
9
|
+
[Register.new]() {
|
|
10
|
+
super[Register.new]();
|
|
11
|
+
}
|
|
12
|
+
static get __name__() {
|
|
13
|
+
return "haxe.ds.IntMap"
|
|
14
|
+
}
|
|
15
|
+
static get __interfaces__() {
|
|
16
|
+
return [IMap]
|
|
17
|
+
}
|
|
18
|
+
static get __super__() {
|
|
19
|
+
return EsMap
|
|
20
|
+
}
|
|
21
|
+
get __class__() {
|
|
22
|
+
return IntMap
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
@@ -32,6 +32,34 @@ export type MinimatchOptions = {
|
|
|
32
32
|
*/
|
|
33
33
|
matchBase?: null | boolean,
|
|
34
34
|
/**
|
|
35
|
+
Max depth to traverse for nested extglobs like `*(a|b|c)`
|
|
36
|
+
|
|
37
|
+
Default is 2, which is quite low, but any higher value
|
|
38
|
+
swiftly results in punishing performance impacts. Note
|
|
39
|
+
that this is *not* relevant when the globstar types can
|
|
40
|
+
be safely coalesced into a single set.
|
|
41
|
+
|
|
42
|
+
For example, `*(a|@(b|c)|d)` would be flattened into
|
|
43
|
+
`*(a|b|c|d)`. Thus, many common extglobs will retain good
|
|
44
|
+
performance and never hit this limit, even if they are
|
|
45
|
+
excessively deep and complicated.
|
|
46
|
+
|
|
47
|
+
If the limit is hit, then the extglob characters are simply
|
|
48
|
+
not parsed, and the pattern effectively switches into
|
|
49
|
+
`noextglob: true` mode for the contents of that nested
|
|
50
|
+
sub-pattern. This will typically _not_ result in a match,
|
|
51
|
+
but is considered a valid trade-off for security and
|
|
52
|
+
performance.
|
|
53
|
+
*/
|
|
54
|
+
maxExtglobRecursion?: null | number,
|
|
55
|
+
/**
|
|
56
|
+
Max number of non-adjacent `**` patterns to recursively walk down.
|
|
57
|
+
|
|
58
|
+
The default of 200 is almost certainly high enough for most purposes,
|
|
59
|
+
and can handle absurdly excessive patterns.
|
|
60
|
+
*/
|
|
61
|
+
maxGlobstarRecursion?: null | number,
|
|
62
|
+
/**
|
|
35
63
|
do not expand `{x,y}` style braces
|
|
36
64
|
*/
|
|
37
65
|
nobrace?: null | boolean,
|
package/bin/whet/Project.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {Profiler, ProfilerConfig} from "./profiler/Profiler"
|
|
1
2
|
import {CacheManager} from "./cache/CacheManager"
|
|
2
3
|
import {CacheStrategy} from "./cache/Cache"
|
|
3
4
|
import {AnyStone, OutputFilter} from "./Stone"
|
|
@@ -13,6 +14,7 @@ export declare class Project {
|
|
|
13
14
|
rootDir: string
|
|
14
15
|
cache: CacheManager
|
|
15
16
|
configStore: ConfigStore
|
|
17
|
+
profiler: null | Profiler
|
|
16
18
|
stones: AnyStone[]
|
|
17
19
|
onInit: (config: any) => Promise<any>
|
|
18
20
|
|
|
@@ -29,6 +31,8 @@ export declare class Project {
|
|
|
29
31
|
getStoneConfig(id: string): Promise<null | StoneConfigView>
|
|
30
32
|
setStoneConfig(id: string, patch: any, mode: string): Promise<boolean>
|
|
31
33
|
clearStoneConfigPreview(id: string): Promise<boolean>
|
|
34
|
+
enableProfiling(config?: null | ProfilerConfig): void
|
|
35
|
+
disableProfiling(): void
|
|
32
36
|
addCommand(name: string, stone?: null | AnyStone): Command
|
|
33
37
|
protected isCommandNameTaken(name: string): boolean
|
|
34
38
|
toString(): string
|
|
@@ -49,6 +53,10 @@ export type ProjectConfig = {
|
|
|
49
53
|
*/
|
|
50
54
|
onInit?: null | ((config: any) => Promise<any>),
|
|
51
55
|
options?: null | Option[],
|
|
56
|
+
/**
|
|
57
|
+
Enable profiling with optional config.
|
|
58
|
+
*/
|
|
59
|
+
profiler?: null | ProfilerConfig,
|
|
52
60
|
rootDir?: null | string
|
|
53
61
|
}
|
|
54
62
|
|
package/bin/whet/Project.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {Router} from "./route/Router.js"
|
|
2
|
+
import {Profiler} from "./profiler/Profiler.js"
|
|
2
3
|
import {StoneId_Fields_} from "./magic/StoneId.js"
|
|
3
4
|
import {MaybeArray_Fields_} from "./magic/MaybeArray.js"
|
|
4
5
|
import {CacheManager} from "./cache/CacheManager.js"
|
|
@@ -18,6 +19,7 @@ export const Project = Register.global("$hxClasses")["whet.Project"] =
|
|
|
18
19
|
class Project extends Register.inherits() {
|
|
19
20
|
[Register.new](config) {
|
|
20
21
|
this.stones = [];
|
|
22
|
+
this.profiler = null;
|
|
21
23
|
this.configStore = null;
|
|
22
24
|
this.cache = null;
|
|
23
25
|
Log.log(20, ...["Instantiating new Project."]);
|
|
@@ -55,6 +57,9 @@ class Project extends Register.inherits() {
|
|
|
55
57
|
};
|
|
56
58
|
this.configStore = config.configStore;
|
|
57
59
|
this.cache = (config.cache == null) ? new CacheManager(this) : config.cache;
|
|
60
|
+
if (config.profiler != null) {
|
|
61
|
+
this.profiler = new Profiler(config.profiler);
|
|
62
|
+
};
|
|
58
63
|
Project.projects.push(this);
|
|
59
64
|
Log.log(30, ...["New project created.", {"project": this, "projectCount": Project.projects.length}]);
|
|
60
65
|
}
|
|
@@ -201,6 +206,14 @@ class Project extends Register.inherits() {
|
|
|
201
206
|
store.clearEntry(stone.id);
|
|
202
207
|
return Promise.resolve(true);
|
|
203
208
|
}
|
|
209
|
+
enableProfiling(config) {
|
|
210
|
+
if (this.profiler == null) {
|
|
211
|
+
this.profiler = new Profiler(config);
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
disableProfiling() {
|
|
215
|
+
this.profiler = null;
|
|
216
|
+
}
|
|
204
217
|
addCommand(name, stone) {
|
|
205
218
|
let cmdName = name;
|
|
206
219
|
let cmdAlias = null;
|
|
@@ -252,6 +265,7 @@ Project.prototype.description = null;
|
|
|
252
265
|
Project.prototype.rootDir = null;
|
|
253
266
|
Project.prototype.cache = null;
|
|
254
267
|
Project.prototype.configStore = null;
|
|
268
|
+
Project.prototype.profiler = null;
|
|
255
269
|
Project.prototype.stones = null;
|
|
256
270
|
Project.prototype.onInit = null;
|
|
257
271
|
Project.prototype.config = null;
|
package/bin/whet/Stone.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {AnySpan} from "./profiler/Span"
|
|
1
2
|
import {StoneIdType} from "./magic/StoneId"
|
|
2
3
|
import {MaybeArray} from "./magic/MaybeArray"
|
|
3
4
|
import {CacheManager} from "./cache/CacheManager"
|
|
@@ -184,6 +185,26 @@ export declare class Stone<T extends StoneConfig> {
|
|
|
184
185
|
* Useful for pure JS stones.
|
|
185
186
|
*/
|
|
186
187
|
cwdPath(path: string): string
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
Wraps an async operation in a profiler span. No-op when profiler is null.
|
|
191
|
+
*/
|
|
192
|
+
protected profilerWithSpan<T, R>(op: string, fn: (() => Promise<R>), meta?: null | T): Promise<R>
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
Starts a manual profiler span. Returns null when profiler is null.
|
|
196
|
+
*/
|
|
197
|
+
protected profilerStartSpan<T>(op: string, meta?: null | T): null | AnySpan
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
Ends a manual profiler span. No-op when span is null.
|
|
201
|
+
*/
|
|
202
|
+
protected profilerEndSpan(span: null | AnySpan): void
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
Returns the current span from ALS context, or null when profiler is disabled.
|
|
206
|
+
*/
|
|
207
|
+
protected profilerGetCurrentSpan(): null | AnySpan
|
|
187
208
|
protected get_cache(): CacheManager
|
|
188
209
|
toString(): string
|
|
189
210
|
}
|
package/bin/whet/Stone.js
CHANGED
|
@@ -75,13 +75,23 @@ class Stone extends Register.inherits() {
|
|
|
75
75
|
let _gthis = this;
|
|
76
76
|
if (this.locked) {
|
|
77
77
|
Log.log(20, ...["Stone is locked, waiting.", {"stone": this}]);
|
|
78
|
+
let waitSpan = (this.project.profiler != null) ? this.project.profiler.startSpan(this, "LockWait", {"queuePosition": this.lockQueue.length, "queueLength": this.lockQueue.length + 1}) : null;
|
|
78
79
|
let deferredRes;
|
|
79
80
|
let deferredRej;
|
|
80
81
|
let deferred = new Promise(function (res, rej) {
|
|
81
82
|
deferredRes = res;
|
|
82
83
|
deferredRej = rej;
|
|
83
84
|
});
|
|
84
|
-
this.lockQueue.push({"run":
|
|
85
|
+
this.lockQueue.push({"run": function () {
|
|
86
|
+
if (waitSpan != null) {
|
|
87
|
+
_gthis.project.profiler.endSpan(waitSpan);
|
|
88
|
+
};
|
|
89
|
+
if (_gthis.project.profiler != null) {
|
|
90
|
+
return _gthis.project.profiler.withSpan(_gthis, "LockHeld", run, null);
|
|
91
|
+
} else {
|
|
92
|
+
return run();
|
|
93
|
+
};
|
|
94
|
+
}, "res": deferredRes, "rej": deferredRej});
|
|
85
95
|
return deferred;
|
|
86
96
|
} else {
|
|
87
97
|
this.locked = true;
|
|
@@ -96,7 +106,7 @@ class Stone extends Register.inherits() {
|
|
|
96
106
|
Log.log(10, ...["No function in lock queue. Stone is now unlocked.", {"stone": _gthis}]);
|
|
97
107
|
};
|
|
98
108
|
};
|
|
99
|
-
return run()["finally"](runNext);
|
|
109
|
+
return ((this.project.profiler != null) ? this.project.profiler.withSpan(this, "LockHeld", run, null) : run())["finally"](runNext);
|
|
100
110
|
};
|
|
101
111
|
}
|
|
102
112
|
|
|
@@ -158,13 +168,25 @@ class Stone extends Register.inherits() {
|
|
|
158
168
|
throw new Error("Acquire a lock before generating.");
|
|
159
169
|
};
|
|
160
170
|
Log.log(20, ...["Generating source.", {"stone": this, "hash": hash}]);
|
|
171
|
+
let deps = (this.config.dependencies != null) ? MaybeArray_Fields_.makeArray(this.config.dependencies) : null;
|
|
161
172
|
let init;
|
|
162
|
-
if (
|
|
173
|
+
if (deps != null) {
|
|
163
174
|
let _g = [];
|
|
164
175
|
let _g1 = 0;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
176
|
+
while (_g1 < deps.length) _g.push(deps[_g1++].id);
|
|
177
|
+
if (this.project.profiler != null) {
|
|
178
|
+
init = this.project.profiler.withSpan(this, "DependencyResolve", function () {
|
|
179
|
+
let _g = [];
|
|
180
|
+
let _g1 = 0;
|
|
181
|
+
while (_g1 < deps.length) _g.push(deps[_g1++].getSource());
|
|
182
|
+
return Promise.all(_g);
|
|
183
|
+
}, {"dependencyIds": _g});
|
|
184
|
+
} else {
|
|
185
|
+
let _g = [];
|
|
186
|
+
let _g1 = 0;
|
|
187
|
+
while (_g1 < deps.length) _g.push(deps[_g1++].getSource());
|
|
188
|
+
init = Promise.all(_g);
|
|
189
|
+
};
|
|
168
190
|
} else {
|
|
169
191
|
init = Promise.resolve(null);
|
|
170
192
|
};
|
|
@@ -471,6 +493,48 @@ class Stone extends Register.inherits() {
|
|
|
471
493
|
cwdPath(path) {
|
|
472
494
|
return Path.posix.join(".", RootDir.fromProject(this.project), ".", path);
|
|
473
495
|
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
Wraps an async operation in a profiler span. No-op when profiler is null.
|
|
499
|
+
*/
|
|
500
|
+
profilerWithSpan(op, fn, meta) {
|
|
501
|
+
if (this.project.profiler != null) {
|
|
502
|
+
return this.project.profiler.withSpan(this, op, fn, meta);
|
|
503
|
+
} else {
|
|
504
|
+
return fn();
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
Starts a manual profiler span. Returns null when profiler is null.
|
|
510
|
+
*/
|
|
511
|
+
profilerStartSpan(op, meta) {
|
|
512
|
+
if (this.project.profiler != null) {
|
|
513
|
+
return this.project.profiler.startSpan(this, op, meta);
|
|
514
|
+
} else {
|
|
515
|
+
return null;
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
Ends a manual profiler span. No-op when span is null.
|
|
521
|
+
*/
|
|
522
|
+
profilerEndSpan(span) {
|
|
523
|
+
if (span != null) {
|
|
524
|
+
this.project.profiler.endSpan(span);
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
Returns the current span from ALS context, or null when profiler is disabled.
|
|
530
|
+
*/
|
|
531
|
+
profilerGetCurrentSpan() {
|
|
532
|
+
if (this.project.profiler != null) {
|
|
533
|
+
return this.project.profiler.getCurrentSpan();
|
|
534
|
+
} else {
|
|
535
|
+
return null;
|
|
536
|
+
};
|
|
537
|
+
}
|
|
474
538
|
get_cache() {
|
|
475
539
|
return this.project.cache;
|
|
476
540
|
}
|
package/bin/whet/Whet.js
CHANGED
|
@@ -26,7 +26,7 @@ class Whet_Fields_ {
|
|
|
26
26
|
if (entryUrl != thisUrl) {
|
|
27
27
|
return;
|
|
28
28
|
};
|
|
29
|
-
Whet_Fields_.program.enablePositionalOptions().passThroughOptions().description("Project tooling.").usage("[options] [command] [+ [command]...]").version("0.
|
|
29
|
+
Whet_Fields_.program.enablePositionalOptions().passThroughOptions().description("Project tooling.").usage("[options] [command] [+ [command]...]").version("0.2.0", "-v, --version").allowUnknownOption(true).allowExcessArguments(true).showSuggestionAfterError(true).option("-p, --project <file>", "project to run", "Project.mjs").option("-l, --log-level <level>", "log level, a string/number", "info").option("--no-pretty", "disable pretty logging").option("--profile <format>", "enable profiling, export to whet-profile.json on exit (format: json or trace, default: json)").exitOverride();
|
|
30
30
|
try {
|
|
31
31
|
Whet_Fields_.program.parse();
|
|
32
32
|
}catch (_g) {
|
|
@@ -92,6 +92,25 @@ class Whet_Fields_ {
|
|
|
92
92
|
if (commands.length > 0) {
|
|
93
93
|
let res = Whet_Fields_.program.parseOptions(commands[0]);
|
|
94
94
|
commands[0] = res.operands.concat(res.unknown);
|
|
95
|
+
let profileFormat = Whet_Fields_.program.opts().profile;
|
|
96
|
+
if (profileFormat != null) {
|
|
97
|
+
let format = (profileFormat == true) ? "json" : profileFormat;
|
|
98
|
+
let _g = 0;
|
|
99
|
+
let _g1 = Project.projects;
|
|
100
|
+
while (_g < _g1.length) _g1[_g++].enableProfiling();
|
|
101
|
+
let onExit = function () {
|
|
102
|
+
let _g = 0;
|
|
103
|
+
let _g1 = Project.projects;
|
|
104
|
+
while (_g < _g1.length) {
|
|
105
|
+
let p = _g1[_g];
|
|
106
|
+
++_g;
|
|
107
|
+
if (p.profiler != null) {
|
|
108
|
+
Fs.writeFileSync("whet-profile.json", JSON.stringify(p.profiler["export"](format), null, " "));
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
process.on("exit", onExit);
|
|
113
|
+
};
|
|
95
114
|
let promises = [];
|
|
96
115
|
let _g = 0;
|
|
97
116
|
let _g1 = Project.projects;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {AnySpan} from "../profiler/Span"
|
|
1
2
|
import {Cache, CacheDurability, DurabilityCheck} from "./Cache"
|
|
2
3
|
import {AnyStone} from "../Stone"
|
|
3
4
|
import {SourceHash} from "../SourceHash"
|
|
@@ -47,4 +48,5 @@ export declare class BaseCache<Key, Value extends {
|
|
|
47
48
|
*/
|
|
48
49
|
protected replaceEntry(stone: AnyStone, existing: Value, replacement: Source): Promise<Value>
|
|
49
50
|
toString(): string
|
|
51
|
+
protected static setGenerateMeta(span: null | AnySpan, src: Source): void
|
|
50
52
|
}
|
|
@@ -23,12 +23,37 @@ class BaseCache extends Register.inherits() {
|
|
|
23
23
|
get(stone, durability, check) {
|
|
24
24
|
let _gthis = this;
|
|
25
25
|
return stone.acquire(function () {
|
|
26
|
-
|
|
26
|
+
let lockHeldSpan = (stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null;
|
|
27
|
+
return ((stone.project.profiler != null) ? stone.project.profiler.withSpan(stone, "Hash", function () {
|
|
28
|
+
return stone.finalMaybeHash().then(function (hash) {
|
|
29
|
+
let span = (stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null;
|
|
30
|
+
let meta = (hash != null) ? SourceHash.toHex(hash) : null;
|
|
31
|
+
if (span != null) {
|
|
32
|
+
span.metadata = {"hashHex": meta};
|
|
33
|
+
};
|
|
34
|
+
return hash;
|
|
35
|
+
});
|
|
36
|
+
}, null) : stone.finalMaybeHash().then(function (hash) {
|
|
37
|
+
let span = (stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null;
|
|
38
|
+
let meta = (hash != null) ? SourceHash.toHex(hash) : null;
|
|
39
|
+
if (span != null) {
|
|
40
|
+
span.metadata = {"hashHex": meta};
|
|
41
|
+
};
|
|
42
|
+
return hash;
|
|
43
|
+
})).then(function (hash) {
|
|
27
44
|
if (hash == null) {
|
|
28
45
|
Log.log(20, ...["Generating source, because it does not supply a hash.", {"stone": stone, "cache": _gthis}]);
|
|
29
46
|
};
|
|
30
47
|
if (hash == null) {
|
|
31
|
-
return stone.
|
|
48
|
+
return ((stone.project.profiler != null) ? stone.project.profiler.withSpan(stone, "Generate", function () {
|
|
49
|
+
return stone.generateSource(null).then(function (src) {
|
|
50
|
+
BaseCache.setGenerateMeta((stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null, src);
|
|
51
|
+
return src;
|
|
52
|
+
});
|
|
53
|
+
}, null) : stone.generateSource(null).then(function (src) {
|
|
54
|
+
BaseCache.setGenerateMeta((stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null, src);
|
|
55
|
+
return src;
|
|
56
|
+
})).then(function (generatedSource) {
|
|
32
57
|
return {"generatedSource": generatedSource, "hash": generatedSource.hash};
|
|
33
58
|
});
|
|
34
59
|
} else {
|
|
@@ -66,6 +91,9 @@ class BaseCache extends Register.inherits() {
|
|
|
66
91
|
let srcPromise = ((value != null) ? _gthis.source(stone, value) : Promise.resolve(null)).then(function (src) {
|
|
67
92
|
if (src == null) {
|
|
68
93
|
Log.log(10, ...["Not cached.", {"stone": stone, "cache": _gthis}]);
|
|
94
|
+
if (lockHeldSpan != null) {
|
|
95
|
+
lockHeldSpan.metadata = {"cacheResult": "miss"};
|
|
96
|
+
};
|
|
69
97
|
return ((value != null) ? _gthis.remove(stone, value) : Promise.resolve(null)).then(function (_) {
|
|
70
98
|
if (check._hx_index == 1) {
|
|
71
99
|
_gthis.checkDurability(stone, values, durability, function (v) {
|
|
@@ -74,19 +102,39 @@ class BaseCache extends Register.inherits() {
|
|
|
74
102
|
return ageCount(v) + 1;
|
|
75
103
|
});
|
|
76
104
|
};
|
|
77
|
-
return ((generatedSource != null) ? Promise.resolve(generatedSource) : stone.
|
|
78
|
-
return
|
|
105
|
+
return ((generatedSource != null) ? Promise.resolve(generatedSource) : (stone.project.profiler != null) ? stone.project.profiler.withSpan(stone, "Generate", function () {
|
|
106
|
+
return stone.generateSource(hash).then(function (src) {
|
|
107
|
+
BaseCache.setGenerateMeta((stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null, src);
|
|
108
|
+
return src;
|
|
109
|
+
});
|
|
110
|
+
}, null) : stone.generateSource(hash).then(function (src) {
|
|
111
|
+
BaseCache.setGenerateMeta((stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null, src);
|
|
112
|
+
return src;
|
|
113
|
+
})).then(function (src) {
|
|
114
|
+
if (stone.project.profiler != null) {
|
|
115
|
+
return stone.project.profiler.withSpan(stone, "CacheWrite", function () {
|
|
116
|
+
return _gthis.set(src);
|
|
117
|
+
}, null);
|
|
118
|
+
} else {
|
|
119
|
+
return _gthis.set(src);
|
|
120
|
+
};
|
|
79
121
|
}).then(function (val) {
|
|
80
122
|
return _gthis.source(stone, val);
|
|
81
123
|
});
|
|
82
124
|
});
|
|
83
125
|
} else if (!src.complete) {
|
|
84
126
|
Log.log(10, ...["Found partial entry in cache, completing.", {"stone": stone, "cache": _gthis}]);
|
|
127
|
+
if (lockHeldSpan != null) {
|
|
128
|
+
lockHeldSpan.metadata = {"cacheResult": "partial"};
|
|
129
|
+
};
|
|
85
130
|
return _gthis.completePartialEntry(stone, value, hash).then(function (val) {
|
|
86
131
|
return _gthis.source(stone, val);
|
|
87
132
|
});
|
|
88
133
|
} else {
|
|
89
134
|
Log.log(10, ...["Found in cache", {"stone": stone, "cache": _gthis}]);
|
|
135
|
+
if (lockHeldSpan != null) {
|
|
136
|
+
lockHeldSpan.metadata = {"cacheResult": "hit"};
|
|
137
|
+
};
|
|
90
138
|
return Promise.resolve(src);
|
|
91
139
|
};
|
|
92
140
|
});
|
|
@@ -104,7 +152,23 @@ class BaseCache extends Register.inherits() {
|
|
|
104
152
|
getPartial(stone, sourceId, durability, check) {
|
|
105
153
|
let _gthis = this;
|
|
106
154
|
return stone.acquire(function () {
|
|
107
|
-
return stone.
|
|
155
|
+
return ((stone.project.profiler != null) ? stone.project.profiler.withSpan(stone, "Hash", function () {
|
|
156
|
+
return stone.finalMaybeHash().then(function (hash) {
|
|
157
|
+
let span = (stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null;
|
|
158
|
+
let meta = (hash != null) ? SourceHash.toHex(hash) : null;
|
|
159
|
+
if (span != null) {
|
|
160
|
+
span.metadata = {"hashHex": meta};
|
|
161
|
+
};
|
|
162
|
+
return hash;
|
|
163
|
+
});
|
|
164
|
+
}, null) : stone.finalMaybeHash().then(function (hash) {
|
|
165
|
+
let span = (stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null;
|
|
166
|
+
let meta = (hash != null) ? SourceHash.toHex(hash) : null;
|
|
167
|
+
if (span != null) {
|
|
168
|
+
span.metadata = {"hashHex": meta};
|
|
169
|
+
};
|
|
170
|
+
return hash;
|
|
171
|
+
})).then(function (hash) {
|
|
108
172
|
let values = _gthis.cache.get(_gthis.key(stone));
|
|
109
173
|
let value = null;
|
|
110
174
|
if (values != null && values.length > 0) {
|
|
@@ -126,7 +190,9 @@ class BaseCache extends Register.inherits() {
|
|
|
126
190
|
} else if (value != null && value.complete) {
|
|
127
191
|
return Promise.resolve(null);
|
|
128
192
|
} else {
|
|
129
|
-
return stone.
|
|
193
|
+
return ((stone.project.profiler != null) ? stone.project.profiler.withSpan(stone, "GeneratePartial", function () {
|
|
194
|
+
return stone.generatePartialSource(sourceId, hash);
|
|
195
|
+
}, {"sourceId": sourceId}) : stone.generatePartialSource(sourceId, hash)).then(function (result) {
|
|
130
196
|
if (result.complete) {
|
|
131
197
|
return ((value != null) ? _gthis.replaceEntry(stone, value, result.source) : _gthis.set(result.source)).then(function (_) {
|
|
132
198
|
return result.source.filterTo(sourceId);
|
|
@@ -193,7 +259,21 @@ class BaseCache extends Register.inherits() {
|
|
|
193
259
|
*/
|
|
194
260
|
completePartialEntry(stone, existing, hash) {
|
|
195
261
|
let _gthis = this;
|
|
196
|
-
return stone.
|
|
262
|
+
return ((stone.project.profiler != null) ? stone.project.profiler.withSpan(stone, "List", function () {
|
|
263
|
+
return stone.list().then(function (ids) {
|
|
264
|
+
let span = (stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null;
|
|
265
|
+
if (span != null) {
|
|
266
|
+
span.metadata = {"resultCount": (ids != null) ? ids.length : null};
|
|
267
|
+
};
|
|
268
|
+
return ids;
|
|
269
|
+
});
|
|
270
|
+
}, null) : stone.list().then(function (ids) {
|
|
271
|
+
let span = (stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null;
|
|
272
|
+
if (span != null) {
|
|
273
|
+
span.metadata = {"resultCount": (ids != null) ? ids.length : null};
|
|
274
|
+
};
|
|
275
|
+
return ids;
|
|
276
|
+
})).then(function (allIds) {
|
|
197
277
|
if (allIds != null) {
|
|
198
278
|
let _g = [];
|
|
199
279
|
let _g1 = 0;
|
|
@@ -285,6 +365,15 @@ class BaseCache extends Register.inherits() {
|
|
|
285
365
|
let c = Boot.getClass(this);
|
|
286
366
|
return c.__name__;
|
|
287
367
|
}
|
|
368
|
+
static setGenerateMeta(span, src) {
|
|
369
|
+
if (span != null) {
|
|
370
|
+
let totalBytes = 0;
|
|
371
|
+
let _g = 0;
|
|
372
|
+
let _g1 = src.data;
|
|
373
|
+
while (_g < _g1.length) totalBytes += _g1[_g++].data.length;
|
|
374
|
+
span.metadata = {"outputCount": src.data.length, "totalBytes": totalBytes};
|
|
375
|
+
};
|
|
376
|
+
}
|
|
288
377
|
static get __name__() {
|
|
289
378
|
return "whet.cache.BaseCache"
|
|
290
379
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {MemoryCache} from "./MemoryCache.js"
|
|
2
2
|
import {FileCache} from "./FileCache.js"
|
|
3
3
|
import {CacheStrategy, CacheDurability, DurabilityCheck} from "./Cache.js"
|
|
4
|
+
import {BaseCache} from "./BaseCache.js"
|
|
4
5
|
import {RootDir} from "../SourceId.js"
|
|
6
|
+
import {SourceHash} from "../SourceHash.js"
|
|
5
7
|
import {Log} from "../Log.js"
|
|
6
8
|
import * as Path from "path"
|
|
7
9
|
import {Register} from "../../genes/Register.js"
|
|
@@ -26,8 +28,36 @@ class CacheManager extends Register.inherits() {
|
|
|
26
28
|
switch (_g._hx_index) {
|
|
27
29
|
case 0:
|
|
28
30
|
return stone.acquire(function () {
|
|
29
|
-
return stone.
|
|
30
|
-
return stone.
|
|
31
|
+
return ((stone.project.profiler != null) ? stone.project.profiler.withSpan(stone, "Hash", function () {
|
|
32
|
+
return stone.finalMaybeHash().then(function (hash) {
|
|
33
|
+
let span = (stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null;
|
|
34
|
+
let meta = (hash != null) ? SourceHash.toHex(hash) : null;
|
|
35
|
+
if (span != null) {
|
|
36
|
+
span.metadata = {"hashHex": meta};
|
|
37
|
+
};
|
|
38
|
+
return hash;
|
|
39
|
+
});
|
|
40
|
+
}, null) : stone.finalMaybeHash().then(function (hash) {
|
|
41
|
+
let span = (stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null;
|
|
42
|
+
let meta = (hash != null) ? SourceHash.toHex(hash) : null;
|
|
43
|
+
if (span != null) {
|
|
44
|
+
span.metadata = {"hashHex": meta};
|
|
45
|
+
};
|
|
46
|
+
return hash;
|
|
47
|
+
})).then(function (hash) {
|
|
48
|
+
if (stone.project.profiler != null) {
|
|
49
|
+
return stone.project.profiler.withSpan(stone, "Generate", function () {
|
|
50
|
+
return stone.generateSource(hash).then(function (src) {
|
|
51
|
+
BaseCache.setGenerateMeta((stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null, src);
|
|
52
|
+
return src;
|
|
53
|
+
});
|
|
54
|
+
}, null);
|
|
55
|
+
} else {
|
|
56
|
+
return stone.generateSource(hash).then(function (src) {
|
|
57
|
+
BaseCache.setGenerateMeta((stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null, src);
|
|
58
|
+
return src;
|
|
59
|
+
});
|
|
60
|
+
};
|
|
31
61
|
});
|
|
32
62
|
});
|
|
33
63
|
break
|
|
@@ -51,10 +81,34 @@ class CacheManager extends Register.inherits() {
|
|
|
51
81
|
switch (_g._hx_index) {
|
|
52
82
|
case 0:
|
|
53
83
|
return stone.acquire(function () {
|
|
54
|
-
return stone.
|
|
55
|
-
return stone.
|
|
56
|
-
|
|
84
|
+
return ((stone.project.profiler != null) ? stone.project.profiler.withSpan(stone, "Hash", function () {
|
|
85
|
+
return stone.finalMaybeHash().then(function (hash) {
|
|
86
|
+
let span = (stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null;
|
|
87
|
+
let meta = (hash != null) ? SourceHash.toHex(hash) : null;
|
|
88
|
+
if (span != null) {
|
|
89
|
+
span.metadata = {"hashHex": meta};
|
|
90
|
+
};
|
|
91
|
+
return hash;
|
|
57
92
|
});
|
|
93
|
+
}, null) : stone.finalMaybeHash().then(function (hash) {
|
|
94
|
+
let span = (stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null;
|
|
95
|
+
let meta = (hash != null) ? SourceHash.toHex(hash) : null;
|
|
96
|
+
if (span != null) {
|
|
97
|
+
span.metadata = {"hashHex": meta};
|
|
98
|
+
};
|
|
99
|
+
return hash;
|
|
100
|
+
})).then(function (hash) {
|
|
101
|
+
if (stone.project.profiler != null) {
|
|
102
|
+
return stone.project.profiler.withSpan(stone, "GeneratePartial", function () {
|
|
103
|
+
return stone.generatePartialSource(sourceId, hash).then(function (r) {
|
|
104
|
+
return r.source.filterTo(sourceId);
|
|
105
|
+
});
|
|
106
|
+
}, {"sourceId": sourceId});
|
|
107
|
+
} else {
|
|
108
|
+
return stone.generatePartialSource(sourceId, hash).then(function (r) {
|
|
109
|
+
return r.source.filterTo(sourceId);
|
|
110
|
+
});
|
|
111
|
+
};
|
|
58
112
|
});
|
|
59
113
|
});
|
|
60
114
|
break
|
|
@@ -82,8 +136,36 @@ class CacheManager extends Register.inherits() {
|
|
|
82
136
|
switch (stone.cacheStrategy._hx_index) {
|
|
83
137
|
case 0:
|
|
84
138
|
return stone.acquire(function () {
|
|
85
|
-
return stone.
|
|
86
|
-
return stone.
|
|
139
|
+
return ((stone.project.profiler != null) ? stone.project.profiler.withSpan(stone, "Hash", function () {
|
|
140
|
+
return stone.finalMaybeHash().then(function (hash) {
|
|
141
|
+
let span = (stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null;
|
|
142
|
+
let meta = (hash != null) ? SourceHash.toHex(hash) : null;
|
|
143
|
+
if (span != null) {
|
|
144
|
+
span.metadata = {"hashHex": meta};
|
|
145
|
+
};
|
|
146
|
+
return hash;
|
|
147
|
+
});
|
|
148
|
+
}, null) : stone.finalMaybeHash().then(function (hash) {
|
|
149
|
+
let span = (stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null;
|
|
150
|
+
let meta = (hash != null) ? SourceHash.toHex(hash) : null;
|
|
151
|
+
if (span != null) {
|
|
152
|
+
span.metadata = {"hashHex": meta};
|
|
153
|
+
};
|
|
154
|
+
return hash;
|
|
155
|
+
})).then(function (hash) {
|
|
156
|
+
if (stone.project.profiler != null) {
|
|
157
|
+
return stone.project.profiler.withSpan(stone, "Generate", function () {
|
|
158
|
+
return stone.generateSource(hash).then(function (src) {
|
|
159
|
+
BaseCache.setGenerateMeta((stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null, src);
|
|
160
|
+
return src;
|
|
161
|
+
});
|
|
162
|
+
}, null);
|
|
163
|
+
} else {
|
|
164
|
+
return stone.generateSource(hash).then(function (src) {
|
|
165
|
+
BaseCache.setGenerateMeta((stone.project.profiler != null) ? stone.project.profiler.getCurrentSpan() : null, src);
|
|
166
|
+
return src;
|
|
167
|
+
});
|
|
168
|
+
};
|
|
87
169
|
});
|
|
88
170
|
});
|
|
89
171
|
break
|