Skip to content

Commit 5003bd4

Browse files
committed
Code tweaks and an additional unit test
- The Histogram `record` method now has an optional `count` parameter. - A new unit test for the above change. - The HdrHistogram `record` method is now `recordValue`. - The HdrHistogram `sizeOfEquivalentValueRange` and `resetInternalCounters` methods are removed.
1 parent 8e2451e commit 5003bd4

File tree

8 files changed

+42
-32
lines changed

8 files changed

+42
-32
lines changed

Histogram.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ class Histogram extends HdrHistogram {
66
super(min, max, sigDigits);
77
}
88

9-
record (value) {
9+
record (value, count) {
1010
if (isNumber(value)) {
11-
return super.record(value);
11+
if (typeof count === 'undefined') {
12+
return super.recordValue(value);
13+
} else {
14+
return super.recordValues(value, count);
15+
}
1216
} else {
1317
return false;
1418
}
@@ -19,7 +23,7 @@ class Histogram extends HdrHistogram {
1923
}
2024

2125
static decode (encoded) {
22-
let histogram = new Histogram (1, 10); // values here are immaterial
26+
let histogram = new Histogram (1, 10); // the values here are immaterial
2327
histogram.setEncoded(encoded);
2428
return histogram;
2529
}

binding-src/binding-util/napi-ingress.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// © Copyright 2020 Simply Inspired Software, Inc., dba inspiredware
2+
// Released under The MIT License — https://en.wikipedia.org/wiki/MIT_License
23

34
#include "napi-ingress.h"
45
#include <napi.h>

binding-src/binding-util/napi-ingress.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// © Copyright 2020 Simply Inspired Software, Inc., dba inspiredware
2+
// Released under The MIT License — https://en.wikipedia.org/wiki/MIT_License
23

34
#include <napi.h>
45
using namespace Napi;

binding-src/binding.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// 2020-06-16T17:09:23.639-07:00 binding (GenerateInitFiles)
1+
// 2020-06-26T15:58:56.777-07:00 binding (GenerateInitFiles)
22
// © Copyright 2020 Simply Inspired Software, Inc., dba inspiredware
3-
// Created by the inspiredware automated binding generator — www.inspiredware.com
3+
// Released under the MIT License — https://en.wikipedia.org/wiki/MIT_License
4+
// Created by the inspiredware automated binding generator — https://inspiredware.com
45

56
#include <napi.h>
67
#include "binding/hdr_histogram.h"

binding-src/binding/hdr_histogram.cc

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// 2020-06-16T17:09:23.251-07:00 binding hdr_histogram.c (GenerateDefinitions)
1+
// 2020-06-26T15:58:56.322-07:00 binding hdr_histogram.c (GenerateDefinitions)
22
// © Copyright 2020 Simply Inspired Software, Inc., dba inspiredware
3-
// Created by the inspiredware automated binding generator — www.inspiredware.com
3+
// Released under the MIT License — https://en.wikipedia.org/wiki/MIT_License
4+
// Created by the inspiredware automated binding generator — https://inspiredware.com
45

56
#include "hdr_histogram.h"
67
#include "napi-ingress.h"
@@ -66,7 +67,7 @@ Napi::Value HdrHistogram::recordCorrectedValuesAtomic (const Napi::CallbackInfo&
6667
return jsRetVal;
6768
}
6869

69-
Napi::Value HdrHistogram::record (const Napi::CallbackInfo& info) {
70+
Napi::Value HdrHistogram::recordValue (const Napi::CallbackInfo& info) {
7071
Napi::Env env = info.Env();
7172
long long value = getInt64<long long> (info[0]);
7273
_Bool retVal = hdr_record_value (histogram, value);
@@ -186,14 +187,6 @@ Napi::Value HdrHistogram::nextNonEquivalentValue (const Napi::CallbackInfo& info
186187
return jsRetVal;
187188
}
188189

189-
Napi::Value HdrHistogram::sizeOfEquivalentValueRange (const Napi::CallbackInfo& info) {
190-
Napi::Env env = info.Env();
191-
long long value = getInt64<long long> (info[0]);
192-
long long retVal = hdr_size_of_equivalent_value_range (histogram, value);
193-
Napi::Value jsRetVal = Number::New (env, retVal);
194-
return jsRetVal;
195-
}
196-
197190
Napi::Value HdrHistogram::percentile (const Napi::CallbackInfo& info) {
198191
Napi::Env env = info.Env();
199192
double percentile = getDouble<double> (info[0]);
@@ -216,13 +209,6 @@ Napi::Value HdrHistogram::reset (const Napi::CallbackInfo& info) {
216209
return jsRetVal;
217210
}
218211

219-
Napi::Value HdrHistogram::resetInternalCounters (const Napi::CallbackInfo& info) {
220-
Napi::Env env = info.Env();
221-
hdr_reset_internal_counters (histogram);
222-
Napi::Value jsRetVal = env.Undefined();
223-
return jsRetVal;
224-
}
225-
226212
Napi::Value HdrHistogram::getEncoded (const Napi::CallbackInfo& info) {
227213
Napi::Env env = info.Env();
228214
char * encoded = NULL;
@@ -288,18 +274,16 @@ Napi::Function HdrHistogram::GetClassDef (Napi::Env env) { // static
288274
InstanceMethod ("recordCorrectedValueAtomic", &HdrHistogram::recordCorrectedValueAtomic),
289275
InstanceMethod ("recordCorrectedValues", &HdrHistogram::recordCorrectedValues),
290276
InstanceMethod ("recordCorrectedValuesAtomic", &HdrHistogram::recordCorrectedValuesAtomic),
291-
InstanceMethod ("record", &HdrHistogram::record),
277+
InstanceMethod ("recordValue", &HdrHistogram::recordValue),
292278
InstanceMethod ("recordAtomic", &HdrHistogram::recordAtomic),
293279
InstanceMethod ("recordValues", &HdrHistogram::recordValues),
294280
InstanceMethod ("recordValuesAtomic", &HdrHistogram::recordValuesAtomic),
295281
InstanceMethod ("reset", &HdrHistogram::reset),
296-
InstanceMethod ("resetInternalCounters", &HdrHistogram::resetInternalCounters),
297282
InstanceMethod ("stddev", &HdrHistogram::stddev),
298283
InstanceMethod ("percentile", &HdrHistogram::percentile),
299284
InstanceMethod ("valuesAreEquivalent", &HdrHistogram::valuesAreEquivalent),
300285
InstanceMethod ("nextNonEquivalentValue", &HdrHistogram::nextNonEquivalentValue),
301286
InstanceMethod ("medianEquivalentValue", &HdrHistogram::medianEquivalentValue),
302-
InstanceMethod ("sizeOfEquivalentValueRange", &HdrHistogram::sizeOfEquivalentValueRange),
303287
InstanceMethod ("getEncoded", &HdrHistogram::getEncoded),
304288
InstanceMethod ("setEncoded", &HdrHistogram::setEncoded),
305289
InstanceAccessor ("highestTrackableValue", &HdrHistogram::getHighestTrackableValue, nullptr, napi_default),

binding-src/binding/hdr_histogram.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// 2020-06-16T17:09:22.946-07:00 binding hdr_histogram.c (GenerateDeclarations)
1+
// 2020-06-26T15:58:55.941-07:00 binding hdr_histogram.c (GenerateDeclarations)
22
// © Copyright 2020 Simply Inspired Software, Inc., dba inspiredware
3-
// Created by the inspiredware automated binding generator — www.inspiredware.com
3+
// Released under the MIT License — https://en.wikipedia.org/wiki/MIT_License
4+
// Created by the inspiredware automated binding generator — https://inspiredware.com
45

56
#include <napi.h>
67
#include <hdr_histogram.h> // from the origin library
@@ -18,7 +19,7 @@ class HdrHistogram : public Napi::ObjectWrap<HdrHistogram> {
1819
Napi::Value recordCorrectedValueAtomic (const Napi::CallbackInfo& info);
1920
Napi::Value recordCorrectedValues (const Napi::CallbackInfo& info);
2021
Napi::Value recordCorrectedValuesAtomic (const Napi::CallbackInfo& info);
21-
Napi::Value record (const Napi::CallbackInfo& info);
22+
Napi::Value recordValue (const Napi::CallbackInfo& info);
2223
Napi::Value recordAtomic (const Napi::CallbackInfo& info);
2324
Napi::Value recordValues (const Napi::CallbackInfo& info);
2425
Napi::Value recordValuesAtomic (const Napi::CallbackInfo& info);
@@ -33,11 +34,9 @@ class HdrHistogram : public Napi::ObjectWrap<HdrHistogram> {
3334
Napi::Value medianEquivalentValue (const Napi::CallbackInfo& info);
3435
Napi::Value min (const Napi::CallbackInfo& info);
3536
Napi::Value nextNonEquivalentValue (const Napi::CallbackInfo& info);
36-
Napi::Value sizeOfEquivalentValueRange (const Napi::CallbackInfo& info);
3737
Napi::Value percentile (const Napi::CallbackInfo& info);
3838
Napi::Value getMemorySize (const Napi::CallbackInfo& info);
3939
Napi::Value reset (const Napi::CallbackInfo& info);
40-
Napi::Value resetInternalCounters (const Napi::CallbackInfo& info);
4140

4241
Napi::Value getEncoded (const Napi::CallbackInfo& info);
4342
Napi::Value getHighestTrackableValue (const Napi::CallbackInfo& info);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-hdr-histogram-napi",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "A lightweight N-API wrapper for the HdrHistogram_c library",
55
"author": "Jim Schlight <[email protected]>",
66
"license": "MIT",

test/test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,26 @@ test('properties', (t) => {
122122
t.end()
123123
})
124124

125+
test('record values', (t) => {
126+
const instance = new Histogram(1, 100)
127+
t.ok(instance.record(10, 3))
128+
t.equal(instance.min(), 10, 'min is correct')
129+
t.equal(instance.max(), 10, 'max is correct')
130+
t.equal(instance.mean(), 10, 'mean is correct')
131+
t.equal(instance.totalCount, 3, 'metotalCountan is correct')
132+
t.ok(instance.record(30, 3))
133+
t.equal(instance.min(), 10, 'min is correct')
134+
t.equal(instance.max(), 30, 'max is correct')
135+
t.equal(instance.mean(), 20, 'mean is correct')
136+
t.equal(instance.totalCount, 6, 'metotalCountan is correct')
137+
t.ok(instance.record(40, 6))
138+
t.equal(instance.min(), 10, 'min is correct')
139+
t.equal(instance.max(), 40, 'max is correct')
140+
t.equal(instance.mean(), 30, 'mean is correct')
141+
t.equal(instance.totalCount, 12, 'metotalCountan is correct')
142+
t.end()
143+
})
144+
125145
test('percentile', (t) => {
126146
const instance = new Histogram(1, 100)
127147
t.ok(instance.record(42))

0 commit comments

Comments
 (0)