Skip to content

Commit

Permalink
fix: replace hex node module version with semantic version macros
Browse files Browse the repository at this point in the history
PR-URL: #131
Reviewed-BY: hyj1991 <[email protected]>
  • Loading branch information
legendecas authored Feb 10, 2022
1 parent 3718573 commit c4ced63
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
10 changes: 5 additions & 5 deletions src/commands/cpuprofiler/cpu_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using v8::String;
Profiler::Profiler() {}
Profiler::~Profiler() {}

#if (NODE_MODULE_VERSION > 0x0039)
#if (NODE_MODULE_VERSION > NODE_8_0_MODULE_VERSION)
static int started_profiles_count = 0;
static int sampling_interval = 0;
static CpuProfiler* current_cpuprofiler = nullptr;
Expand All @@ -24,7 +24,7 @@ void Profiler::StartProfiling(std::string t) {
HandleScope scope;
Local<String> title = New<String>(t).ToLocalChecked();

#if (NODE_MODULE_VERSION > 0x0039)
#if (NODE_MODULE_VERSION > NODE_8_0_MODULE_VERSION)
if (!started_profiles_count) {
current_cpuprofiler = CpuProfiler::New(Isolate::GetCurrent());
}
Expand All @@ -43,15 +43,15 @@ void Profiler::StopProfiling(string t, string filename) {
HandleScope scope;
Local<String> title = New<String>(t).ToLocalChecked();

#if (NODE_MODULE_VERSION > 0x0039)
#if (NODE_MODULE_VERSION > NODE_8_0_MODULE_VERSION)
profile = current_cpuprofiler->StopProfiling(title);
#else
profile = Isolate::GetCurrent()->GetCpuProfiler()->StopProfiling(title);
#endif

Profile::Serialize(profile, filename);

#if (NODE_MODULE_VERSION > 0x0039)
#if (NODE_MODULE_VERSION > NODE_8_0_MODULE_VERSION)
const_cast<CpuProfile*>(profile)->Delete();
--started_profiles_count;
if (!started_profiles_count) {
Expand All @@ -62,7 +62,7 @@ void Profiler::StopProfiling(string t, string filename) {
}

void Profiler::SetSamplingInterval(uint32_t sample) {
#if (NODE_MODULE_VERSION > 0x0039)
#if (NODE_MODULE_VERSION > NODE_8_0_MODULE_VERSION)
sampling_interval = sample;
#else
Isolate::GetCurrent()->GetCpuProfiler()->SetSamplingInterval(sample);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/report/javascript_stack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "nan.h"

static const unsigned kMaxFramesCount = 255;
#if (NODE_MODULE_VERSION >= 0x003b)
#if (NODE_MODULE_VERSION >= NODE_9_0_MODULE_VERSION)
static const char* v8_states[] = {
"JS", "GC", "PARSER", "BYTECODE_COMPILER",
"COMPILER", "OTHER", "EXTERNAL", "IDLE"};
Expand Down Expand Up @@ -106,4 +106,4 @@ void SetJavaScriptStack(JSONWriter* writer, bool fatal_error) {
}
writer->json_arrayend();
}
} // namespace xprofiler
} // namespace xprofiler
2 changes: 1 addition & 1 deletion src/logbypass/heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void GetRss(size_t* rss) {

void SetHeapStatistics(XprofilerHeapStatistics* heap_statistics) {
GetHeapStatistics(heap_statistics->handle());
#if (NODE_MODULE_VERSION < 72)
#if (NODE_MODULE_VERSION < NODE_12_0_MODULE_VERSION)
Isolate* isolate = Isolate::GetCurrent();
heap_statistics->external_memory() =
isolate->AdjustAmountOfExternalAllocatedMemory(0);
Expand Down
12 changes: 6 additions & 6 deletions src/logbypass/heap.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _SRC_LOGBYPASS_HEAP_H
#define _SRC_LOGBYPASS_HEAP_H
#ifndef XPROFILER_SRC_LOGBYPASS_HEAP_H
#define XPROFILER_SRC_LOGBYPASS_HEAP_H

#include "node_version.h"
#include "nan.h"
#include "v8.h"

namespace xprofiler {
Expand Down Expand Up @@ -31,14 +31,14 @@ struct XprofilerHeapStatistics {
return heap_statistics_.total_physical_size();
}
size_t malloced_memory() { return heap_statistics_.malloced_memory(); }
#if (NODE_MODULE_VERSION >= 72)
#if (NODE_MODULE_VERSION >= NODE_12_0_MODULE_VERSION)
size_t external_memory() { return heap_statistics_.external_memory(); }
#else
size_t& external_memory() { return external_memory_; }
#endif

private:
#if (NODE_MODULE_VERSION < 72)
#if (NODE_MODULE_VERSION < NODE_12_0_MODULE_VERSION)
// external memory
size_t external_memory_ = 0;
#endif
Expand Down Expand Up @@ -66,4 +66,4 @@ void CollectMemoryStatistics(EnvironmentData* env_data);
void WriteMemoryInfoToLog(EnvironmentData* env_data, bool log_format_alinode);
} // namespace xprofiler

#endif
#endif /* XPROFILER_SRC_LOGBYPASS_HEAP_H */
4 changes: 2 additions & 2 deletions src/platform/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void SleepCrossPlatform(int seconds);
string GetSep();
int GetPid();
// for node-v8.x & ndoe-v10.x
#if (NODE_MODULE_VERSION < 72)
#if (NODE_MODULE_VERSION < NODE_12_0_MODULE_VERSION)
typedef struct {
int64_t tv_sec;
int32_t tv_usec;
Expand All @@ -42,4 +42,4 @@ void PrintLoadedLibraries(JSONWriter *writer);
void CheckSocketPath(const FunctionCallbackInfo<Value> &info);
} // namespace xprofiler

#endif
#endif
4 changes: 2 additions & 2 deletions src/platform/unix/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ string GetSep() { return "/"; }

int GetPid() { return getpid(); }

#if (NODE_MODULE_VERSION < 72)
#if (NODE_MODULE_VERSION < NODE_12_0_MODULE_VERSION)
// from libuv: uv/src/unix
int uv_gettimeofday(uv_timeval64_t *tv) {
struct timeval time;
Expand All @@ -28,4 +28,4 @@ int uv_gettimeofday(uv_timeval64_t *tv) {
#endif
} // namespace xprofiler

#endif
#endif
4 changes: 2 additions & 2 deletions src/platform/win/utils_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ string GetSep() { return "\\"; }

int GetPid() { return getpid(); }

#if (NODE_MODULE_VERSION < 72)
#if (NODE_MODULE_VERSION < NODE_12_0_MODULE_VERSION)
// from libuv: uv/src/unix
int uv_gettimeofday(uv_timeval64_t *tv) {
const uint64_t epoch = (uint64_t)116444736000000000ULL;
Expand All @@ -30,4 +30,4 @@ int uv_gettimeofday(uv_timeval64_t *tv) {
#endif
} // namespace xprofiler

#endif
#endif

0 comments on commit c4ced63

Please sign in to comment.