summaryrefslogtreecommitdiff
path: root/src/node_perf.h
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2017-12-21 14:29:05 -0800
committerAnna Henningsen <anna@addaleax.net>2017-12-27 19:44:40 +0100
commit9e5ccf0313b7167d710e50c511db17ecfcdf416f (patch)
tree503308ce701ff3e18b2f9c2744c068f028904572 /src/node_perf.h
parent6c0da349056578d36254d1aed973ddbaa252ce89 (diff)
downloadandroid-node-v8-9e5ccf0313b7167d710e50c511db17ecfcdf416f.tar.gz
android-node-v8-9e5ccf0313b7167d710e50c511db17ecfcdf416f.tar.bz2
android-node-v8-9e5ccf0313b7167d710e50c511db17ecfcdf416f.zip
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 <anna@addaleax.net>
Diffstat (limited to 'src/node_perf.h')
-rw-r--r--src/node_perf.h134
1 files changed, 40 insertions, 94 deletions
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<Value> object);
static void New(const FunctionCallbackInfo<Value>& args);
PerformanceEntry(Environment* env,
- Local<Object> 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<PerformanceEntry>(this);
- NotifyObservers(env, this);
- }
+ uint64_t endTime) : env_(env),
+ name_(name),
+ type_(type),
+ startTime_(startTime),
+ endTime_(endTime) { }
- PerformanceEntry(Environment* env,
- Local<Object> wrap,
- Data* data) :
- BaseObject(env, wrap),
- name_(data->name()),
- type_(data->type()),
- startTime_(data->startTime()),
- endTime_(data->endTime()) {
- MakeWeak<PerformanceEntry>(this);
- NotifyObservers(env, this);
- }
+ virtual ~PerformanceEntry() { }
- ~PerformanceEntry() {}
+ virtual const Local<Object> 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