Skip to content

Commit

Permalink
fix: worker_threads uptime
Browse files Browse the repository at this point in the history
PR-URL: #158
  • Loading branch information
legendecas authored Apr 8, 2022
1 parent 6242c54 commit 3c50958
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/commands/gcprofiler/gc_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ NAN_GC_CALLBACK(GCTracerPrologueCallback) {
writer->json_start();
writer->json_keyvalue("totalSpentfromStart", TotalGcDuration());
writer->json_keyvalue("totalTimesfromStart", TotalGcTimes());
writer->json_keyvalue("timeFromStart", GetUptime());
writer->json_keyvalue("timeFromStart", env_data->uptime());
writer->json_keyvalue("start",
(uv_hrtime() - env_data->gc_profiler->init()) / 10e5);
write_space_data(isolate, type, writer, "before");
Expand Down
2 changes: 1 addition & 1 deletion src/environment_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void EnvironmentData::Create(v8::Isolate* isolate) {
}

EnvironmentData::EnvironmentData(v8::Isolate* isolate, uv_loop_t* loop)
: isolate_(isolate), loop_(loop) {
: uptime_(uv_hrtime()), isolate_(isolate), loop_(loop) {
CHECK_EQ(0, uv_async_init(loop, &interrupt_async_, InterruptIdleCallback));
uv_unref(reinterpret_cast<uv_handle_t*>(&interrupt_async_));
CHECK_EQ(0, uv_async_init(loop, &statistics_async_, CollectStatistics));
Expand Down
12 changes: 8 additions & 4 deletions src/environment_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ class EnvironmentData {

void RequestInterrupt(InterruptCallback interrupt);

inline v8::Isolate* isolate() { return isolate_; }
inline uv_loop_t* loop() { return loop_; }
inline v8::Isolate* isolate() const { return isolate_; }
inline uv_loop_t* loop() const { return loop_; }

inline bool is_main_thread() { return is_main_thread_; }
inline ThreadId thread_id() { return thread_id_; }
inline bool is_main_thread() const { return is_main_thread_; }
inline ThreadId thread_id() const { return thread_id_; }

inline uint64_t uptime() const { return uptime_; }

inline GcStatistics* gc_statistics() { return &gc_statistics_; }
inline HttpStatistics* http_statistics() { return &http_statistics_; }
Expand All @@ -62,6 +64,8 @@ class EnvironmentData {
static void CollectStatistics(uv_async_t* handle);
EnvironmentData(v8::Isolate* isolate, uv_loop_t* loop);

const uint64_t uptime_;

v8::Isolate* isolate_;
uv_loop_t* loop_;
uv_async_t statistics_async_;
Expand Down
7 changes: 0 additions & 7 deletions src/library/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ std::atomic_size_t next_file_id(0);

void InitOnceLoadTime() { time(&per_process::load_time); }

unsigned long GetUptime() {
time_t current_time;
time(&current_time);
return static_cast<unsigned long>(
difftime(current_time, per_process::load_time));
}

std::string GetStartTime(std::string format) {
char time_string_day[32];
struct tm* ptm = localtime(&per_process::load_time);
Expand Down
7 changes: 4 additions & 3 deletions src/logbypass/gc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ void WriteGcStatusToLog(EnvironmentData* env_data, bool log_format_alinode) {
Mutex::ScopedLock lock(gc_statistics->mutex);

// record gc status
if (log_format_alinode)
if (log_format_alinode) {
Info("gc",
"gc_time_during_last_min: %lu, total: %lu, scavange_duration: %lu, "
"marksweep_duration: %lu",
gc_statistics->gc_time_during_last_record,
gc_statistics->total_gc_duration,
gc_statistics->scavange_duration_last_record,
gc_statistics->marksweep_duration_last_record);
else
} else {
InfoT("gc", env_data->thread_id(),
"uptime: %lu, "
"total_gc_times: %u, "
Expand All @@ -116,7 +116,7 @@ void WriteGcStatusToLog(EnvironmentData* env_data, bool log_format_alinode) {
"scavange_duration_last_record: %lu, "
"marksweep_duration_last_record: %lu, "
"incremental_marking_duration_last_record: %lu",
GetUptime(), // uptime, s
env_data->uptime(), // uptime, s
// total
gc_statistics->total_gc_times, gc_statistics->total_gc_duration,
gc_statistics->total_scavange_duration,
Expand All @@ -127,6 +127,7 @@ void WriteGcStatusToLog(EnvironmentData* env_data, bool log_format_alinode) {
gc_statistics->scavange_duration_last_record,
gc_statistics->marksweep_duration_last_record,
gc_statistics->incremental_marking_duration_last_record);
}
// reset last record
gc_statistics->reset();
}
Expand Down

0 comments on commit 3c50958

Please sign in to comment.