Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit e139a1f

Browse files
authored
fix: check inf and remove rounding (#208)
* fix: check inf and remove rounding * fix: check inf and remove rounding
1 parent 12c2eec commit e139a1f

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

bindings/cpu_profiler.cc

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void MeasurementsTicker::cpu_callback() {
167167
double total_avg = total / count;
168168
double rate = 1.0 - idle_avg / total_avg;
169169

170-
if(rate < 0.0 || isnan(rate)) {
170+
if(rate < 0.0 || isinf(rate) || isnan(rate)) {
171171
rate = 0.0;
172172
}
173173

@@ -637,10 +637,6 @@ static void GetSamples(const napi_env& env, const v8::CpuProfile* profile, const
637637
}
638638
}
639639

640-
static double RoundDoubleToPrecision(double value, double precision){
641-
return (floor((value * pow(10, precision) + 0.5)) / pow(10, precision));
642-
}
643-
644640
static napi_value TranslateMeasurementsDouble(const napi_env& env, const char* unit, const uint16_t size, const std::vector<double>& values, const std::vector<uint64_t>& timestamps) {
645641
if (size > values.size() || size > timestamps.size()) {
646642
napi_throw_range_error(env, "NAPI_ERROR", "CPU measurement size is larger than the number of values or timestamps");
@@ -668,17 +664,10 @@ static napi_value TranslateMeasurementsDouble(const napi_env& env, const char* u
668664
napi_value entry;
669665
napi_create_object(env, &entry);
670666

671-
double v = values[i];
672-
if(isnan(v)){
673-
v = 0.0;
674-
}
675-
676667
napi_value value;
677-
if(napi_create_double(env, RoundDoubleToPrecision(v, 4), &value) != napi_ok){
668+
if(napi_create_double(env, values[i], &value) != napi_ok){
678669
if(napi_create_double(env, 0.0, &value) != napi_ok){
679-
// If we failed twice, throw an error
680-
napi_throw_error(env, "NAPI_ERROR", "Failed to create double value.");
681-
break;
670+
continue;
682671
}
683672
}
684673

0 commit comments

Comments
 (0)