@eggjs/core 7.0.0-beta.18 → 7.0.0-beta.20

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.
@@ -1,24 +0,0 @@
1
- //#region src/utils/timing.d.ts
2
- interface TimingItem {
3
- name: string;
4
- start: number;
5
- end?: number;
6
- duration?: number;
7
- pid: number;
8
- index: number;
9
- }
10
- declare class Timing {
11
- #private;
12
- constructor();
13
- init(): void;
14
- start(name?: string, start?: number): TimingItem | undefined;
15
- end(name?: string): TimingItem | undefined;
16
- enable(): void;
17
- disable(): void;
18
- clear(): void;
19
- toJSON(): TimingItem[];
20
- itemToString(timelineEnd: number, item: TimingItem, times: number): string;
21
- toString(prefix?: string, width?: number): string;
22
- }
23
- //#endregion
24
- export { Timing, TimingItem };
@@ -1,85 +0,0 @@
1
- import { debuglog } from "node:util";
2
- import assert from "node:assert";
3
- import { EOL } from "node:os";
4
-
5
- //#region src/utils/timing.ts
6
- const debug = debuglog("egg/core/utils/timing");
7
- var Timing = class {
8
- #enable;
9
- #startTime;
10
- #map;
11
- #list;
12
- constructor() {
13
- this.#enable = true;
14
- this.#map = /* @__PURE__ */ new Map();
15
- this.#list = [];
16
- this.init();
17
- }
18
- init() {
19
- this.start("Process Start", Date.now() - Math.floor(process.uptime() * 1e3));
20
- this.end("Process Start");
21
- if ("scriptStartTime" in process && typeof process.scriptStartTime === "number") {
22
- this.start("Script Start", process.scriptStartTime);
23
- this.end("Script Start");
24
- }
25
- }
26
- start(name, start) {
27
- if (!name || !this.#enable) return;
28
- if (this.#map.has(name)) this.end(name);
29
- start = start || Date.now();
30
- if (!this.#startTime) this.#startTime = start;
31
- const item = {
32
- name,
33
- start,
34
- pid: process.pid,
35
- index: this.#list.length
36
- };
37
- this.#map.set(name, item);
38
- this.#list.push(item);
39
- debug("start %j", item);
40
- return item;
41
- }
42
- end(name) {
43
- if (!name || !this.#enable) return;
44
- const item = this.#map.get(name);
45
- assert(item, `should run timing.start('${name}') first`);
46
- item.end = Date.now();
47
- item.duration = item.end - item.start;
48
- debug("end %j", item);
49
- return item;
50
- }
51
- enable() {
52
- this.#enable = true;
53
- }
54
- disable() {
55
- this.#enable = false;
56
- }
57
- clear() {
58
- this.#map.clear();
59
- this.#list = [];
60
- }
61
- toJSON() {
62
- return this.#list;
63
- }
64
- itemToString(timelineEnd, item, times) {
65
- const isEnd = typeof item.duration === "number";
66
- const duration = isEnd ? item.duration : timelineEnd - item.start;
67
- const offset = item.start - this.#startTime;
68
- const status = `${duration}ms${isEnd ? "" : " NOT_END"}`;
69
- const timespan = Math.floor(Number((offset * times).toFixed(6)));
70
- let timeline = Math.floor(Number((duration * times).toFixed(6)));
71
- timeline = timeline > 0 ? timeline : 1;
72
- const message = `#${item.index} ${item.name}`;
73
- return " ".repeat(timespan) + "▇".repeat(timeline) + ` [${status}] - ${message}`;
74
- }
75
- toString(prefix = "egg start timeline:", width = 50) {
76
- const timelineEnd = Date.now();
77
- const timelineDuration = timelineEnd - this.#startTime;
78
- let times = 1;
79
- if (timelineDuration > width) times = width / timelineDuration;
80
- return prefix + EOL + this.#list.map((item) => this.itemToString(timelineEnd, item, times)).join(EOL);
81
- }
82
- };
83
-
84
- //#endregion
85
- export { Timing };