Init commit.
This commit is contained in:
commit
26ce684fb7
|
|
@ -0,0 +1,36 @@
|
|||
cmake_minimum_required(VERSION 3.8)
|
||||
project(logging_debug)
|
||||
|
||||
add_compile_options(-Wall -Wextra -Wpedantic)
|
||||
|
||||
# find dependencies
|
||||
find_package(ament_cmake REQUIRED)
|
||||
find_package(rclcpp REQUIRED)
|
||||
find_package(spdlog REQUIRED)
|
||||
|
||||
add_executable(roslog src/roslog.cpp)
|
||||
target_link_libraries(roslog rclcpp::rclcpp)
|
||||
target_compile_features(roslog PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
|
||||
|
||||
add_executable(spdlog src/spdlog.cpp)
|
||||
target_link_libraries(spdlog rclcpp::rclcpp spdlog::spdlog)
|
||||
target_compile_features(spdlog PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
|
||||
|
||||
add_executable(nolog src/nolog.cpp)
|
||||
target_link_libraries(nolog rclcpp::rclcpp)
|
||||
target_compile_features(nolog PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
|
||||
|
||||
add_executable(spdlog_macro src/spdlog_macro.cpp)
|
||||
target_link_libraries(spdlog_macro rclcpp::rclcpp spdlog::spdlog)
|
||||
target_compile_features(spdlog_macro PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
|
||||
target_compile_definitions(spdlog_macro PRIVATE SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_INFO)
|
||||
|
||||
|
||||
install(TARGETS
|
||||
roslog
|
||||
spdlog
|
||||
spdlog_macro
|
||||
nolog
|
||||
DESTINATION lib/${PROJECT_NAME})
|
||||
|
||||
ament_package()
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
|
||||
<package format="3">
|
||||
<name>logging_debug</name>
|
||||
<version>0.0.0</version>
|
||||
<description>TODO: Package description</description>
|
||||
<maintainer email="jpace121@gmail.com">jimmy</maintainer>
|
||||
<license>MPL-2.0</license>
|
||||
|
||||
<depend>rclcpp</depend>
|
||||
<depend>spdlog</depend>
|
||||
|
||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_cmake</build_type>
|
||||
</export>
|
||||
</package>
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
/* Copyright 2025 James Pace
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
* defined by the Mozilla Public License, v. 2.0.
|
||||
*/
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class Publisher : public rclcpp::Node
|
||||
{
|
||||
public:
|
||||
Publisher():
|
||||
Node("roslog")
|
||||
{
|
||||
timer_ = this->create_wall_timer(100ms, [this]()
|
||||
{
|
||||
timer_->cancel();
|
||||
|
||||
volatile double val = 0;
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
for(int i = 0; i < 10000; i++)
|
||||
{
|
||||
val = val + 0.001*(1.0 - val);
|
||||
}
|
||||
const auto end = std::chrono::steady_clock::now();
|
||||
|
||||
const std::chrono::duration<double> diff = end - start;
|
||||
RCLCPP_INFO_STREAM(this->get_logger(), "val: " << val);
|
||||
RCLCPP_INFO_STREAM(this->get_logger(), "Time delta: " << diff.count());
|
||||
|
||||
|
||||
std::exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
rclcpp::TimerBase::SharedPtr timer_;
|
||||
};
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
rclcpp::init(argc, argv);
|
||||
rclcpp::spin(std::make_shared<Publisher>());
|
||||
rclcpp::shutdown();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
/* Copyright 2025 James Pace
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
* defined by the Mozilla Public License, v. 2.0.
|
||||
*/
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class Publisher : public rclcpp::Node
|
||||
{
|
||||
public:
|
||||
Publisher():
|
||||
Node("roslog")
|
||||
{
|
||||
timer_ = this->create_wall_timer(100ms, [this]()
|
||||
{
|
||||
timer_->cancel();
|
||||
|
||||
double val = 0;
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
for(int i = 0; i < 10000; i++)
|
||||
{
|
||||
val = val + 0.001*(1.0 - val);
|
||||
RCLCPP_DEBUG_STREAM(this->get_logger(), "Val is " << val);
|
||||
}
|
||||
const auto end = std::chrono::steady_clock::now();
|
||||
|
||||
const std::chrono::duration<double> diff = end - start;
|
||||
RCLCPP_WARN_STREAM(this->get_logger(), "Time delta: " << diff.count());
|
||||
|
||||
|
||||
std::exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
rclcpp::TimerBase::SharedPtr timer_;
|
||||
};
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
rclcpp::init(argc, argv);
|
||||
rclcpp::spin(std::make_shared<Publisher>());
|
||||
rclcpp::shutdown();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/* Copyright 2025 James Pace
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
* defined by the Mozilla Public License, v. 2.0.
|
||||
*/
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "spdlog/cfg/env.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class Publisher : public rclcpp::Node
|
||||
{
|
||||
public:
|
||||
Publisher():
|
||||
Node("spdlog")
|
||||
{
|
||||
timer_ = this->create_wall_timer(100ms, [this]()
|
||||
{
|
||||
timer_->cancel();
|
||||
|
||||
double val = 0;
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
for(int i = 0; i < 10000; i++)
|
||||
{
|
||||
val = val + 0.001*(1.0 - val);
|
||||
spdlog::info("Val is {}", val);
|
||||
}
|
||||
const auto end = std::chrono::steady_clock::now();
|
||||
|
||||
const std::chrono::duration<double> diff = end - start;
|
||||
spdlog::error("Time delta: {}", diff.count());
|
||||
|
||||
std::exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
rclcpp::TimerBase::SharedPtr timer_;
|
||||
};
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
spdlog::cfg::load_env_levels();
|
||||
rclcpp::init(argc, argv);
|
||||
rclcpp::spin(std::make_shared<Publisher>());
|
||||
rclcpp::shutdown();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/* Copyright 2025 James Pace
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
* defined by the Mozilla Public License, v. 2.0.
|
||||
*/
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "spdlog/cfg/env.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
class Publisher : public rclcpp::Node
|
||||
{
|
||||
public:
|
||||
Publisher():
|
||||
Node("spdlog")
|
||||
{
|
||||
timer_ = this->create_wall_timer(100ms, [this]()
|
||||
{
|
||||
timer_->cancel();
|
||||
|
||||
volatile double val = 0;
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
for(int i = 0; i < 10000; i++)
|
||||
{
|
||||
val = val + 0.001*(1.0 - val);
|
||||
SPDLOG_INFO("Val is {}", val);
|
||||
}
|
||||
const auto end = std::chrono::steady_clock::now();
|
||||
|
||||
const std::chrono::duration<double> diff = end - start;
|
||||
SPDLOG_ERROR("Time delta: {}", diff.count());
|
||||
|
||||
std::exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
rclcpp::TimerBase::SharedPtr timer_;
|
||||
};
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
spdlog::cfg::load_env_levels();
|
||||
rclcpp::init(argc, argv);
|
||||
rclcpp::spin(std::make_shared<Publisher>());
|
||||
rclcpp::shutdown();
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue