@microsoft/metrics-ts 0.0.2-alpha.0c8479eb2.0 → 0.0.2-alpha.0d47bc042.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.
@@ -1,2 +1,2 @@
1
- export { timer } from "./timer";
1
+ export { MSTimer } from "./timer";
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/capability/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/capability/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.timer = void 0;
3
+ exports.MSTimer = void 0;
4
4
  var timer_1 = require("./timer");
5
- Object.defineProperty(exports, "timer", { enumerable: true, get: function () { return timer_1.timer; } });
5
+ Object.defineProperty(exports, "MSTimer", { enumerable: true, get: function () { return timer_1.MSTimer; } });
6
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/capability/index.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAAvB,8FAAA,KAAK,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/capability/index.ts"],"names":[],"mappings":";;;AAAA,iCAAkC;AAAzB,gGAAA,OAAO,OAAA"}
@@ -1,2 +1,2 @@
1
- export declare const timer: (fn: string) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
1
+ export declare const MSTimer: (fn: string) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
2
2
  //# sourceMappingURL=timer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../../src/capability/timer.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,KAAK,OAAQ,MAAM,cAGd,GAAG,eAAe,MAAM,cAAc,kBAAkB,uBA+CzE,CAAC"}
1
+ {"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../../src/capability/timer.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,OAAO,OAAQ,MAAM,cAGhB,GAAG,eAAe,MAAM,cAAc,kBAAkB,uBAqEzE,CAAC"}
@@ -1,13 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.timer = void 0;
3
+ exports.MSTimer = void 0;
4
4
  /**
5
5
  * Timer - measures call-rate of a function and the distribution of the duration of all calls
6
6
  */
7
7
  const perf_hooks_1 = require("perf_hooks");
8
+ const rawData_1 = require("../rawData");
8
9
  const tracing_1 = require("../tracing");
9
10
  const writer_1 = require("../writer");
