mirror of
https://github.com/hanzomsg/nats.js.git
synced 2026-10-30 20:31:36 +00:00
Reworked errors - removed NatsError --------- Signed-off-by: Alberto Ricart <[email protected]>
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
/*
|
|
* Copyright 2024 Synadia Communications, Inc
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
exports.Performance = class Performance {
|
|
timers;
|
|
measures;
|
|
|
|
constructor() {
|
|
this.timers = new Map();
|
|
this.measures = new Map();
|
|
}
|
|
|
|
mark(key) {
|
|
this.timers.set(key, Date.now());
|
|
}
|
|
|
|
measure(key, startKey, endKey) {
|
|
const s = this.timers.get(startKey);
|
|
if (s === undefined) {
|
|
throw new Error(`${startKey} is not defined`);
|
|
}
|
|
const e = this.timers.get(endKey);
|
|
if (e === undefined) {
|
|
throw new Error(`${endKey} is not defined`);
|
|
}
|
|
this.measures.set(key, e - s);
|
|
}
|
|
|
|
getEntries() {
|
|
const values = [];
|
|
this.measures.forEach((v, k) => {
|
|
values.push({ name: k, duration: v });
|
|
});
|
|
return values;
|
|
}
|
|
};
|