Skip to content

Commit e5b3f5e

Browse files
author
Minggang Wang
authored
Merge pull request #161 from minggangw/fix-issue-53-1
Add debug log for C++ code
2 parents e38f53a + a219851 commit e5b3f5e

File tree

6 files changed

+26
-1
lines changed

6 files changed

+26
-1
lines changed

binding.gyp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
{
2+
'target_defaults': {
3+
'default_configuration': 'Release',
4+
'configurations': {
5+
'Debug': {
6+
'defines': ['SPDLOG_DEBUG_ON'],
7+
},
8+
}
9+
},
210
'targets': [
311
{
412
'target_name': 'rclnodejs',
@@ -16,6 +24,7 @@
1624
],
1725
'include_dirs': [
1826
'.',
27+
'src/third_party/spdlog/include/',
1928
"<!(node -e \"require('nan')\")",
2029
],
2130
'cflags!': [

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies:
1818
- export PATH=/usr/local/Cellar/numpy/1.13.1_1/libexec/nose/bin:$PATH && mkdir -p ~/ros2_ws/src && cd ~/ros2_ws && wget https://raw.githubusercontent.com/ros2/ros2/master/ros2.repos && vcs import src < ros2.repos && src/ament/ament_tools/scripts/ament.py build --symlink-install
1919

2020
override:
21-
- source ~/ros2_ws/install/local_setup.bash && npm install && npm run lint
21+
- source ~/ros2_ws/install/local_setup.bash && git submodule init && git submodule update && npm install && npm run lint
2222

2323
test:
2424
override:

scripts/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set -e
1818

1919
pushd $(dirname $0) > /dev/null
2020

21+
git submodule update --init --recursive
2122
npm install --unsafe-perm
2223
npm run lint
2324
npm test

src/addon.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "rcl_bindings.hpp"
1818
#include "rcl_handle.hpp"
1919
#include "shadow_node.hpp"
20+
#include "spdlog/spdlog.h"
2021

2122
void InitModule(v8::Local<v8::Object> exports) {
2223
for (uint32_t i = 0;
@@ -29,6 +30,11 @@ void InitModule(v8::Local<v8::Object> exports) {
2930

3031
rclnodejs::ShadowNode::Init(exports);
3132
rclnodejs::RclHandle::Init(exports);
33+
34+
#ifdef SPDLOG_DEBUG_ON
35+
auto console = spdlog::stdout_color_mt("rclnodejs");
36+
console->set_level(spdlog::level::debug);
37+
#endif
3238
}
3339

3440
NODE_MODULE(rclnodejs, InitModule);

src/executor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <string>
2121

2222
#include "handle_manager.hpp"
23+
#include "spdlog/spdlog.h"
2324

2425
namespace rclnodejs {
2526

@@ -66,6 +67,8 @@ void Executor::Stop() {
6667
});
6768
while (!handle_closed)
6869
uv_run(uv_default_loop(), UV_RUN_ONCE);
70+
71+
SPDLOG_DEBUG(spdlog::get("rclnodejs"), "Background thread stopped.");
6972
}
7073
}
7174
}
@@ -83,6 +86,7 @@ void Executor::DoWork(uv_async_t* handle) {
8386
}
8487

8588
void Executor::Run(void* arg) {
89+
SPDLOG_DEBUG(spdlog::get("rclnodejs"), "Background thread started.");
8690
Executor* executor = reinterpret_cast<Executor*>(arg);
8791
HandleManager* handle_manager = executor->handle_manager_;
8892

src/handle_manager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <vector>
1818

1919
#include "rcl_handle.hpp"
20+
#include "spdlog/spdlog.h"
2021

2122
namespace rclnodejs {
2223

@@ -54,6 +55,9 @@ void HandleManager::CollectHandles(const v8::Local<v8::Object> node) {
5455
&clients_);
5556
CollectHandlesByType(services.ToLocalChecked()->ToObject(),
5657
&services_);
58+
SPDLOG_DEBUG(spdlog::get("rclnodejs"),
59+
"Add {0:d} timers, {1:d} subscriptions, {2:d} clients, {3:d} services.",
60+
timers_.size(), subscriptions_.size(), clients_.size(), services_.size());
5761
}
5862

5963
uint32_t HandleManager::SubscriptionsCount() {
@@ -91,6 +95,7 @@ bool HandleManager::AddHandlesToWaitSet(rcl_wait_set_t* wait_set) {
9195
if (rcl_wait_set_add_service(wait_set, service) != RCL_RET_OK)
9296
return false;
9397
}
98+
9499
return true;
95100
}
96101

0 commit comments

Comments
 (0)