Commit efdc571 1 parent ee7b7f6 commit efdc571 Copy full SHA for efdc571
File tree 3 files changed +31
-8
lines changed
3 files changed +31
-8
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const common = require ( '../common.js' ) ;
4
+ const loadavg = require ( 'os' ) . loadavg ;
5
+
6
+ const bench = common . createBenchmark ( main , {
7
+ n : [ 5e6 ]
8
+ } ) ;
9
+
10
+ function main ( conf ) {
11
+ const n = + conf . n ;
12
+
13
+ bench . start ( ) ;
14
+ for ( var i = 0 ; i < n ; ++ i )
15
+ loadavg ( ) ;
16
+ bench . end ( n ) ;
17
+ }
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
const binding = process . binding ( 'os' ) ;
4
+ const getLoadAvg = binding . getLoadAvg ;
4
5
const constants = process . binding ( 'constants' ) . os ;
5
6
const internalUtil = require ( 'internal/util' ) ;
6
7
const isWindows = process . platform === 'win32' ;
7
8
8
9
exports . hostname = binding . getHostname ;
9
- exports . loadavg = binding . getLoadAvg ;
10
10
exports . uptime = binding . getUptime ;
11
11
exports . freemem = binding . getFreeMem ;
12
12
exports . totalmem = binding . getTotalMem ;
@@ -17,6 +17,12 @@ exports.networkInterfaces = binding.getInterfaceAddresses;
17
17
exports . homedir = binding . getHomeDirectory ;
18
18
exports . userInfo = binding . getUserInfo ;
19
19
20
+ const avgValues = new Float64Array ( 3 ) ;
21
+ exports . loadavg = function loadavg ( ) {
22
+ getLoadAvg ( avgValues ) ;
23
+ return [ avgValues [ 0 ] , avgValues [ 1 ] , avgValues [ 2 ] ] ;
24
+ } ;
25
+
20
26
Object . defineProperty ( exports , 'constants' , {
21
27
configurable : false ,
22
28
enumerable : true ,
Original file line number Diff line number Diff line change @@ -28,8 +28,10 @@ namespace node {
28
28
namespace os {
29
29
30
30
using v8::Array;
31
+ using v8::ArrayBuffer;
31
32
using v8::Boolean ;
32
33
using v8::Context;
34
+ using v8::Float64Array;
33
35
using v8::FunctionCallbackInfo;
34
36
using v8::Integer;
35
37
using v8::Local;
@@ -182,14 +184,12 @@ static void GetUptime(const FunctionCallbackInfo<Value>& args) {
182
184
183
185
184
186
static void GetLoadAvg (const FunctionCallbackInfo<Value>& args) {
185
- Environment* env = Environment::GetCurrent (args);
186
- double loadavg[3 ];
187
+ CHECK (args[0 ]->IsFloat64Array ());
188
+ Local<Float64Array> array = args[0 ].As <Float64Array>();
189
+ CHECK_EQ (array->Length (), 3 );
190
+ Local<ArrayBuffer> ab = array->Buffer ();
191
+ double * loadavg = static_cast <double *>(ab->GetContents ().Data ());
187
192
uv_loadavg (loadavg);
188
- Local<Array> loads = Array::New (env->isolate (), 3 );
189
- loads->Set (0 , Number::New (env->isolate (), loadavg[0 ]));
190
- loads->Set (1 , Number::New (env->isolate (), loadavg[1 ]));
191
- loads->Set (2 , Number::New (env->isolate (), loadavg[2 ]));
192
- args.GetReturnValue ().Set (loads);
193
193
}
194
194
195
195
You can’t perform that action at this time.
0 commit comments