This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move methods that do not need to be inline into their own file, replace `std::function` with a template variant for performance, remove `inline` for functions with implicit inline linkage. PR-URL: #126 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
4 changed files
with
151 additions
and
150 deletions.
There are no files selected for viewing
This file contains 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 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 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.