forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperf-counters.cpp
More file actions
55 lines (44 loc) · 1.6 KB
/
perf-counters.cpp
File metadata and controls
55 lines (44 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include <node.h>
#include "hardware-counter.h"
namespace PerfCounters {
using HPHP::HardwareCounter;
void Init(const v8::FunctionCallbackInfo<v8::Value>& args) {
// TODO: Allow customizing recorded events
bool enable = true;
std::string events = "";
bool recordSubprocesses = false;
HardwareCounter::Init(enable, events, recordSubprocesses);
HardwareCounter::s_counter.getCheck();
}
void GetCounters(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
v8::Local<v8::Object> obj = v8::Object::New(isolate);
std::pair<v8::Isolate*, v8::Local<v8::Object>> pair(isolate, obj);
HardwareCounter::GetPerfEvents(
[](const std::string& key, int64_t value, void* data) {
std::pair<v8::Isolate*, v8::Local<v8::Object>>& pair =
*reinterpret_cast<std::pair<v8::Isolate*, v8::Local<v8::Object>>*>(data);
v8::Isolate* isolate = pair.first;
v8::Local<v8::Object> obj = pair.second;
obj->Set(
v8::String::NewFromUtf8(isolate, key.c_str()),
v8::Number::New(isolate, value)
);
},
&pair);
args.GetReturnValue().Set(obj);
}
void InitModule(v8::Local<v8::Object> exports) {
NODE_SET_METHOD(exports, "init", Init);
NODE_SET_METHOD(exports, "getCounters", GetCounters);
}
NODE_MODULE(perfcounters, InitModule)
}