Skip to content

Commit

Permalink
Merged PR 317009: Add NAPA debug logs
Browse files Browse the repository at this point in the history
Add NAPA debug logs
  • Loading branch information
fs-eire committed Jul 7, 2017
1 parent 97d5f2b commit 8fe1039
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
16 changes: 8 additions & 8 deletions inc/napa-log.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,25 @@ inline void LogFormattedMessage(
#endif

#define LOG_ERROR(section, format, ...) \
LOG(section, napa::providers::LoggingProvider::Verboseness::Error, "", format, ##__VA_ARGS__);
LOG(section, napa::providers::LoggingProvider::Verboseness::Error, "", format, ##__VA_ARGS__)

#define LOG_ERROR_WITH_TRACEID(section, traceId, format, ...) \
LOG(section, napa::providers::LoggingProvider::Verboseness::Error, traceId, format, ##__VA_ARGS__);
LOG(section, napa::providers::LoggingProvider::Verboseness::Error, traceId, format, ##__VA_ARGS__)

#define LOG_WARNING(section, format, ...) \
LOG(section, napa::providers::LoggingProvider::Verboseness::Warning, "", format, ##__VA_ARGS__);
LOG(section, napa::providers::LoggingProvider::Verboseness::Warning, "", format, ##__VA_ARGS__)

#define LOG_WARNING_WITH_TRACEID(section, traceId, format, ...) \
LOG(section, napa::providers::LoggingProvider::Verboseness::Warning, traceId, format, ##__VA_ARGS__);
LOG(section, napa::providers::LoggingProvider::Verboseness::Warning, traceId, format, ##__VA_ARGS__)

#define LOG_INFO(section, format, ...) \
LOG(section, napa::providers::LoggingProvider::Verboseness::Info, "", format, ##__VA_ARGS__);
LOG(section, napa::providers::LoggingProvider::Verboseness::Info, "", format, ##__VA_ARGS__)

#define LOG_INFO_WITH_TRACEID(section, traceId, format, ...) \
LOG(section, napa::providers::LoggingProvider::Verboseness::Info, traceId, format, ##__VA_ARGS__);
LOG(section, napa::providers::LoggingProvider::Verboseness::Info, traceId, format, ##__VA_ARGS__)

#define LOG_DEBUG(section, format, ...) \
LOG(section, napa::providers::LoggingProvider::Verboseness::Debug, "", format, ##__VA_ARGS__);
LOG(section, napa::providers::LoggingProvider::Verboseness::Debug, "", format, ##__VA_ARGS__)

#define LOG_DEBUG_WITH_TRACEID(section, traceId, format, ...) \
LOG(section, napa::providers::LoggingProvider::Verboseness::Debug, traceId, format, ##__VA_ARGS__);
LOG(section, napa::providers::LoggingProvider::Verboseness::Debug, traceId, format, ##__VA_ARGS__)
2 changes: 1 addition & 1 deletion src/platform/dll.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace napa {

/// <summary> Returns the path of the dll including this line of code. </summary>
static inline std::string ThisLineLocation() {
return GetSymbolLocation(ThisLineLocation);
return GetSymbolLocation(reinterpret_cast<void*>(ThisLineLocation));
}
}
}
3 changes: 3 additions & 0 deletions src/platform/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ namespace platform {
/// <summary> Return pid. </summary>
int32_t Getpid();

/// <summary> Return tid. </summary>
int32_t Gettid();

/// <summary> Return nonzero value if a descriptor is associated with a character device. </summary>
/// <param name="fd"> File descriptor. </param>
int32_t Isatty(int32_t fd);
Expand Down
4 changes: 4 additions & 0 deletions src/platform/win/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ int32_t platform::Getpid() {
return _getpid();
}

int32_t platform::Gettid() {
return static_cast<int32_t>(GetCurrentThreadId());
}

int32_t platform::Isatty(int32_t fd) {
return _isatty(fd);
}
9 changes: 9 additions & 0 deletions src/utils/debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "napa-log.h"

#if defined(ENABLE_NAPA_DEBUG_LOG)
#define NAPA_DEBUG(section, format, ...) LOG_DEBUG(section, format, ##__VA_ARGS__)
#else
#define NAPA_DEBUG
#endif
10 changes: 8 additions & 2 deletions src/zone/worker-context.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "worker-context.h"

#include <napa-log.h>

#include <utils/debug.h>
#include <platform/platform.h>
#include <array>

using namespace napa::zone;
Expand All @@ -22,12 +23,17 @@ namespace {

void WorkerContext::Init() {
dataCollection.fill(nullptr);
NAPA_DEBUG("TLS", "[tid:%d] Init", platform::Gettid());
}

void* WorkerContext::Get(WorkerContextItem item) {
return GetTlsData(item);
auto data = GetTlsData(item);
NAPA_DEBUG("TLS", "[tid:%d] Get(%d): %ld", platform::Gettid(), (int)item, (size_t)data);

return data;
}

void WorkerContext::Set(WorkerContextItem item, void* data) {
GetTlsData(item) = data;
NAPA_DEBUG("TLS", "[tid:%d] Set(%d, %ld)", platform::Gettid(), (int)item, (size_t)data);
}

0 comments on commit 8fe1039

Please sign in to comment.