@abaplint/runtime 2.10.82 → 2.10.83

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.
@@ -50,6 +50,7 @@ import { FieldSymbol, Structure, Table } from "../types";
50
50
  import { INumeric } from "../types/_numeric";
51
51
  import { ICallFunctionOptions } from "./call_function";
52
52
  import { SelectDatabaseOptions, SelectRuntimeOptions } from "../db/db";
53
+ import { Trace } from "../trace";
53
54
  export declare class Statements {
54
55
  append: typeof append;
55
56
  assert: typeof assert;
@@ -91,11 +92,8 @@ export declare class Statements {
91
92
  receive: typeof receive;
92
93
  callTransaction: typeof callTransaction;
93
94
  private readonly context;
94
- private readonly traceTotals;
95
95
  constructor(context: Context);
96
- private _trace;
97
- private _traceAsync;
98
- _setTrace(min?: number, totals?: boolean): void;
96
+ _setTrace(min?: number, totals?: boolean): Trace;
99
97
  openCursor(target: INumeric, select: string, options: IOpenCursorDatabaseOptions): Promise<void>;
100
98
  fetchNextCursor(cursor: INumeric, target: any, packageSize?: INumeric): Promise<void>;
101
99
  closeCursor(cursor: INumeric): Promise<void>;
@@ -51,7 +51,7 @@ const call_transaction_1 = require("./call_transaction");
51
51
  const update_database_1 = require("./update_database");
52
52
  const write_1 = require("./write");
53
53
  const call_function_1 = require("./call_function");
54
- const types_1 = require("util/types");
54
+ const trace_1 = require("../trace");
55
55
  // this is a class, as statements like SELECT needs access to the database object instance
56
56
  // and WRITE will access the Console
57
57
  class Statements {
@@ -96,66 +96,9 @@ class Statements {
96
96
  this.receive = receive_1.receive;
97
97
  this.callTransaction = call_transaction_1.callTransaction;
98
98
  this.context = context;
99
- this.traceTotals = {};
100
- }
101
- _trace(func, name, min, totals) {
102
- const tt = this.traceTotals;
103
- const exec = (...options) => {
104
- const start = Date.now();
105
- const result = func.bind(this)(...options);
106
- const runtime = Date.now() - start;
107
- if (totals === true) {
108
- if (tt[name] === undefined) {
109
- tt[name] = 0;
110
- }
111
- tt[name] += runtime;
112
- }
113
- if (runtime >= min) {
114
- console.log(`STATEMENT: ${name}, ${runtime} ms`);
115
- if (totals === true) {
116
- console.log(JSON.stringify(tt));
117
- }
118
- }
119
- return result;
120
- };
121
- return exec;
122
- }
123
- _traceAsync(func, name, min, totals) {
124
- const tt = this.traceTotals;
125
- const exec = async (...options) => {
126
- const start = Date.now();
127
- const result = await func.bind(this)(...options);
128
- const runtime = Date.now() - start;
129
- if (totals === true) {
130
- if (tt[name] === undefined) {
131
- tt[name] = 0;
132
- }
133
- tt[name] += runtime;
134
- }
135
- if (runtime >= min) {
136
- console.log(`STATEMENT: ${name}, ${runtime} ms`);
137
- if (totals === true) {
138
- console.log(JSON.stringify(tt));
139
- }
140
- }
141
- return result;
142
- };
143
- return exec;
144
99
  }
145
100
  _setTrace(min = 10, totals = false) {
146
- const candidates = [...Object.keys(this), ...Object.getOwnPropertyNames(Statements.prototype)];
147
- for (const c of candidates) {
148
- if (c === "context" || c === "constructor" || c.startsWith("_") || c === "loop") {
149
- continue;
150
- }
151
- const func = this[c];
152
- if ((0, types_1.isAsyncFunction)(func)) {
153
- this[c] = this._traceAsync(func, c, min, totals);
154
- }
155
- else {
156
- this[c] = this._trace(func, c, min, totals);
157
- }
158
- }
101
+ return new trace_1.Trace().setTrace(min, totals, this);
159
102
  }
160
103
  async openCursor(target, select, options) {
161
104
  const num = await (0, open_cursor_1.openCursor)(this.context, select, options);
@@ -0,0 +1,12 @@
1
+ export declare class Trace {
2
+ private readonly traceTotals;
3
+ setTrace(min: number, totals: boolean, statements: any): this;
4
+ getTotals(): {
5
+ [name: string]: {
6
+ calls: number;
7
+ totalRuntime: number;
8
+ };
9
+ };
10
+ private _trace;
11
+ private _traceAsync;
12
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Trace = void 0;
4
+ const types_1 = require("util/types");
5
+ const statements_1 = require("./statements");
6
+ class Trace {
7
+ constructor() {
8
+ this.traceTotals = {};
9
+ }
10
+ setTrace(min, totals, statements) {
11
+ const candidates = [...Object.keys(statements), ...Object.getOwnPropertyNames(statements_1.Statements.prototype)];
12
+ for (const c of candidates) {
13
+ if (c === "context" || c === "constructor" || c.startsWith("_") || c === "loop") {
14
+ continue;
15
+ }
16
+ const func = statements[c];
17
+ if ((0, types_1.isAsyncFunction)(func)) {
18
+ statements[c] = this._traceAsync(func, c, min, totals);
19
+ }
20
+ else {
21
+ statements[c] = this._trace(func, c, min, totals);
22
+ }
23
+ }
24
+ return this;
25
+ }
26
+ getTotals() {
27
+ return this.traceTotals;
28
+ }
29
+ //////////////////////////////////////////
30
+ _trace(func, name, min, totals) {
31
+ const tt = this.traceTotals;
32
+ const exec1 = (...options) => {
33
+ const start = Date.now();
34
+ const result = func.bind(this)(...options);
35
+ const runtime = Date.now() - start;
36
+ if (totals === true) {
37
+ if (tt[name] === undefined) {
38
+ tt[name] = { calls: 0, totalRuntime: 0 };
39
+ }
40
+ tt[name].totalRuntime += runtime;
41
+ tt[name].calls++;
42
+ }
43
+ if (min > 0 && runtime >= min) {
44
+ console.log(`STATEMENT: ${name}, ${runtime} ms`);
45
+ if (totals === true) {
46
+ console.log(JSON.stringify(tt));
47
+ }
48
+ }
49
+ return result;
50
+ };
51
+ return exec1;
52
+ }
53
+ _traceAsync(func, name, min, totals) {
54
+ const tt = this.traceTotals;
55
+ const exec2 = async (...options) => {
56
+ const start = Date.now();
57
+ const result = await func.bind(this)(...options);
58
+ const runtime = Date.now() - start;
59
+ if (totals === true) {
60
+ if (tt[name] === undefined) {
61
+ tt[name] = { calls: 0, totalRuntime: 0 };
62
+ }
63
+ tt[name].totalRuntime += runtime;
64
+ tt[name].calls++;
65
+ }
66
+ if (min > 0 && runtime >= min) {
67
+ console.log(`STATEMENT: ${name}, ${runtime} ms`);
68
+ if (totals === true) {
69
+ console.log(JSON.stringify(tt));
70
+ }
71
+ }
72
+ return result;
73
+ };
74
+ return exec2;
75
+ }
76
+ }
77
+ exports.Trace = Trace;
78
+ //# sourceMappingURL=trace.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.10.82",
3
+ "version": "2.10.83",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",