@oino-ts/common 0.9.1 → 0.10.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/dist/cjs/OINOBenchmark.js +80 -31
- package/dist/cjs/OINOHtmlTemplate.js +6 -6
- package/dist/esm/OINOBenchmark.js +80 -31
- package/dist/esm/OINOHtmlTemplate.js +6 -6
- package/dist/types/OINOBenchmark.d.ts +45 -12
- package/package.json +2 -2
- package/src/OINOBenchmark.ts +94 -35
- package/src/OINOHtmlTemplate.ts +6 -6
|
@@ -56,8 +56,8 @@ class OINOBenchmark {
|
|
|
56
56
|
* @param module of the benchmark
|
|
57
57
|
* @param method of the benchmark
|
|
58
58
|
*/
|
|
59
|
-
static
|
|
60
|
-
OINOBenchmark._instance?.
|
|
59
|
+
static startMetric(module, method) {
|
|
60
|
+
OINOBenchmark._instance?._startMetric(module, method);
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
63
|
* Complete benchmark timing
|
|
@@ -66,8 +66,8 @@ class OINOBenchmark {
|
|
|
66
66
|
* @param method of the benchmark
|
|
67
67
|
* @param category optional subcategory of the benchmark
|
|
68
68
|
*/
|
|
69
|
-
static
|
|
70
|
-
|
|
69
|
+
static endMetric(module, method, category = "OK") {
|
|
70
|
+
OINOBenchmark._instance?._endMetric(module, method, category);
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* Get given benchmark data.
|
|
@@ -76,15 +76,51 @@ class OINOBenchmark {
|
|
|
76
76
|
* @param method of the benchmark
|
|
77
77
|
*
|
|
78
78
|
*/
|
|
79
|
-
static
|
|
80
|
-
return OINOBenchmark._instance?.
|
|
79
|
+
static getMetric(module, method) {
|
|
80
|
+
return OINOBenchmark._instance?._getMetric(module, method);
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* Get all benchmark data.
|
|
84
84
|
*
|
|
85
85
|
*/
|
|
86
|
-
static
|
|
87
|
-
return OINOBenchmark._instance?.
|
|
86
|
+
static getMetrics() {
|
|
87
|
+
return OINOBenchmark._instance?._getMetrics();
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Track a metric value
|
|
91
|
+
*
|
|
92
|
+
* @param value of the metric
|
|
93
|
+
* @param module of the metric
|
|
94
|
+
* @param method of the metric
|
|
95
|
+
* @param category optional subcategory of the metric
|
|
96
|
+
*
|
|
97
|
+
*/
|
|
98
|
+
static trackMetric(module, method, category, value) {
|
|
99
|
+
if (OINOBenchmark._enabled[module]) {
|
|
100
|
+
OINOBenchmark._instance?._trackMetric(module, method, category, value);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Track an exception
|
|
105
|
+
*
|
|
106
|
+
* @param module of the benchmark
|
|
107
|
+
* @param method of the benchmark
|
|
108
|
+
* @param category optional subcategory of the benchmark
|
|
109
|
+
* @param name of the exception
|
|
110
|
+
* @param message of the exception
|
|
111
|
+
* @param stack trace of the exception
|
|
112
|
+
*/
|
|
113
|
+
static trackException(module, method, category, name, message, stack) {
|
|
114
|
+
if (OINOBenchmark._enabled[module]) {
|
|
115
|
+
OINOBenchmark._instance?._trackException(module, method, category, name, message, stack);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Get all tracked exceptions.
|
|
120
|
+
*
|
|
121
|
+
*/
|
|
122
|
+
static getExceptions() {
|
|
123
|
+
return OINOBenchmark._instance?._getExceptions();
|
|
88
124
|
}
|
|
89
125
|
}
|
|
90
126
|
exports.OINOBenchmark = OINOBenchmark;
|
|
@@ -97,6 +133,7 @@ class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
97
133
|
_benchmarkCount = {};
|
|
98
134
|
_benchmarkData = {};
|
|
99
135
|
_benchmarkStart = {};
|
|
136
|
+
_exceptions = [];
|
|
100
137
|
/**
|
|
101
138
|
* Reset benchmark data (but not what is enabled).
|
|
102
139
|
*
|
|
@@ -111,13 +148,9 @@ class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
111
148
|
* @param module of the benchmark
|
|
112
149
|
* @param method of the benchmark
|
|
113
150
|
*/
|
|
114
|
-
|
|
151
|
+
_startMetric(module, method) {
|
|
115
152
|
const name = module + "." + method;
|
|
116
153
|
if (OINOBenchmark._enabled[module] && ((this._benchmarkStart[name] === undefined) || (this._benchmarkStart[name] === 0))) { // if benchmark is already started (e.g. loop/recursion), do not start it again
|
|
117
|
-
if (this._benchmarkCount[name] == undefined) {
|
|
118
|
-
this._benchmarkCount[name] = 0;
|
|
119
|
-
this._benchmarkData[name] = 0;
|
|
120
|
-
}
|
|
121
154
|
this._benchmarkStart[name] = performance.now();
|
|
122
155
|
}
|
|
123
156
|
}
|
|
@@ -128,26 +161,14 @@ class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
128
161
|
* @param method of the benchmark
|
|
129
162
|
* @param category optional subcategory of the benchmark
|
|
130
163
|
*/
|
|
131
|
-
|
|
164
|
+
_endMetric(module, method, category) {
|
|
132
165
|
const name = module + "." + method;
|
|
133
166
|
let result = 0;
|
|
134
|
-
if (OINOBenchmark._enabled[module]) {
|
|
167
|
+
if (OINOBenchmark._enabled[module] && (this._benchmarkStart[name] > 0)) { // if benchmark is started, end it
|
|
135
168
|
const duration = performance.now() - this._benchmarkStart[name];
|
|
136
|
-
this.
|
|
137
|
-
this._benchmarkData[name] += duration;
|
|
138
|
-
if (category) {
|
|
139
|
-
const category_name = name + "." + category;
|
|
140
|
-
if (this._benchmarkCount[category_name] == undefined) {
|
|
141
|
-
this._benchmarkCount[category_name] = 0;
|
|
142
|
-
this._benchmarkData[category_name] = 0;
|
|
143
|
-
}
|
|
144
|
-
this._benchmarkCount[category_name] += 1;
|
|
145
|
-
this._benchmarkData[category_name] += duration;
|
|
146
|
-
}
|
|
147
|
-
result = this._benchmarkData[name] / this._benchmarkCount[name];
|
|
148
|
-
this._benchmarkStart[name] = 0;
|
|
169
|
+
this._trackMetric(module, method, category, duration);
|
|
149
170
|
}
|
|
150
|
-
return
|
|
171
|
+
return;
|
|
151
172
|
}
|
|
152
173
|
/**
|
|
153
174
|
* Get given benchmark data.
|
|
@@ -156,7 +177,7 @@ class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
156
177
|
* @param method of the benchmark
|
|
157
178
|
*
|
|
158
179
|
*/
|
|
159
|
-
|
|
180
|
+
_getMetric(module, method) {
|
|
160
181
|
const name = module + "." + method;
|
|
161
182
|
if (OINOBenchmark._enabled[module] && (this._benchmarkCount[name] > 0)) {
|
|
162
183
|
return this._benchmarkData[module] / this._benchmarkCount[module];
|
|
@@ -167,7 +188,7 @@ class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
167
188
|
* Get all benchmark data.
|
|
168
189
|
*
|
|
169
190
|
*/
|
|
170
|
-
|
|
191
|
+
_getMetrics() {
|
|
171
192
|
let result = {};
|
|
172
193
|
for (const name in this._benchmarkData) {
|
|
173
194
|
if (this._benchmarkCount[name] > 0) {
|
|
@@ -176,5 +197,33 @@ class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
176
197
|
}
|
|
177
198
|
return result;
|
|
178
199
|
}
|
|
200
|
+
_trackMetric(module, method, category, value) {
|
|
201
|
+
const name = module + "." + method;
|
|
202
|
+
if (this._benchmarkCount[name] == undefined) {
|
|
203
|
+
this._benchmarkCount[name] = 1;
|
|
204
|
+
this._benchmarkData[name] = value;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
this._benchmarkCount[name] += 1;
|
|
208
|
+
this._benchmarkData[name] += value;
|
|
209
|
+
}
|
|
210
|
+
const category_name = name + "." + category;
|
|
211
|
+
if (this._benchmarkCount[category_name] == undefined) {
|
|
212
|
+
this._benchmarkCount[category_name] = 1;
|
|
213
|
+
this._benchmarkData[category_name] = value;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
this._benchmarkCount[category_name] += 1;
|
|
217
|
+
this._benchmarkData[category_name] += value;
|
|
218
|
+
}
|
|
219
|
+
this._benchmarkStart[name] = 0;
|
|
220
|
+
}
|
|
221
|
+
_trackException(module, method, category, name, message, stack) {
|
|
222
|
+
const exception = { module, method, category, name, message, stack };
|
|
223
|
+
this._exceptions.push(exception);
|
|
224
|
+
}
|
|
225
|
+
_getExceptions() {
|
|
226
|
+
return this._exceptions;
|
|
227
|
+
}
|
|
179
228
|
}
|
|
180
229
|
exports.OINOMemoryBenchmark = OINOMemoryBenchmark;
|
|
@@ -116,10 +116,10 @@ class OINOHtmlTemplate {
|
|
|
116
116
|
*
|
|
117
117
|
*/
|
|
118
118
|
renderFromKeyValue(key, value, removeUnusedTags = true) {
|
|
119
|
-
_1.OINOBenchmark.
|
|
119
|
+
_1.OINOBenchmark.startMetric("OINOHtmlTemplate", "renderFromKeyValue");
|
|
120
120
|
this.setVariableFromValue(key, value);
|
|
121
121
|
const result = this.render(removeUnusedTags);
|
|
122
|
-
_1.OINOBenchmark.
|
|
122
|
+
_1.OINOBenchmark.endMetric("OINOHtmlTemplate", "renderFromKeyValue");
|
|
123
123
|
return result;
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
@@ -130,10 +130,10 @@ class OINOHtmlTemplate {
|
|
|
130
130
|
*
|
|
131
131
|
*/
|
|
132
132
|
renderFromObject(object, removeUnusedTags = true) {
|
|
133
|
-
_1.OINOBenchmark.
|
|
133
|
+
_1.OINOBenchmark.startMetric("OINOHtmlTemplate", "renderFromObject");
|
|
134
134
|
this.setVariableFromProperties(object);
|
|
135
135
|
const result = this.render(removeUnusedTags);
|
|
136
|
-
_1.OINOBenchmark.
|
|
136
|
+
_1.OINOBenchmark.endMetric("OINOHtmlTemplate", "renderFromObject");
|
|
137
137
|
return result;
|
|
138
138
|
}
|
|
139
139
|
/**
|
|
@@ -149,7 +149,7 @@ class OINOHtmlTemplate {
|
|
|
149
149
|
*
|
|
150
150
|
*/
|
|
151
151
|
renderFromResult(result, removeUnusedTags = true, messageSeparator = "", includeErrorMessages = false, includeWarningMessages = false, includeInfoMessages = false, includeDebugMessages = false) {
|
|
152
|
-
_1.OINOBenchmark.
|
|
152
|
+
_1.OINOBenchmark.startMetric("OINOHtmlTemplate", "renderFromResult");
|
|
153
153
|
this.setVariableFromValue("statusCode", result.statusCode.toString());
|
|
154
154
|
this.setVariableFromValue("statusMessage", result.statusMessage.toString());
|
|
155
155
|
let messages = [];
|
|
@@ -171,7 +171,7 @@ class OINOHtmlTemplate {
|
|
|
171
171
|
this.setVariableFromValue("messages", messages.join(messageSeparator), false); // messages have been escaped already
|
|
172
172
|
}
|
|
173
173
|
const http_result = this.render(removeUnusedTags);
|
|
174
|
-
_1.OINOBenchmark.
|
|
174
|
+
_1.OINOBenchmark.endMetric("OINOHtmlTemplate", "renderFromResult");
|
|
175
175
|
return http_result;
|
|
176
176
|
}
|
|
177
177
|
}
|
|
@@ -53,8 +53,8 @@ export class OINOBenchmark {
|
|
|
53
53
|
* @param module of the benchmark
|
|
54
54
|
* @param method of the benchmark
|
|
55
55
|
*/
|
|
56
|
-
static
|
|
57
|
-
OINOBenchmark._instance?.
|
|
56
|
+
static startMetric(module, method) {
|
|
57
|
+
OINOBenchmark._instance?._startMetric(module, method);
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
60
|
* Complete benchmark timing
|
|
@@ -63,8 +63,8 @@ export class OINOBenchmark {
|
|
|
63
63
|
* @param method of the benchmark
|
|
64
64
|
* @param category optional subcategory of the benchmark
|
|
65
65
|
*/
|
|
66
|
-
static
|
|
67
|
-
|
|
66
|
+
static endMetric(module, method, category = "OK") {
|
|
67
|
+
OINOBenchmark._instance?._endMetric(module, method, category);
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
70
|
* Get given benchmark data.
|
|
@@ -73,15 +73,51 @@ export class OINOBenchmark {
|
|
|
73
73
|
* @param method of the benchmark
|
|
74
74
|
*
|
|
75
75
|
*/
|
|
76
|
-
static
|
|
77
|
-
return OINOBenchmark._instance?.
|
|
76
|
+
static getMetric(module, method) {
|
|
77
|
+
return OINOBenchmark._instance?._getMetric(module, method);
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* Get all benchmark data.
|
|
81
81
|
*
|
|
82
82
|
*/
|
|
83
|
-
static
|
|
84
|
-
return OINOBenchmark._instance?.
|
|
83
|
+
static getMetrics() {
|
|
84
|
+
return OINOBenchmark._instance?._getMetrics();
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Track a metric value
|
|
88
|
+
*
|
|
89
|
+
* @param value of the metric
|
|
90
|
+
* @param module of the metric
|
|
91
|
+
* @param method of the metric
|
|
92
|
+
* @param category optional subcategory of the metric
|
|
93
|
+
*
|
|
94
|
+
*/
|
|
95
|
+
static trackMetric(module, method, category, value) {
|
|
96
|
+
if (OINOBenchmark._enabled[module]) {
|
|
97
|
+
OINOBenchmark._instance?._trackMetric(module, method, category, value);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Track an exception
|
|
102
|
+
*
|
|
103
|
+
* @param module of the benchmark
|
|
104
|
+
* @param method of the benchmark
|
|
105
|
+
* @param category optional subcategory of the benchmark
|
|
106
|
+
* @param name of the exception
|
|
107
|
+
* @param message of the exception
|
|
108
|
+
* @param stack trace of the exception
|
|
109
|
+
*/
|
|
110
|
+
static trackException(module, method, category, name, message, stack) {
|
|
111
|
+
if (OINOBenchmark._enabled[module]) {
|
|
112
|
+
OINOBenchmark._instance?._trackException(module, method, category, name, message, stack);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get all tracked exceptions.
|
|
117
|
+
*
|
|
118
|
+
*/
|
|
119
|
+
static getExceptions() {
|
|
120
|
+
return OINOBenchmark._instance?._getExceptions();
|
|
85
121
|
}
|
|
86
122
|
}
|
|
87
123
|
/**
|
|
@@ -93,6 +129,7 @@ export class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
93
129
|
_benchmarkCount = {};
|
|
94
130
|
_benchmarkData = {};
|
|
95
131
|
_benchmarkStart = {};
|
|
132
|
+
_exceptions = [];
|
|
96
133
|
/**
|
|
97
134
|
* Reset benchmark data (but not what is enabled).
|
|
98
135
|
*
|
|
@@ -107,13 +144,9 @@ export class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
107
144
|
* @param module of the benchmark
|
|
108
145
|
* @param method of the benchmark
|
|
109
146
|
*/
|
|
110
|
-
|
|
147
|
+
_startMetric(module, method) {
|
|
111
148
|
const name = module + "." + method;
|
|
112
149
|
if (OINOBenchmark._enabled[module] && ((this._benchmarkStart[name] === undefined) || (this._benchmarkStart[name] === 0))) { // if benchmark is already started (e.g. loop/recursion), do not start it again
|
|
113
|
-
if (this._benchmarkCount[name] == undefined) {
|
|
114
|
-
this._benchmarkCount[name] = 0;
|
|
115
|
-
this._benchmarkData[name] = 0;
|
|
116
|
-
}
|
|
117
150
|
this._benchmarkStart[name] = performance.now();
|
|
118
151
|
}
|
|
119
152
|
}
|
|
@@ -124,26 +157,14 @@ export class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
124
157
|
* @param method of the benchmark
|
|
125
158
|
* @param category optional subcategory of the benchmark
|
|
126
159
|
*/
|
|
127
|
-
|
|
160
|
+
_endMetric(module, method, category) {
|
|
128
161
|
const name = module + "." + method;
|
|
129
162
|
let result = 0;
|
|
130
|
-
if (OINOBenchmark._enabled[module]) {
|
|
163
|
+
if (OINOBenchmark._enabled[module] && (this._benchmarkStart[name] > 0)) { // if benchmark is started, end it
|
|
131
164
|
const duration = performance.now() - this._benchmarkStart[name];
|
|
132
|
-
this.
|
|
133
|
-
this._benchmarkData[name] += duration;
|
|
134
|
-
if (category) {
|
|
135
|
-
const category_name = name + "." + category;
|
|
136
|
-
if (this._benchmarkCount[category_name] == undefined) {
|
|
137
|
-
this._benchmarkCount[category_name] = 0;
|
|
138
|
-
this._benchmarkData[category_name] = 0;
|
|
139
|
-
}
|
|
140
|
-
this._benchmarkCount[category_name] += 1;
|
|
141
|
-
this._benchmarkData[category_name] += duration;
|
|
142
|
-
}
|
|
143
|
-
result = this._benchmarkData[name] / this._benchmarkCount[name];
|
|
144
|
-
this._benchmarkStart[name] = 0;
|
|
165
|
+
this._trackMetric(module, method, category, duration);
|
|
145
166
|
}
|
|
146
|
-
return
|
|
167
|
+
return;
|
|
147
168
|
}
|
|
148
169
|
/**
|
|
149
170
|
* Get given benchmark data.
|
|
@@ -152,7 +173,7 @@ export class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
152
173
|
* @param method of the benchmark
|
|
153
174
|
*
|
|
154
175
|
*/
|
|
155
|
-
|
|
176
|
+
_getMetric(module, method) {
|
|
156
177
|
const name = module + "." + method;
|
|
157
178
|
if (OINOBenchmark._enabled[module] && (this._benchmarkCount[name] > 0)) {
|
|
158
179
|
return this._benchmarkData[module] / this._benchmarkCount[module];
|
|
@@ -163,7 +184,7 @@ export class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
163
184
|
* Get all benchmark data.
|
|
164
185
|
*
|
|
165
186
|
*/
|
|
166
|
-
|
|
187
|
+
_getMetrics() {
|
|
167
188
|
let result = {};
|
|
168
189
|
for (const name in this._benchmarkData) {
|
|
169
190
|
if (this._benchmarkCount[name] > 0) {
|
|
@@ -172,4 +193,32 @@ export class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
172
193
|
}
|
|
173
194
|
return result;
|
|
174
195
|
}
|
|
196
|
+
_trackMetric(module, method, category, value) {
|
|
197
|
+
const name = module + "." + method;
|
|
198
|
+
if (this._benchmarkCount[name] == undefined) {
|
|
199
|
+
this._benchmarkCount[name] = 1;
|
|
200
|
+
this._benchmarkData[name] = value;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
this._benchmarkCount[name] += 1;
|
|
204
|
+
this._benchmarkData[name] += value;
|
|
205
|
+
}
|
|
206
|
+
const category_name = name + "." + category;
|
|
207
|
+
if (this._benchmarkCount[category_name] == undefined) {
|
|
208
|
+
this._benchmarkCount[category_name] = 1;
|
|
209
|
+
this._benchmarkData[category_name] = value;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
this._benchmarkCount[category_name] += 1;
|
|
213
|
+
this._benchmarkData[category_name] += value;
|
|
214
|
+
}
|
|
215
|
+
this._benchmarkStart[name] = 0;
|
|
216
|
+
}
|
|
217
|
+
_trackException(module, method, category, name, message, stack) {
|
|
218
|
+
const exception = { module, method, category, name, message, stack };
|
|
219
|
+
this._exceptions.push(exception);
|
|
220
|
+
}
|
|
221
|
+
_getExceptions() {
|
|
222
|
+
return this._exceptions;
|
|
223
|
+
}
|
|
175
224
|
}
|
|
@@ -113,10 +113,10 @@ export class OINOHtmlTemplate {
|
|
|
113
113
|
*
|
|
114
114
|
*/
|
|
115
115
|
renderFromKeyValue(key, value, removeUnusedTags = true) {
|
|
116
|
-
OINOBenchmark.
|
|
116
|
+
OINOBenchmark.startMetric("OINOHtmlTemplate", "renderFromKeyValue");
|
|
117
117
|
this.setVariableFromValue(key, value);
|
|
118
118
|
const result = this.render(removeUnusedTags);
|
|
119
|
-
OINOBenchmark.
|
|
119
|
+
OINOBenchmark.endMetric("OINOHtmlTemplate", "renderFromKeyValue");
|
|
120
120
|
return result;
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
@@ -127,10 +127,10 @@ export class OINOHtmlTemplate {
|
|
|
127
127
|
*
|
|
128
128
|
*/
|
|
129
129
|
renderFromObject(object, removeUnusedTags = true) {
|
|
130
|
-
OINOBenchmark.
|
|
130
|
+
OINOBenchmark.startMetric("OINOHtmlTemplate", "renderFromObject");
|
|
131
131
|
this.setVariableFromProperties(object);
|
|
132
132
|
const result = this.render(removeUnusedTags);
|
|
133
|
-
OINOBenchmark.
|
|
133
|
+
OINOBenchmark.endMetric("OINOHtmlTemplate", "renderFromObject");
|
|
134
134
|
return result;
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
@@ -146,7 +146,7 @@ export class OINOHtmlTemplate {
|
|
|
146
146
|
*
|
|
147
147
|
*/
|
|
148
148
|
renderFromResult(result, removeUnusedTags = true, messageSeparator = "", includeErrorMessages = false, includeWarningMessages = false, includeInfoMessages = false, includeDebugMessages = false) {
|
|
149
|
-
OINOBenchmark.
|
|
149
|
+
OINOBenchmark.startMetric("OINOHtmlTemplate", "renderFromResult");
|
|
150
150
|
this.setVariableFromValue("statusCode", result.statusCode.toString());
|
|
151
151
|
this.setVariableFromValue("statusMessage", result.statusMessage.toString());
|
|
152
152
|
let messages = [];
|
|
@@ -168,7 +168,7 @@ export class OINOHtmlTemplate {
|
|
|
168
168
|
this.setVariableFromValue("messages", messages.join(messageSeparator), false); // messages have been escaped already
|
|
169
169
|
}
|
|
170
170
|
const http_result = this.render(removeUnusedTags);
|
|
171
|
-
OINOBenchmark.
|
|
171
|
+
OINOBenchmark.endMetric("OINOHtmlTemplate", "renderFromResult");
|
|
172
172
|
return http_result;
|
|
173
173
|
}
|
|
174
174
|
}
|
|
@@ -30,15 +30,15 @@ export declare abstract class OINOBenchmark {
|
|
|
30
30
|
* @param modules array of those benchmarks that are enabled
|
|
31
31
|
*/
|
|
32
32
|
static setEnabled(modules: string[]): void;
|
|
33
|
-
protected abstract
|
|
33
|
+
protected abstract _startMetric(module: string, method: string): void;
|
|
34
34
|
/**
|
|
35
35
|
* Start benchmark timing.
|
|
36
36
|
*
|
|
37
37
|
* @param module of the benchmark
|
|
38
38
|
* @param method of the benchmark
|
|
39
39
|
*/
|
|
40
|
-
static
|
|
41
|
-
protected abstract
|
|
40
|
+
static startMetric(module: string, method: string): void;
|
|
41
|
+
protected abstract _endMetric(module: string, method: string, category: string): void;
|
|
42
42
|
/**
|
|
43
43
|
* Complete benchmark timing
|
|
44
44
|
*
|
|
@@ -46,8 +46,8 @@ export declare abstract class OINOBenchmark {
|
|
|
46
46
|
* @param method of the benchmark
|
|
47
47
|
* @param category optional subcategory of the benchmark
|
|
48
48
|
*/
|
|
49
|
-
static
|
|
50
|
-
protected abstract
|
|
49
|
+
static endMetric(module: string, method: string, category?: string): void;
|
|
50
|
+
protected abstract _getMetric(module: string, method: string): number;
|
|
51
51
|
/**
|
|
52
52
|
* Get given benchmark data.
|
|
53
53
|
*
|
|
@@ -55,13 +55,42 @@ export declare abstract class OINOBenchmark {
|
|
|
55
55
|
* @param method of the benchmark
|
|
56
56
|
*
|
|
57
57
|
*/
|
|
58
|
-
static
|
|
59
|
-
protected abstract
|
|
58
|
+
static getMetric(module: string, method: string): number;
|
|
59
|
+
protected abstract _getMetrics(): Record<string, number>;
|
|
60
60
|
/**
|
|
61
61
|
* Get all benchmark data.
|
|
62
62
|
*
|
|
63
63
|
*/
|
|
64
|
-
static
|
|
64
|
+
static getMetrics(): Record<string, number>;
|
|
65
|
+
protected abstract _trackMetric(module: string, method: string, category: string, value: number): void;
|
|
66
|
+
/**
|
|
67
|
+
* Track a metric value
|
|
68
|
+
*
|
|
69
|
+
* @param value of the metric
|
|
70
|
+
* @param module of the metric
|
|
71
|
+
* @param method of the metric
|
|
72
|
+
* @param category optional subcategory of the metric
|
|
73
|
+
*
|
|
74
|
+
*/
|
|
75
|
+
static trackMetric(module: string, method: string, category: string, value: number): void;
|
|
76
|
+
protected abstract _trackException(module: string, method: string, category: string, name: string, message: string, stack: string): void;
|
|
77
|
+
/**
|
|
78
|
+
* Track an exception
|
|
79
|
+
*
|
|
80
|
+
* @param module of the benchmark
|
|
81
|
+
* @param method of the benchmark
|
|
82
|
+
* @param category optional subcategory of the benchmark
|
|
83
|
+
* @param name of the exception
|
|
84
|
+
* @param message of the exception
|
|
85
|
+
* @param stack trace of the exception
|
|
86
|
+
*/
|
|
87
|
+
static trackException(module: string, method: string, category: string, name: string, message: string, stack: string): void;
|
|
88
|
+
protected abstract _getExceptions(): any[];
|
|
89
|
+
/**
|
|
90
|
+
* Get all tracked exceptions.
|
|
91
|
+
*
|
|
92
|
+
*/
|
|
93
|
+
static getExceptions(): any[];
|
|
65
94
|
}
|
|
66
95
|
/**
|
|
67
96
|
* OINOMemoryBenchmark is a memory-based benchmark implementation.
|
|
@@ -72,6 +101,7 @@ export declare class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
72
101
|
protected _benchmarkCount: Record<string, number>;
|
|
73
102
|
protected _benchmarkData: Record<string, number>;
|
|
74
103
|
protected _benchmarkStart: Record<string, number>;
|
|
104
|
+
protected _exceptions: any[];
|
|
75
105
|
/**
|
|
76
106
|
* Reset benchmark data (but not what is enabled).
|
|
77
107
|
*
|
|
@@ -83,7 +113,7 @@ export declare class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
83
113
|
* @param module of the benchmark
|
|
84
114
|
* @param method of the benchmark
|
|
85
115
|
*/
|
|
86
|
-
protected
|
|
116
|
+
protected _startMetric(module: string, method: string): void;
|
|
87
117
|
/**
|
|
88
118
|
* Complete benchmark timing
|
|
89
119
|
*
|
|
@@ -91,7 +121,7 @@ export declare class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
91
121
|
* @param method of the benchmark
|
|
92
122
|
* @param category optional subcategory of the benchmark
|
|
93
123
|
*/
|
|
94
|
-
protected
|
|
124
|
+
protected _endMetric(module: string, method: string, category: string): void;
|
|
95
125
|
/**
|
|
96
126
|
* Get given benchmark data.
|
|
97
127
|
*
|
|
@@ -99,10 +129,13 @@ export declare class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
99
129
|
* @param method of the benchmark
|
|
100
130
|
*
|
|
101
131
|
*/
|
|
102
|
-
protected
|
|
132
|
+
protected _getMetric(module: string, method: string): number;
|
|
103
133
|
/**
|
|
104
134
|
* Get all benchmark data.
|
|
105
135
|
*
|
|
106
136
|
*/
|
|
107
|
-
protected
|
|
137
|
+
protected _getMetrics(): Record<string, number>;
|
|
138
|
+
protected _trackMetric(module: string, method: string, category: string, value: number): void;
|
|
139
|
+
protected _trackException(module: string, method: string, category: string, name: string, message: string, stack: string): void;
|
|
140
|
+
protected _getExceptions(): any[];
|
|
108
141
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oino-ts/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "OINO TS package for common classes.",
|
|
5
5
|
"author": "Matias Kiviniemi (pragmatta)",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@oino-ts/types": "0.
|
|
22
|
+
"@oino-ts/types": "0.10.0"
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"src/*.ts",
|
package/src/OINOBenchmark.ts
CHANGED
|
@@ -56,18 +56,18 @@ export abstract class OINOBenchmark {
|
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
protected abstract
|
|
59
|
+
protected abstract _startMetric(module:string, method:string):void
|
|
60
60
|
/**
|
|
61
61
|
* Start benchmark timing.
|
|
62
62
|
*
|
|
63
63
|
* @param module of the benchmark
|
|
64
64
|
* @param method of the benchmark
|
|
65
65
|
*/
|
|
66
|
-
static
|
|
67
|
-
OINOBenchmark._instance?.
|
|
66
|
+
static startMetric(module:string, method:string):void {
|
|
67
|
+
OINOBenchmark._instance?._startMetric(module, method)
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
protected abstract
|
|
70
|
+
protected abstract _endMetric(module:string, method:string, category:string):void
|
|
71
71
|
/**
|
|
72
72
|
* Complete benchmark timing
|
|
73
73
|
*
|
|
@@ -75,11 +75,11 @@ export abstract class OINOBenchmark {
|
|
|
75
75
|
* @param method of the benchmark
|
|
76
76
|
* @param category optional subcategory of the benchmark
|
|
77
77
|
*/
|
|
78
|
-
static
|
|
79
|
-
|
|
78
|
+
static endMetric(module:string, method:string, category:string = "OK"):void {
|
|
79
|
+
OINOBenchmark._instance?._endMetric(module, method, category)
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
protected abstract
|
|
82
|
+
protected abstract _getMetric(module:string, method:string):number
|
|
83
83
|
/**
|
|
84
84
|
* Get given benchmark data.
|
|
85
85
|
*
|
|
@@ -87,17 +87,59 @@ export abstract class OINOBenchmark {
|
|
|
87
87
|
* @param method of the benchmark
|
|
88
88
|
*
|
|
89
89
|
*/
|
|
90
|
-
static
|
|
91
|
-
return OINOBenchmark._instance?.
|
|
90
|
+
static getMetric(module:string, method:string):number {
|
|
91
|
+
return OINOBenchmark._instance?._getMetric(module, method)
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
protected abstract
|
|
94
|
+
protected abstract _getMetrics():Record<string, number>
|
|
95
95
|
/**
|
|
96
96
|
* Get all benchmark data.
|
|
97
97
|
*
|
|
98
98
|
*/
|
|
99
|
-
static
|
|
100
|
-
return OINOBenchmark._instance?.
|
|
99
|
+
static getMetrics():Record<string, number> {
|
|
100
|
+
return OINOBenchmark._instance?._getMetrics()
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
protected abstract _trackMetric(module:string, method:string, category:string, value:number):void
|
|
104
|
+
/**
|
|
105
|
+
* Track a metric value
|
|
106
|
+
*
|
|
107
|
+
* @param value of the metric
|
|
108
|
+
* @param module of the metric
|
|
109
|
+
* @param method of the metric
|
|
110
|
+
* @param category optional subcategory of the metric
|
|
111
|
+
*
|
|
112
|
+
*/
|
|
113
|
+
static trackMetric(module:string, method:string, category:string, value:number):void {
|
|
114
|
+
if (OINOBenchmark._enabled[module]) {
|
|
115
|
+
OINOBenchmark._instance?._trackMetric(module, method, category, value)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
protected abstract _trackException(module:string, method:string, category:string, name:string, message:string, stack: string):void
|
|
120
|
+
/**
|
|
121
|
+
* Track an exception
|
|
122
|
+
*
|
|
123
|
+
* @param module of the benchmark
|
|
124
|
+
* @param method of the benchmark
|
|
125
|
+
* @param category optional subcategory of the benchmark
|
|
126
|
+
* @param name of the exception
|
|
127
|
+
* @param message of the exception
|
|
128
|
+
* @param stack trace of the exception
|
|
129
|
+
*/
|
|
130
|
+
static trackException(module:string, method:string, category:string, name:string, message:string, stack:string):void {
|
|
131
|
+
if (OINOBenchmark._enabled[module]) {
|
|
132
|
+
OINOBenchmark._instance?._trackException(module, method, category, name, message, stack)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
protected abstract _getExceptions():any[]
|
|
137
|
+
/**
|
|
138
|
+
* Get all tracked exceptions.
|
|
139
|
+
*
|
|
140
|
+
*/
|
|
141
|
+
static getExceptions():any[] {
|
|
142
|
+
return OINOBenchmark._instance?._getExceptions()
|
|
101
143
|
}
|
|
102
144
|
}
|
|
103
145
|
|
|
@@ -112,6 +154,8 @@ export class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
112
154
|
protected _benchmarkData:Record<string, number> = {}
|
|
113
155
|
protected _benchmarkStart:Record<string, number> = {}
|
|
114
156
|
|
|
157
|
+
protected _exceptions:any[] = []
|
|
158
|
+
|
|
115
159
|
/**
|
|
116
160
|
* Reset benchmark data (but not what is enabled).
|
|
117
161
|
*
|
|
@@ -127,13 +171,9 @@ export class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
127
171
|
* @param module of the benchmark
|
|
128
172
|
* @param method of the benchmark
|
|
129
173
|
*/
|
|
130
|
-
protected
|
|
174
|
+
protected _startMetric(module:string, method:string):void {
|
|
131
175
|
const name:string = module + "." + method
|
|
132
176
|
if (OINOBenchmark._enabled[module] && ((this._benchmarkStart[name] === undefined) || (this._benchmarkStart[name] === 0))) { // if benchmark is already started (e.g. loop/recursion), do not start it again
|
|
133
|
-
if (this._benchmarkCount[name] == undefined) {
|
|
134
|
-
this._benchmarkCount[name] = 0
|
|
135
|
-
this._benchmarkData[name] = 0
|
|
136
|
-
}
|
|
137
177
|
this._benchmarkStart[name] = performance.now()
|
|
138
178
|
}
|
|
139
179
|
}
|
|
@@ -145,26 +185,14 @@ export class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
145
185
|
* @param method of the benchmark
|
|
146
186
|
* @param category optional subcategory of the benchmark
|
|
147
187
|
*/
|
|
148
|
-
protected
|
|
188
|
+
protected _endMetric(module:string, method:string, category:string):void {
|
|
149
189
|
const name:string = module + "." + method
|
|
150
190
|
let result:number = 0
|
|
151
|
-
if (OINOBenchmark._enabled[module]) {
|
|
191
|
+
if (OINOBenchmark._enabled[module] && (this._benchmarkStart[name] > 0)) { // if benchmark is started, end it
|
|
152
192
|
const duration = performance.now() - this._benchmarkStart[name]
|
|
153
|
-
this.
|
|
154
|
-
this._benchmarkData[name] += duration
|
|
155
|
-
if (category) {
|
|
156
|
-
const category_name = name + "." + category
|
|
157
|
-
if (this._benchmarkCount[category_name] == undefined) {
|
|
158
|
-
this._benchmarkCount[category_name] = 0
|
|
159
|
-
this._benchmarkData[category_name] = 0
|
|
160
|
-
}
|
|
161
|
-
this._benchmarkCount[category_name] += 1
|
|
162
|
-
this._benchmarkData[category_name] += duration
|
|
163
|
-
}
|
|
164
|
-
result = this._benchmarkData[name] / this._benchmarkCount[name]
|
|
165
|
-
this._benchmarkStart[name] = 0
|
|
193
|
+
this._trackMetric(module, method, category, duration)
|
|
166
194
|
}
|
|
167
|
-
return
|
|
195
|
+
return
|
|
168
196
|
}
|
|
169
197
|
|
|
170
198
|
/**
|
|
@@ -174,7 +202,7 @@ export class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
174
202
|
* @param method of the benchmark
|
|
175
203
|
*
|
|
176
204
|
*/
|
|
177
|
-
protected
|
|
205
|
+
protected _getMetric(module:string, method:string):number {
|
|
178
206
|
const name:string = module + "." + method
|
|
179
207
|
if (OINOBenchmark._enabled[module] && (this._benchmarkCount[name] > 0)) {
|
|
180
208
|
return this._benchmarkData[module] / this._benchmarkCount[module]
|
|
@@ -186,7 +214,7 @@ export class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
186
214
|
* Get all benchmark data.
|
|
187
215
|
*
|
|
188
216
|
*/
|
|
189
|
-
protected
|
|
217
|
+
protected _getMetrics():Record<string, number> {
|
|
190
218
|
let result:Record<string, number> = {}
|
|
191
219
|
for (const name in this._benchmarkData) {
|
|
192
220
|
if (this._benchmarkCount[name] > 0) {
|
|
@@ -195,4 +223,35 @@ export class OINOMemoryBenchmark extends OINOBenchmark {
|
|
|
195
223
|
}
|
|
196
224
|
return result
|
|
197
225
|
}
|
|
226
|
+
|
|
227
|
+
protected _trackMetric(module:string, method:string, category:string, value:number):void {
|
|
228
|
+
const name:string = module + "." + method
|
|
229
|
+
if (this._benchmarkCount[name] == undefined) {
|
|
230
|
+
this._benchmarkCount[name] = 1
|
|
231
|
+
this._benchmarkData[name] = value
|
|
232
|
+
} else {
|
|
233
|
+
this._benchmarkCount[name] += 1
|
|
234
|
+
this._benchmarkData[name] += value
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const category_name = name + "." + category
|
|
238
|
+
if (this._benchmarkCount[category_name] == undefined) {
|
|
239
|
+
this._benchmarkCount[category_name] = 1
|
|
240
|
+
this._benchmarkData[category_name] = value
|
|
241
|
+
} else {
|
|
242
|
+
this._benchmarkCount[category_name] += 1
|
|
243
|
+
this._benchmarkData[category_name] += value
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
this._benchmarkStart[name] = 0
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
protected _trackException(module:string, method:string, category:string, name:string, message:string, stack:string):void {
|
|
250
|
+
const exception = { module, method, category, name, message, stack }
|
|
251
|
+
this._exceptions.push(exception)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
protected _getExceptions():any[] {
|
|
255
|
+
return this._exceptions
|
|
256
|
+
}
|
|
198
257
|
}
|
package/src/OINOHtmlTemplate.ts
CHANGED
|
@@ -124,10 +124,10 @@ export class OINOHtmlTemplate {
|
|
|
124
124
|
*
|
|
125
125
|
*/
|
|
126
126
|
renderFromKeyValue(key:string, value:string, removeUnusedTags:boolean = true):OINOHttpResult {
|
|
127
|
-
OINOBenchmark.
|
|
127
|
+
OINOBenchmark.startMetric("OINOHtmlTemplate", "renderFromKeyValue")
|
|
128
128
|
this.setVariableFromValue(key, value)
|
|
129
129
|
const result:OINOHttpResult = this.render(removeUnusedTags)
|
|
130
|
-
OINOBenchmark.
|
|
130
|
+
OINOBenchmark.endMetric("OINOHtmlTemplate", "renderFromKeyValue")
|
|
131
131
|
return result
|
|
132
132
|
}
|
|
133
133
|
|
|
@@ -139,10 +139,10 @@ export class OINOHtmlTemplate {
|
|
|
139
139
|
*
|
|
140
140
|
*/
|
|
141
141
|
renderFromObject(object:any, removeUnusedTags:boolean = true):OINOHttpResult {
|
|
142
|
-
OINOBenchmark.
|
|
142
|
+
OINOBenchmark.startMetric("OINOHtmlTemplate", "renderFromObject")
|
|
143
143
|
this.setVariableFromProperties(object)
|
|
144
144
|
const result:OINOHttpResult = this.render(removeUnusedTags)
|
|
145
|
-
OINOBenchmark.
|
|
145
|
+
OINOBenchmark.endMetric("OINOHtmlTemplate", "renderFromObject")
|
|
146
146
|
return result
|
|
147
147
|
}
|
|
148
148
|
|
|
@@ -159,7 +159,7 @@ export class OINOHtmlTemplate {
|
|
|
159
159
|
*
|
|
160
160
|
*/
|
|
161
161
|
renderFromResult(result:OINOResult, removeUnusedTags:boolean=true, messageSeparator:string = "", includeErrorMessages:boolean=false, includeWarningMessages:boolean=false, includeInfoMessages:boolean=false, includeDebugMessages:boolean=false):OINOHttpResult {
|
|
162
|
-
OINOBenchmark.
|
|
162
|
+
OINOBenchmark.startMetric("OINOHtmlTemplate", "renderFromResult")
|
|
163
163
|
this.setVariableFromValue("statusCode", result.statusCode.toString())
|
|
164
164
|
this.setVariableFromValue("statusMessage", result.statusMessage.toString())
|
|
165
165
|
let messages:string[] = []
|
|
@@ -182,7 +182,7 @@ export class OINOHtmlTemplate {
|
|
|
182
182
|
this.setVariableFromValue("messages", messages.join(messageSeparator), false) // messages have been escaped already
|
|
183
183
|
}
|
|
184
184
|
const http_result:OINOHttpResult = this.render(removeUnusedTags)
|
|
185
|
-
OINOBenchmark.
|
|
185
|
+
OINOBenchmark.endMetric("OINOHtmlTemplate", "renderFromResult")
|
|
186
186
|
return http_result
|
|
187
187
|
}
|
|
188
188
|
};
|