Skip to content

Commit

Permalink
fix: ensure config dtor order
Browse files Browse the repository at this point in the history
PR-URL: #177
  • Loading branch information
hyj1991 authored May 9, 2022
1 parent 1d81ae2 commit ef7d4f3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 35 deletions.
37 changes: 22 additions & 15 deletions src/configure-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,59 @@
#define XPROFILER_SRC_CONFIGURE_INL_H

#include "configure.h"
#include "process_data.h"

namespace xprofiler {
std::string GetLogDir() { return per_process::config_store.log_dir; }
std::string GetLogDir() { return ProcessData::Get()->config_store()->log_dir; }

uint32_t GetLogInterval() { return per_process::config_store.log_interval; }
uint32_t GetLogInterval() {
return ProcessData::Get()->config_store()->log_interval;
}

LOG_LEVEL GetLogLevel() { return per_process::config_store.log_level; }
LOG_LEVEL GetLogLevel() {
return ProcessData::Get()->config_store()->log_level;
}

LOG_TYPE GetLogType() { return per_process::config_store.log_type; }
LOG_TYPE GetLogType() { return ProcessData::Get()->config_store()->log_type; }

bool GetFormatAsAlinode() {
return per_process::config_store.log_format_alinode;
return ProcessData::Get()->config_store()->log_format_alinode;
}

bool GetEnableLogUvHandles() {
return per_process::config_store.enable_log_uv_handles;
return ProcessData::Get()->config_store()->enable_log_uv_handles;
}

bool GetEnableFatalErrorHook() {
return per_process::config_store.enable_fatal_error_hook;
return ProcessData::Get()->config_store()->enable_fatal_error_hook;
}

bool GetEnableFatalErrorReport() {
return per_process::config_store.enable_fatal_error_report;
return ProcessData::Get()->config_store()->enable_fatal_error_report;
}

bool GetEnableFatalErrorCoredump() {
return per_process::config_store.enable_fatal_error_coredump;
return ProcessData::Get()->config_store()->enable_fatal_error_coredump;
}

bool GetPatchHttp() { return per_process::config_store.patch_http; }
bool GetPatchHttp() { return ProcessData::Get()->config_store()->patch_http; }

uint32_t GetPatchHttpTimeout() {
return per_process::config_store.patch_http_timeout;
return ProcessData::Get()->config_store()->patch_http_timeout;
}

bool GetCheckThrow() { return per_process::config_store.check_throw; }
bool GetCheckThrow() { return ProcessData::Get()->config_store()->check_throw; }

void SetLogLevel(LOG_LEVEL value) {
per_process::config_store.log_level = value;
ProcessData::Get()->config_store()->log_level = value;
}

void SetLogType(LOG_TYPE value) { per_process::config_store.log_type = value; }
void SetLogType(LOG_TYPE value) {
ProcessData::Get()->config_store()->log_type = value;
}

void SetEnableLogUvHandles(bool value) {
per_process::config_store.enable_log_uv_handles = value;
ProcessData::Get()->config_store()->enable_log_uv_handles = value;
}

} // namespace xprofiler
Expand Down
31 changes: 15 additions & 16 deletions src/configure.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "configure.h"

#include "process_data.h"
#include "util-inl.h"

namespace xprofiler {
Expand All @@ -19,10 +20,6 @@ using v8::Object;
using v8::String;
using v8::Value;

namespace per_process {
ConfigStore config_store;
}

#define LOCAL_VALUE(key) \
Local<Value> key##_value = \
Get(config, OneByteString(isolate, #key)).ToLocalChecked();
Expand All @@ -32,35 +29,37 @@ ConfigStore config_store;
if (key##_value->IsString()) { \
Local<String> key##_string = To<String>(key##_value).ToLocalChecked(); \
Utf8String key##_utf8string(key##_string); \
per_process::config_store.key = *key##_utf8string; \
ProcessData::Get()->config_store()->key = *key##_utf8string; \
}

#define CONVERT_UINT32(key) \
LOCAL_VALUE(key) \
if (key##_value->IsUint32()) { \
per_process::config_store.key = To<uint32_t>(key##_value).ToChecked(); \
#define CONVERT_UINT32(key) \
LOCAL_VALUE(key) \
if (key##_value->IsUint32()) { \
ProcessData::Get()->config_store()->key = \
To<uint32_t>(key##_value).ToChecked(); \
}

#define CONVERT_UINT32_WITH_TYPE(key, type) \
LOCAL_VALUE(key) \
if (key##_value->IsUint32()) { \
per_process::config_store.key = \
ProcessData::Get()->config_store()->key = \
static_cast<type>(To<uint32_t>(key##_value).ToChecked()); \
}

#define CONVERT_BOOL(key) \
LOCAL_VALUE(key) \
if (key##_value->IsBoolean()) { \
per_process::config_store.key = To<bool>(key##_value).ToChecked(); \
#define CONVERT_BOOL(key) \
LOCAL_VALUE(key) \
if (key##_value->IsBoolean()) { \
ProcessData::Get()->config_store()->key = \
To<bool>(key##_value).ToChecked(); \
}

#define CONFIG_LOCAL_STRING(key, type) \
Set(config, OneByteString(isolate, #key), \
New<type>(per_process::config_store.key).ToLocalChecked());
New<type>(ProcessData::Get()->config_store()->key).ToLocalChecked());

#define CONFIG_NATIVE_NUMBER(key, type) \
Set(config, OneByteString(isolate, #key), \
New<type>(per_process::config_store.key));
New<type>(ProcessData::Get()->config_store()->key));

void Configure(const FunctionCallbackInfo<Value>& info) {
Isolate* isolate = info.GetIsolate();
Expand Down
4 changes: 0 additions & 4 deletions src/configure.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ class ConfigStore {
bool enable_fatal_error_coredump = false;
};

namespace per_process {
extern ConfigStore config_store;
}

} // namespace xprofiler

#endif /* XPROFILER_SRC_CONFIGURE_H */
5 changes: 5 additions & 0 deletions src/process_data.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef XPROFILER_SRC_PROCESS_DATA_H
#define XPROFILER_SRC_PROCESS_DATA_H

#include "configure.h"
#include "environment_data.h"
#include "environment_registry.h"
#include "logbypass/log.h"
Expand Down Expand Up @@ -28,12 +29,16 @@ class ProcessData {
EnvironmentRegistry* environment_registry() {
return &environment_registry_;
};

ConfigStore* config_store() { return &config_store_; }

std::unique_ptr<LogByPass> log_by_pass;
Mutex log_by_pass_mutex;
Mutex logger_mutex;

private:
EnvironmentRegistry environment_registry_;
ConfigStore config_store_;
};

} // namespace xprofiler
Expand Down

0 comments on commit ef7d4f3

Please sign in to comment.