From 9e5ccf0313b7167d710e50c511db17ecfcdf416f Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 21 Dec 2017 14:29:05 -0800 Subject: perf_hooks: refactor internals Refactor and simplify the perf_hooks native internals. PR-URL: https://github.com/nodejs/node/pull/17822 Reviewed-By: Anna Henningsen --- src/node_perf.h | 134 +++++++++++++++++--------------------------------------- 1 file changed, 40 insertions(+), 94 deletions(-) (limited to 'src/node_perf.h') diff --git a/src/node_perf.h b/src/node_perf.h index 690f708309..e5655f54fe 100644 --- a/src/node_perf.h +++ b/src/node_perf.h @@ -42,120 +42,51 @@ static inline PerformanceEntryType ToPerformanceEntryTypeEnum( NODE_EXTERN inline void MarkPerformanceMilestone( Environment* env, PerformanceMilestone milestone) { - env->performance_state()->milestones[milestone] = PERFORMANCE_NOW(); - } + env->performance_state()->milestones[milestone] = PERFORMANCE_NOW(); +} -class PerformanceEntry : public BaseObject { +class PerformanceEntry { public: - // Used for temporary storage of performance entry details when the - // object cannot be created immediately. - class Data { - public: - Data( - Environment* env, - const char* name, - const char* type, - uint64_t startTime, - uint64_t endTime, - int data = 0) : - env_(env), - name_(name), - type_(type), - startTime_(startTime), - endTime_(endTime), - data_(data) {} - - Environment* env() const { - return env_; - } - - const std::string& name() const { - return name_; - } - - const std::string& type() const { - return type_; - } - - uint64_t startTime() const { - return startTime_; - } - - uint64_t endTime() const { - return endTime_; - } - - int data() const { - return data_; - } - - private: - Environment* const env_; - const std::string name_; - const std::string type_; - const uint64_t startTime_; - const uint64_t endTime_; - const int data_; - }; - - static void NotifyObservers(Environment* env, PerformanceEntry* entry); + static inline void Notify(Environment* env, + PerformanceEntryType type, + Local object); static void New(const FunctionCallbackInfo& args); PerformanceEntry(Environment* env, - Local wrap, const char* name, const char* type, uint64_t startTime, - uint64_t endTime) : - BaseObject(env, wrap), - name_(name), - type_(type), - startTime_(startTime), - endTime_(endTime) { - MakeWeak(this); - NotifyObservers(env, this); - } + uint64_t endTime) : env_(env), + name_(name), + type_(type), + startTime_(startTime), + endTime_(endTime) { } - PerformanceEntry(Environment* env, - Local wrap, - Data* data) : - BaseObject(env, wrap), - name_(data->name()), - type_(data->type()), - startTime_(data->startTime()), - endTime_(data->endTime()) { - MakeWeak(this); - NotifyObservers(env, this); - } + virtual ~PerformanceEntry() { } - ~PerformanceEntry() {} + virtual const Local ToObject() const; - const std::string& name() const { - return name_; - } + Environment* env() const { return env_; } - const std::string& type() const { - return type_; - } + const std::string& name() const { return name_; } - double startTime() const { - return startTime_ / 1e6; - } + const std::string& type() const { return type_; } - double duration() const { - return durationNano() / 1e6; + PerformanceEntryType kind() { + return ToPerformanceEntryTypeEnum(type().c_str()); } - uint64_t startTimeNano() const { - return startTime_; - } + double startTime() const { return startTime_ / 1e6; } - uint64_t durationNano() const { - return endTime_ - startTime_; - } + double duration() const { return durationNano() / 1e6; } + + uint64_t startTimeNano() const { return startTime_; } + + uint64_t durationNano() const { return endTime_ - startTime_; } private: + Environment* env_; const std::string name_; const std::string type_; const uint64_t startTime_; @@ -169,6 +100,21 @@ enum PerformanceGCKind { NODE_PERFORMANCE_GC_WEAKCB = GCType::kGCTypeProcessWeakCallbacks }; +class GCPerformanceEntry : public PerformanceEntry { + public: + GCPerformanceEntry(Environment* env, + PerformanceGCKind gckind, + uint64_t startTime, + uint64_t endTime) : + PerformanceEntry(env, "gc", "gc", startTime, endTime), + gckind_(gckind) { } + + PerformanceGCKind gckind() const { return gckind_; } + + private: + PerformanceGCKind gckind_; +}; + } // namespace performance } // namespace node -- cgit v1.2.3