This repository was archived by the owner on Aug 11, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 51
Closed
C++-side refactor #126
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
75ea63b
quic: remove user_data from quic buffer callback
addaleax 762d03f
quic: remove `typedef enum`
addaleax 4a11d59
quic: cleanup node_quic_buffer.h
addaleax 1ccfbd2
src: cleanup histogram code
addaleax 650ea1f
quic: remove opaque pointer from Timer callback
addaleax bdd45bd
quic: cleanup QuicSession code
addaleax e334d94
src: refactor memory tracker implementation
addaleax 34f46df
http2: use shared memory tracking implementation
addaleax 5f0ea8e
quic: remove QuicStreamListener
addaleax 96b22fd
quic: more general C++ cleanup
addaleax c7015ef
fixup! quic: remove opaque pointer from Timer callback
addaleax 3f1b93f
fixup! src: cleanup histogram code
addaleax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#include "histogram.h" // NOLINT(build/include_inline) | ||
#include "histogram-inl.h" | ||
#include "memory_tracker-inl.h" | ||
|
||
namespace node { | ||
|
||
using v8::FunctionCallbackInfo; | ||
using v8::FunctionTemplate; | ||
using v8::Local; | ||
using v8::Map; | ||
using v8::Number; | ||
using v8::ObjectTemplate; | ||
using v8::String; | ||
using v8::Value; | ||
|
||
void HistogramBase::MemoryInfo(MemoryTracker* tracker) const { | ||
tracker->TrackFieldWithSize("histogram", GetMemorySize()); | ||
} | ||
|
||
void HistogramBase::HistogramMin(const FunctionCallbackInfo<Value>& args) { | ||
HistogramBase* histogram; | ||
ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); | ||
double value = static_cast<double>(histogram->Min()); | ||
args.GetReturnValue().Set(value); | ||
} | ||
|
||
void HistogramBase::HistogramMax(const FunctionCallbackInfo<Value>& args) { | ||
HistogramBase* histogram; | ||
ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); | ||
double value = static_cast<double>(histogram->Max()); | ||
args.GetReturnValue().Set(value); | ||
} | ||
|
||
void HistogramBase::HistogramMean(const FunctionCallbackInfo<Value>& args) { | ||
HistogramBase* histogram; | ||
ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); | ||
args.GetReturnValue().Set(histogram->Mean()); | ||
} | ||
|
||
void HistogramBase::HistogramExceeds(const FunctionCallbackInfo<Value>& args) { | ||
HistogramBase* histogram; | ||
ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); | ||
double value = static_cast<double>(histogram->Exceeds()); | ||
args.GetReturnValue().Set(value); | ||
} | ||
|
||
void HistogramBase::HistogramStddev(const FunctionCallbackInfo<Value>& args) { | ||
HistogramBase* histogram; | ||
ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); | ||
args.GetReturnValue().Set(histogram->Stddev()); | ||
} | ||
|
||
void HistogramBase::HistogramPercentile( | ||
const FunctionCallbackInfo<Value>& args) { | ||
HistogramBase* histogram; | ||
ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); | ||
CHECK(args[0]->IsNumber()); | ||
double percentile = args[0].As<Number>()->Value(); | ||
args.GetReturnValue().Set(histogram->Percentile(percentile)); | ||
} | ||
|
||
void HistogramBase::HistogramPercentiles( | ||
const FunctionCallbackInfo<Value>& args) { | ||
Environment* env = Environment::GetCurrent(args); | ||
HistogramBase* histogram; | ||
ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); | ||
CHECK(args[0]->IsMap()); | ||
Local<Map> map = args[0].As<Map>(); | ||
histogram->Percentiles([&](double key, double value) { | ||
map->Set( | ||
env->context(), | ||
Number::New(env->isolate(), key), | ||
Number::New(env->isolate(), value)).IsEmpty(); | ||
}); | ||
} | ||
|
||
void HistogramBase::HistogramReset(const FunctionCallbackInfo<Value>& args) { | ||
HistogramBase* histogram; | ||
ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder()); | ||
histogram->ResetState(); | ||
} | ||
|
||
void HistogramBase::Initialize(Environment* env) { | ||
// Guard against multiple initializations | ||
if (!env->histogram_ctor_template().IsEmpty()) | ||
return; | ||
|
||
Local<String> classname = | ||
FIXED_ONE_BYTE_STRING(env->isolate(), "Histogram"); | ||
|
||
Local<FunctionTemplate> histogram = | ||
FunctionTemplate::New(env->isolate()); | ||
histogram->SetClassName(classname); | ||
|
||
Local<ObjectTemplate> histogramt = | ||
histogram->InstanceTemplate(); | ||
|
||
histogramt->SetInternalFieldCount(1); | ||
env->SetProtoMethod(histogram, "exceeds", HistogramExceeds); | ||
env->SetProtoMethod(histogram, "min", HistogramMin); | ||
env->SetProtoMethod(histogram, "max", HistogramMax); | ||
env->SetProtoMethod(histogram, "mean", HistogramMean); | ||
env->SetProtoMethod(histogram, "stddev", HistogramStddev); | ||
env->SetProtoMethod(histogram, "percentile", HistogramPercentile); | ||
env->SetProtoMethod(histogram, "percentiles", HistogramPercentiles); | ||
env->SetProtoMethod(histogram, "reset", HistogramReset); | ||
|
||
env->set_histogram_ctor_template(histogramt); | ||
} | ||
|
||
} // namespace node |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.