10
- const timer = (fn) => {
11
+ /**
12
+ * TODO: allow cutomization
13
+ * all in millsecond
14
+ */
15
+ const fast = 1;
16
+ const normal = 20;
17
+ const MSTimer = (fn) => {
11
18
  /* eslint-disable @typescript-eslint/no-explicit-any */
12
19
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
13
20
  return (target, propertyKey, descriptor) => {
@@ -28,8 +35,20 @@ const timer = (fn) => {
28
35
  const start = perf_hooks_1.performance.now();
29
36
  const result = await originalMethod.apply(this, args);
30
37
  const end = perf_hooks_1.performance.now();
38
+ const duration = end - start;
39
+ let severity;
40
+ if (duration > normal) {
41
+ severity = rawData_1.TimerSeverity.Slow;
42
+ }
43
+ else if (duration > fast) {
44
+ severity = rawData_1.TimerSeverity.Normal;
45
+ }
46
+ else {
47
+ severity = rawData_1.TimerSeverity.Fast;
48
+ }
31
49
  const timerData = {
32
- duraion: end - start,
50
+ duration: duration,
51
+ severity: severity,
33
52
  };
34
53
  data.timer = timerData;
35
54
  await (0, writer_1.appendOutput)(data);
@@ -42,8 +61,20 @@ const timer = (fn) => {
42
61
  const start = perf_hooks_1.performance.now();
43
62
  const result = originalMethod.apply(this, args);
44
63
  const end = perf_hooks_1.performance.now();
64
+ const duration = end - start;
65
+ let severity;
66
+ if (duration > normal) {
67
+ severity = rawData_1.TimerSeverity.Slow;
68
+ }
69
+ else if (duration > fast) {
70
+ severity = rawData_1.TimerSeverity.Normal;
71
+ }
72
+ else {
73
+ severity = rawData_1.TimerSeverity.Fast;
74
+ }
45
75
  const timerData = {
46
- duraion: end - start,
76
+ duration: duration,
77
+ severity: severity,
47
78
  };
48
79
  data.timer = timerData;
49
80
  (0, writer_1.appendOutputSync)(data);
@@ -53,5 +84,5 @@ const timer = (fn) => {
53
84
  return descriptor;
54
85
  };
55
86
  };
56
- exports.timer = timer;
87
+ exports.MSTimer = MSTimer;
57
88
  //# sourceMappingURL=timer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"timer.js","sourceRoot":"","sources":["../../src/capability/timer.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,2CAAyC;AAEzC,wCAAqC;AACrC,sCAA2D;AAEpD,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE;IAClC,wDAAwD;IACxD,uEAAuE;IACvE,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,UAA8B,EAAE,EAAE;QAC1E,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC;;WAEG;QACH,MAAM,IAAI,GAAe;YACvB,OAAO,EAAE,IAAA,iBAAO,GAAE;YAClB,IAAI,EAAE,EAAE;YACR,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI;YAC9B,MAAM,EAAE,cAAc,CAAC,IAAI;YAC3B,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC;QAEF,IAAI,cAAc,CAAC,WAAW,CAAC,IAAI,KAAK,eAAe,EAAE;YACvD,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAG,IAAW;gBAC/C,IAAI,CAAC,IAAI,GAAG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,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;gBAEvB,MAAM,IAAA,qBAAY,EAAC,IAAI,CAAC,CAAC;gBACzB,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC;SACH;aAAM;YACL,UAAU,CAAC,KAAK,GAAG,UAAU,GAAG,IAAW;gBACzC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;gBAEjB,MAAM,KAAK,GAAG,wBAAW,CAAC,GAAG,EAAE,CAAC;gBAChC,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAChD,MAAM,GAAG,GAAG,wBAAW,CAAC,GAAG,EAAE,CAAC;gBAC9B,MAAM,QAAQ,GAAG,GAAG,GAAG,KAAK,CAAC;gBAC7B,IAAI,QAAuB,CAAC;gBAC5B,IAAI,QAAQ,GAAG,MAAM,EAAE;oBACrB,QAAQ,GAAG,uBAAa,CAAC,IAAI,CAAC;iBAC/B;qBAAM,IAAI,QAAQ,GAAG,IAAI,EAAE;oBAC1B,QAAQ,GAAG,uBAAa,CAAC,MAAM,CAAC;iBACjC;qBAAM;oBACL,QAAQ,GAAG,uBAAa,CAAC,IAAI,CAAC;iBAC/B;gBACD,MAAM,SAAS,GAAc;oBAC3B,QAAQ,EAAE,QAAQ;oBAClB,QAAQ,EAAE,QAAQ;iBACnB,CAAC;gBAEF,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;gBAEvB,IAAA,yBAAgB,EAAC,IAAI,CAAC,CAAC;gBACvB,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC;SACH;QACD,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC,CAAC;AAxEW,QAAA,OAAO,WAwElB"}
@@ -7,7 +7,13 @@ export interface tracePoint {
7
7
  args?: any;
8
8
  timer?: timerData;
9
9
  }
10
+ export declare enum TimerSeverity {
11
+ Fast = "fast",
12
+ Normal = "normal",
13
+ Slow = "slow"
14
+ }
10
15
  export interface timerData {
11
- duraion: number;
16
+ duration: number;
17
+ severity: TimerSeverity;
12
18
  }
13
19
  //# sourceMappingURL=rawData.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rawData.d.ts","sourceRoot":"","sources":["../src/rawData.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAGhB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IAEf,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;CACjB"}
1
+ {"version":3,"file":"rawData.d.ts","sourceRoot":"","sources":["../src/rawData.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAGhB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IAEf,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAED,oBAAY,aAAa;IACvB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,IAAI,SAAS;CACd;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,aAAa,CAAC;CACzB"}
package/build/rawData.js CHANGED
@@ -1,3 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TimerSeverity = void 0;
4
+ var TimerSeverity;
5
+ (function (TimerSeverity) {
6
+ TimerSeverity["Fast"] = "fast";
7
+ TimerSeverity["Normal"] = "normal";
8
+ TimerSeverity["Slow"] = "slow";
9
+ })(TimerSeverity = exports.TimerSeverity || (exports.TimerSeverity = {}));
3
10
  //# sourceMappingURL=rawData.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rawData.js","sourceRoot":"","sources":["../src/rawData.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"rawData.js","sourceRoot":"","sources":["../src/rawData.ts"],"names":[],"mappings":";;;AAaA,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,8BAAa,CAAA;IACb,kCAAiB,CAAA;IACjB,8BAAa,CAAA;AACf,CAAC,EAJW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAIxB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/metrics-ts",
3
- "version": "0.0.2-alpha.0c8479eb2.0",
3
+ "version": "0.0.2-alpha.0d47bc042.0",
4
4
  "description": "Add metrics without intruding source code",
5
5
  "keywords": [
6
6
  "Metrics"
@@ -59,5 +59,5 @@
59
59
  "dependencies": {
60
60
  "uuid": "^8.3.2"
61
61
  },
62
- "gitHead": "20d795492c2079210d5c18537997f193f2e1a982"
62
+ "gitHead": "5b6ca3ff813c76f3955df2737a7f2aa2630c3dc0"
63
63
  }
@@ -1,25 +1,25 @@
1
1
  import * as path123 from "path";
2
- import { timer } from "@microsoft/metrics-ts";
2
+ import { MSTimer } from "@microsoft/metrics-ts";
3
3
 
4
4
  function delay(ms: number) {
5
5
  return new Promise((resolve) => setTimeout(resolve, ms));
6
6
  }
7
7
 
8
8
  class Foo {
9
- @timer()
9
+ @MSTimer(__filename)
10
10
  bar() {
11
11
  const r = this.baz();
12
12
  console.log(r);
13
13
  console.log(r.indexOf(0));
14
14
  }
15
15
 
16
- @timer()
16
+ @MSTimer(__filename)
17
17
  baz(): number[] {
18
18
  path123.join("a", "b");
19
19
  return [1];
20
20
  }
21
21
 
22
- @timer()
22
+ @MSTimer(__filename)
23
23
  async buz(arg: string, arg2: any) {
24
24
  await delay(1000);
25
25
  this.bar();
@@ -1 +1 @@
1
- export { timer } from "./timer";
1
+ export { MSTimer } from "./timer";
@@ -2,11 +2,18 @@
2
2
  * Timer - measures call-rate of a function and the distribution of the duration of all calls
3
3
  */
4
4
  import { performance } from "perf_hooks";
5
- import { timerData, tracePoint } from "../rawData";
5
+ import { timerData, TimerSeverity, tracePoint } from "../rawData";
6
6
  import { traceId } from "../tracing";
7
7
  import { appendOutput, appendOutputSync } from "../writer";
8
8
 
9
- export const timer = (fn: string) => {
9
+ /**
10
+ * TODO: allow cutomization
11
+ * all in millsecond
12
+ */
13
+ const fast = 1;
14
+ const normal = 20;
15
+
16
+ export const MSTimer = (fn: string) => {
10
17
  /* eslint-disable @typescript-eslint/no-explicit-any */
11
18
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
12
19
  return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
@@ -30,9 +37,20 @@ export const timer = (fn: string) => {
30
37
  const start = performance.now();
31
38
  const result = await originalMethod.apply(this, args);
32
39
  const end = performance.now();
40
+ const duration = end - start;
41
+ let severity: TimerSeverity;
42
+ if (duration > normal) {
43
+ severity = TimerSeverity.Slow;
44
+ } else if (duration > fast) {
45
+ severity = TimerSeverity.Normal;
46
+ } else {
47
+ severity = TimerSeverity.Fast;
48
+ }
33
49
  const timerData: timerData = {
34
- duraion: end - start,
50
+ duration: duration,
51
+ severity: severity,
35
52
  };
53
+
36
54
  data.timer = timerData;
37
55
 
38
56
  await appendOutput(data);
@@ -45,9 +63,20 @@ export const timer = (fn: string) => {
45
63
  const start = performance.now();
46
64
  const result = originalMethod.apply(this, args);
47
65
  const end = performance.now();
66
+ const duration = end - start;
67
+ let severity: TimerSeverity;
68
+ if (duration > normal) {
69
+ severity = TimerSeverity.Slow;
70
+ } else if (duration > fast) {
71
+ severity = TimerSeverity.Normal;
72
+ } else {
73
+ severity = TimerSeverity.Fast;
74
+ }
48
75
  const timerData: timerData = {
49
- duraion: end - start,
76
+ duration: duration,
77
+ severity: severity,
50
78
  };
79
+
51
80
  data.timer = timerData;
52
81
 
53
82
  appendOutputSync(data);
package/src/rawData.ts CHANGED
@@ -11,6 +11,13 @@ export interface tracePoint {
11
11
  timer?: timerData;
12
12
  }
13
13
 
14
+ export enum TimerSeverity {
15
+ Fast = "fast",
16
+ Normal = "normal",
17
+ Slow = "slow",
18
+ }
19
+
14
20
  export interface timerData {
15
- duraion: number;
21
+ duration: number;
22
+ severity: TimerSeverity;
16
23
  }