| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 230e98b commit 82df851
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -228,9 +228,8 @@ Environment::Environment(IsolateData* isolate_data, | |||
| 228 | 228 | performance_state_.reset(new performance::performance_state(isolate())); | |
| 229 | 229 | performance_state_->Mark( | |
| 230 | 230 | performance::NODE_PERFORMANCE_MILESTONE_ENVIRONMENT); | |
| 231 | - performance_state_->Mark( | ||
| 232 | - performance::NODE_PERFORMANCE_MILESTONE_NODE_START, | ||
| 233 | - performance::performance_node_start); | ||
| 231 | + performance_state_->Mark(performance::NODE_PERFORMANCE_MILESTONE_NODE_START, | ||
| 232 | + per_process::node_start_time); | ||
| 234 | 233 | performance_state_->Mark( | |
| 235 | 234 | performance::NODE_PERFORMANCE_MILESTONE_V8_START, | |
| 236 | 235 | performance::performance_v8_start); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -145,8 +145,8 @@ unsigned int reverted_cve = 0; | |||
| 145 | 145 | bool v8_initialized = false; | |
| 146 | 146 | ||
| 147 | 147 | // node_internals.h | |
| 148 | - // process-relative uptime base, initialized at start-up | ||
| 149 | - double prog_start_time; | ||
| 148 | + // process-relative uptime base in nanoseconds, initialized in node::Start() | ||
| 149 | + uint64_t node_start_time; | ||
| 150 | 150 | // Tells whether --prof is passed. | |
| 151 | 151 | bool v8_is_profiling = false; | |
| 152 | 152 | ||
@@ -611,9 +611,6 @@ int ProcessGlobalArgs(std::vector<std::string>* args, | |||
| 611 | 611 | int Init(std::vector<std::string>* argv, | |
| 612 | 612 | std::vector<std::string>* exec_argv, | |
| 613 | 613 | std::vector<std::string>* errors) { | |
| 614 | - // Initialize prog_start_time to get relative uptime. | ||
| 615 | - per_process::prog_start_time = static_cast<double>(uv_now(uv_default_loop())); | ||
| 616 | - | ||
| 617 | 614 | // Register built-in modules | |
| 618 | 615 | binding::RegisterBuiltinModules(); | |
| 619 | 616 | ||
@@ -891,7 +888,7 @@ inline int Start(uv_loop_t* event_loop, | |||
| 891 | 888 | int Start(int argc, char** argv) { | |
| 892 | 889 | atexit([] () { uv_tty_reset_mode(); }); | |
| 893 | 890 | PlatformInit(); | |
| 894 | - performance::performance_node_start = PERFORMANCE_NOW(); | ||
| 891 | + per_process::node_start_time = uv_hrtime(); | ||
| 895 | 892 | ||
| 896 | 893 | CHECK_GT(argc, 0); | |
| 897 | 894 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,7 +55,7 @@ class NativeModuleLoader; | |||
| 55 | 55 | ||
| 56 | 56 | namespace per_process { | |
| 57 | 57 | extern Mutex env_var_mutex; | |
| 58 | - extern double prog_start_time; | ||
| 58 | + extern uint64_t node_start_time; | ||
| 59 | 59 | extern bool v8_is_profiling; | |
| 60 | 60 | } // namespace per_process | |
| 61 | 61 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,7 +46,6 @@ using v8::Value; | |||
| 46 | 46 | const uint64_t timeOrigin = PERFORMANCE_NOW(); | |
| 47 | 47 | // https://w3c.github.io/hr-time/#dfn-time-origin-timestamp | |
| 48 | 48 | const double timeOriginTimestamp = GetCurrentTimeInMicroseconds(); | |
| 49 | - uint64_t performance_node_start; | ||
| 50 | 49 | uint64_t performance_v8_start; | |
| 51 | 50 | ||
| 52 | 51 | void performance_state::Mark(enum PerformanceMilestone milestone, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,6 @@ namespace performance { | |||
| 18 | 18 | ||
| 19 | 19 | // These occur before the environment is created. Cache them | |
| 20 | 20 | // here and add them to the milestones when the env is init'd. | |
| 21 | - extern uint64_t performance_node_start; | ||
| 22 | 21 | extern uint64_t performance_v8_start; | |
| 23 | 22 | ||
| 24 | 23 | #define NODE_PERFORMANCE_MILESTONES(V) \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,6 +44,7 @@ using v8::Isolate; | |||
| 44 | 44 | using v8::Local; | |
| 45 | 45 | using v8::Name; | |
| 46 | 46 | using v8::NewStringType; | |
| 47 | + using v8::Number; | ||
| 47 | 48 | using v8::Object; | |
| 48 | 49 | using v8::String; | |
| 49 | 50 | using v8::Uint32; | |
@@ -58,6 +59,8 @@ Mutex umask_mutex; | |||
| 58 | 59 | #define MICROS_PER_SEC 1e6 | |
| 59 | 60 | // used in Hrtime() below | |
| 60 | 61 | #define NANOS_PER_SEC 1000000000 | |
| 62 | + // Used in Uptime() | ||
| 63 | + #define NANOS_PER_MICROS 1e3 | ||
| 61 | 64 | ||
| 62 | 65 | #ifdef _WIN32 | |
| 63 | 66 | /* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */ | |
@@ -239,12 +242,12 @@ static void Umask(const FunctionCallbackInfo<Value>& args) { | |||
| 239 | 242 | ||
| 240 | 243 | static void Uptime(const FunctionCallbackInfo<Value>& args) { | |
| 241 | 244 | Environment* env = Environment::GetCurrent(args); | |
| 242 | - double uptime; | ||
| 243 | 245 | ||
| 244 | 246 | uv_update_time(env->event_loop()); | |
| 245 | - uptime = uv_now(env->event_loop()) - per_process::prog_start_time; | ||
| 246 | - | ||
| 247 | - args.GetReturnValue().Set(uptime / 1000); | ||
| 247 | + double uptime = | ||
| 248 | + static_cast<double>(uv_hrtime() - per_process::node_start_time); | ||
| 249 | + Local<Number> result = Number::New(env->isolate(), uptime / NANOS_PER_MICROS); | ||
| 250 | + args.GetReturnValue().Set(result); | ||
| 248 | 251 | } | |
| 249 | 252 | ||
| 250 | 253 | static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,6 +47,9 @@ | |||
| 47 | 47 | extern char** environ; | |
| 48 | 48 | #endif | |
| 49 | 49 | ||
| 50 | + constexpr int NANOS_PER_SEC = 1000 * 1000 * 1000; | ||
| 51 | + constexpr double SEC_PER_MICROS = 1e-6; | ||
| 52 | + | ||
| 50 | 53 | namespace report { | |
| 51 | 54 | using node::arraysize; | |
| 52 | 55 | using node::Environment; | |
@@ -489,20 +492,19 @@ static void PrintGCStatistics(JSONWriter* writer, Isolate* isolate) { | |||
| 489 | 492 | #ifndef _WIN32 | |
| 490 | 493 | // Report resource usage (Linux/OSX only). | |
| 491 | 494 | static void PrintResourceUsage(JSONWriter* writer) { | |
| 492 | - time_t current_time; // current time absolute | ||
| 493 | - time(¤t_time); | ||
| 494 | - size_t boot_time = static_cast<time_t>(node::per_process::prog_start_time / | ||
| 495 | - (1000 * 1000 * 1000)); | ||
| 496 | - auto uptime = difftime(current_time, boot_time); | ||
| 495 | + // Get process uptime in seconds | ||
| 496 | + uint64_t uptime = | ||
| 497 | + (uv_hrtime() - node::per_process::node_start_time) / (NANOS_PER_SEC); | ||
| 497 | 498 | if (uptime == 0) uptime = 1; // avoid division by zero. | |
| 498 | 499 | ||
| 499 | 500 | // Process and current thread usage statistics | |
| 500 | 501 | struct rusage stats; | |
| 501 | 502 | writer->json_objectstart("resourceUsage"); | |
| 502 | 503 | if (getrusage(RUSAGE_SELF, &stats) == 0) { | |
| 503 | - double user_cpu = stats.ru_utime.tv_sec + 0.000001 * stats.ru_utime.tv_usec; | ||
| 504 | + double user_cpu = | ||
| 505 | + stats.ru_utime.tv_sec + SEC_PER_MICROS * stats.ru_utime.tv_usec; | ||
| 504 | 506 | double kernel_cpu = | |
| 505 | - stats.ru_utime.tv_sec + 0.000001 * stats.ru_utime.tv_usec; | ||
| 507 | + stats.ru_utime.tv_sec + SEC_PER_MICROS * stats.ru_utime.tv_usec; | ||
| 506 | 508 | writer->json_keyvalue("userCpuSeconds", user_cpu); | |
| 507 | 509 | writer->json_keyvalue("kernelCpuSeconds", kernel_cpu); | |
| 508 | 510 | double cpu_abs = user_cpu + kernel_cpu; | |
@@ -522,9 +524,10 @@ static void PrintResourceUsage(JSONWriter* writer) { | |||
| 522 | 524 | #ifdef RUSAGE_THREAD | |
| 523 | 525 | if (getrusage(RUSAGE_THREAD, &stats) == 0) { | |
| 524 | 526 | writer->json_objectstart("uvthreadResourceUsage"); | |
| 525 | - double user_cpu = stats.ru_utime.tv_sec + 0.000001 * stats.ru_utime.tv_usec; | ||
| 527 | + double user_cpu = | ||
| 528 | + stats.ru_utime.tv_sec + SEC_PER_MICROS * stats.ru_utime.tv_usec; | ||
| 526 | 529 | double kernel_cpu = | |
| 527 | - stats.ru_utime.tv_sec + 0.000001 * stats.ru_utime.tv_usec; | ||
| 530 | + stats.ru_utime.tv_sec + SEC_PER_MICROS * stats.ru_utime.tv_usec; | ||
| 528 | 531 | writer->json_keyvalue("userCpuSeconds", user_cpu); | |
| 529 | 532 | writer->json_keyvalue("kernelCpuSeconds", kernel_cpu); | |
| 530 | 533 | double cpu_abs = user_cpu + kernel_cpu; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments