-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replace logbypass static storages with EnvironmentData
PR-URL: #129 Reviewed-BY: hyj1991 <[email protected]>
- Loading branch information
1 parent
21ade0e
commit 3718573
Showing
21 changed files
with
524 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html | ||
BasedOnStyle: Google | ||
MaxEmptyLinesToKeep: 2 | ||
DerivePointerAlignment: false | ||
MaxEmptyLinesToKeep: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "environment_data.h" | ||
|
||
#include <memory> | ||
|
||
#include "util.h" | ||
#include "xpf_node.h" | ||
|
||
namespace xprofiler { | ||
using Nan::HandleScope; | ||
using v8::Isolate; | ||
|
||
namespace per_process { | ||
// TODO(legendecas): environment registry. | ||
std::unique_ptr<EnvironmentData> environment_data; | ||
} // namespace per_process | ||
|
||
EnvironmentData* EnvironmentData::GetCurrent() { | ||
CHECK_NE(per_process::environment_data, nullptr); | ||
return per_process::environment_data.get(); | ||
} | ||
|
||
EnvironmentData* EnvironmentData::GetCurrent(v8::Isolate* isolate) { | ||
// TODO(legendecas): environment registry. | ||
CHECK_NE(per_process::environment_data, nullptr); | ||
return per_process::environment_data.get(); | ||
} | ||
|
||
EnvironmentData* EnvironmentData::GetCurrent( | ||
const Nan::FunctionCallbackInfo<v8::Value>& info) { | ||
// TODO(legendecas): environment registry. | ||
CHECK_NE(per_process::environment_data, nullptr); | ||
return per_process::environment_data.get(); | ||
} | ||
|
||
EnvironmentData* EnvironmentData::Create(v8::Isolate* isolate) { | ||
// TODO(legendecas): environment registry. | ||
CHECK_EQ(per_process::environment_data, nullptr); | ||
|
||
CHECK_EQ(isolate, Isolate::GetCurrent()); | ||
HandleScope scope; | ||
|
||
per_process::environment_data = | ||
std::unique_ptr<EnvironmentData>(new EnvironmentData(isolate)); | ||
xprofiler::AtExit(isolate, AtExit, nullptr); | ||
|
||
return per_process::environment_data.get(); | ||
} | ||
|
||
EnvironmentData::EnvironmentData(v8::Isolate* isolate) : isolate_(isolate) { | ||
uv_loop_t* loop = node::GetCurrentEventLoop(isolate); | ||
CHECK_EQ(0, uv_async_init(loop, &statistics_async_, CollectStatistics)); | ||
uv_unref(reinterpret_cast<uv_handle_t*>(&statistics_async_)); | ||
} | ||
|
||
void EnvironmentData::AtExit(void* arg) { | ||
// TODO(legendecas): environment registry. | ||
per_process::environment_data.reset(); | ||
} | ||
|
||
void EnvironmentData::SendCollectStatistics() { | ||
uv_async_send(&statistics_async_); | ||
} | ||
|
||
void EnvironmentData::CollectStatistics(uv_async_t* handle) { | ||
EnvironmentData* env_data = | ||
ContainerOf(&EnvironmentData::statistics_async_, handle); | ||
CollectMemoryStatistics(env_data); | ||
CollectLibuvHandleStatistics(env_data); | ||
} | ||
|
||
} // namespace xprofiler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#ifndef XPROFILER_SRC_ENVIRONMENT_DATA_H | ||
#define XPROFILER_SRC_ENVIRONMENT_DATA_H | ||
|
||
#include "logbypass/gc.h" | ||
#include "logbypass/heap.h" | ||
#include "logbypass/http.h" | ||
#include "logbypass/libuv.h" | ||
#include "nan.h" | ||
|
||
namespace xprofiler { | ||
|
||
class EnvironmentData { | ||
public: | ||
// TODO(legendecas): remove this no-args GetCurrent. | ||
static EnvironmentData* GetCurrent(); | ||
static EnvironmentData* GetCurrent(v8::Isolate* isolate); | ||
static EnvironmentData* GetCurrent( | ||
const Nan::FunctionCallbackInfo<v8::Value>& info); | ||
static EnvironmentData* Create(v8::Isolate* isolate); | ||
|
||
void SendCollectStatistics(); | ||
|
||
inline v8::Isolate* isolate() { return isolate_; } | ||
|
||
inline GcStatistics* gc_statistics() { return &gc_statistics_; } | ||
inline HttpStatistics* http_statistics() { return &http_statistics_; } | ||
inline MemoryStatistics* memory_statistics() { return &memory_statistics_; } | ||
inline UvHandleStatistics* uv_handle_statistics() { | ||
return &uv_handle_statistics_; | ||
} | ||
|
||
private: | ||
static void AtExit(void* arg); | ||
static void CollectStatistics(uv_async_t* handle); | ||
EnvironmentData(v8::Isolate* isolate); | ||
|
||
v8::Isolate* isolate_; | ||
uv_async_t statistics_async_; | ||
|
||
GcStatistics gc_statistics_; | ||
MemoryStatistics memory_statistics_; | ||
HttpStatistics http_statistics_; | ||
UvHandleStatistics uv_handle_statistics_; | ||
}; | ||
|
||
} // namespace xprofiler | ||
|
||
#endif /* XPROFILER_SRC_ENVIRONMENT_DATA_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
#ifndef _SRC_LOGBYPASS_CPU_H | ||
#define _SRC_LOGBYPASS_CPU_H | ||
#ifndef XPROFILER_SRC_LOGBYPASS_CPU_H | ||
#define XPROFILER_SRC_LOGBYPASS_CPU_H | ||
|
||
namespace xprofiler { | ||
void SetNowCpuUsage(); | ||
void WriteCpuUsageInPeriod(bool log_format_alinode); | ||
} // namespace xprofiler | ||
|
||
#endif | ||
#endif /* XPROFILER_SRC_LOGBYPASS_CPU_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,45 @@ | ||
#ifndef _SRC_LOGBYPASS_GC_H | ||
#define _SRC_LOGBYPASS_GC_H | ||
#ifndef XPROFILER_SRC_LOGBYPASS_GC_H | ||
#define XPROFILER_SRC_LOGBYPASS_GC_H | ||
|
||
#include "nan.h" | ||
#include "xpf_mutex-inl.h" | ||
|
||
namespace xprofiler { | ||
typedef struct GcStatistics { | ||
class EnvironmentData; | ||
|
||
class GcStatistics { | ||
public: | ||
// total gc times | ||
unsigned int total_gc_times = 0; | ||
uint32_t total_gc_times = 0; | ||
// total gc duration | ||
unsigned long total_gc_duration = 0; | ||
unsigned long total_scavange_duration = 0; | ||
unsigned long total_marksweep_duration = 0; | ||
unsigned long total_incremental_marking_duration = 0; | ||
uint32_t total_gc_duration = 0; | ||
uint32_t total_scavange_duration = 0; | ||
uint32_t total_marksweep_duration = 0; | ||
uint32_t total_incremental_marking_duration = 0; | ||
// last record | ||
unsigned long gc_time_during_last_record = 0; | ||
unsigned long scavange_duration_last_record = 0; | ||
unsigned long marksweep_duration_last_record = 0; | ||
unsigned long incremental_marking_duration_last_record = 0; | ||
uint32_t gc_time_during_last_record = 0; | ||
uint32_t scavange_duration_last_record = 0; | ||
uint32_t marksweep_duration_last_record = 0; | ||
uint32_t incremental_marking_duration_last_record = 0; | ||
uint64_t start = 0; | ||
|
||
// record start | ||
uint64_t &start() { return start_; } | ||
Mutex mutex; | ||
|
||
// reset last record | ||
void reset() { | ||
start_ = 0; | ||
start = 0; | ||
gc_time_during_last_record = 0; | ||
scavange_duration_last_record = 0; | ||
marksweep_duration_last_record = 0; | ||
incremental_marking_duration_last_record = 0; | ||
} | ||
}; | ||
|
||
private: | ||
uint64_t start_ = 0; | ||
} gc_statistics_t; | ||
void InitGcStatusHooks(); | ||
void WriteGcStatusToLog(EnvironmentData* env_data, bool log_format_alinode); | ||
|
||
int InitGcStatusHooks(); | ||
void WriteGcStatusToLog(bool log_format_alinode); | ||
unsigned int TotalGcTimes(); | ||
unsigned long TotalGcDuration(); | ||
uint32_t TotalGcTimes(); | ||
uint32_t TotalGcDuration(); | ||
} // namespace xprofiler | ||
|
||
#endif | ||
#endif /* XPROFILER_SRC_LOGBYPASS_GC_H */ |
Oops, something went wrong.