console.log('Changed umask from: ' + oldmask.toString(8) +
' to ' + newmask.toString(8));
+
+### process.uptime()
+
+Number of seconds Node has been running.
}
}
+static Handle<Value> Uptime(const Arguments& args) {
+ HandleScope scope;
+ assert(args.Length() == 0);
+
+ double uptime = Platform::GetUptime(true);
+
+ if (uptime < 0) {
+ return Undefined();
+ }
+
+ return scope.Close(Number::New(uptime));
+}
v8::Handle<v8::Value> MemoryUsage(const v8::Arguments& args) {
HandleScope scope;
NODE_SET_METHOD(process, "_kill", Kill);
#endif // __POSIX__
+ NODE_SET_METHOD(process, "uptime", Uptime);
NODE_SET_METHOD(process, "memoryUsage", MemoryUsage);
NODE_SET_METHOD(process, "binding", Binding);
static int GetCPUInfo(v8::Local<v8::Array> *cpus);
static double GetFreeMemory();
static double GetTotalMemory();
- static double GetUptime();
+ static double GetUptime(bool adjusted = false)
+ {
+ return adjusted ? GetUptimeImpl() - prog_start_time : GetUptimeImpl();
+ }
static int GetLoadAvg(v8::Local<v8::Array> *loads);
+ private:
+ static double GetUptimeImpl();
+ static double prog_start_time;
};
static char buf[MAXPATHLEN + 1];
static char *process_title = NULL;
-
+double Platform::prog_start_time = Platform::GetUptime();
// Does the about the same as perror(), but for windows api functions
static void _winapi_perror(const char* prefix = NULL) {
return pages * pagesize;
}
-double Platform::GetUptime() {
+double Platform::GetUptimeImpl() {
double amount;
char line[512];
FILE *fpUptime = fopen("/proc/uptime", "r");
using namespace v8;
static char *process_title;
+double Platform::prog_start_time = Platform::GetUptime();
char** Platform::SetupArgs(int argc, char *argv[]) {
process_title = argc ? strdup(argv[0]) : NULL;
return static_cast<double>(info);
}
-double Platform::GetUptime() {
+double Platform::GetUptimeImpl() {
time_t now;
struct timeval info;
size_t size = sizeof(info);
using namespace v8;
static char *process_title;
+double Platform::prog_start_time = Platform::GetUptime();
char** Platform::SetupArgs(int argc, char *argv[]) {
process_title = argc ? strdup(argv[0]) : NULL;
return static_cast<double>(info);
}
-double Platform::GetUptime() {
+double Platform::GetUptimeImpl() {
time_t now;
struct timeval info;
size_t size = sizeof(info);
static char buf[MAXPATHLEN + 1];
static char *process_title;
+double Platform::prog_start_time = Platform::GetUptime();
char** Platform::SetupArgs(int argc, char *argv[]) {
return pages * pagesize;
}
-double Platform::GetUptime() {
+double Platform::GetUptimeImpl() {
struct sysinfo info;
if (sysinfo(&info) < 0) {
using namespace v8;
static char *process_title;
+double Platform::prog_start_time = Platform::GetUptime();
char** Platform::SetupArgs(int argc, char *argv[]) {
process_title = argc ? strdup(argv[0]) : NULL;
return static_cast<double>(info);
}
-double Platform::GetUptime() {
+double Platform::GetUptimeImpl() {
time_t now;
struct timeval info;
size_t size = sizeof(info);
using namespace v8;
+double Platform::prog_start_time = Platform::GetUptime();
+
char** Platform::SetupArgs(int argc, char *argv[]) {
return argv;
}
}
-double Platform::GetUptime() {
+double Platform::GetUptimeImpl() {
// http://munin-monitoring.org/attachment/ticket/419/uptime
return 0.0;
}
using namespace v8;
static char *process_title = NULL;
+double Platform::prog_start_time = 0.0;
// Does the about the same as strerror(),
}
-double Platform::GetUptime() {
+double Platform::GetUptimeImpl() {
return -1;
}
--- /dev/null
+var assert = require('assert');
+
+assert.equal(process.uptime(), 0);
+
+setTimeout(function() {
+ var uptime = process.uptime();
+ // some wiggle room to account for timer
+ // granularity, processor speed, and scheduling
+ assert.ok(uptime >= 2);
+ assert.ok(uptime <= 3);
+}, 2000);