Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions daemon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ ENDIF()

IF(GATORD_WERROR)
SET(GATORD_C_CXX_FLAGS "${GATORD_C_CXX_FLAGS} -Werror")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(GATORD_C_CXX_FLAGS "${GATORD_C_CXX_FLAGS} -Wno-error=maybe-uninitialized")
endif()
ENDIF()

IF(GATORD_BUILD_STATIC)
Expand Down
4 changes: 2 additions & 2 deletions daemon/agents/common/polling_cpu_monitor.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2022-2024 by Arm Limited. All rights reserved. */
/* Copyright (C) 2022-2025 by Arm Limited. All rights reserved. */

#pragma once

Expand Down Expand Up @@ -99,7 +99,7 @@ namespace agents {
return start_on(st->strand) //
| then([st]() { return st->on_strand_do_poll(); }) //
| then([st](bool any_offline) {
st->timer.expires_from_now(any_offline ? short_poll_interval : long_poll_interval);
st->timer.expires_after(any_offline ? short_poll_interval : long_poll_interval);
}) //
| st->timer.async_wait(use_continuation) //
| post_on(st->strand) //
Expand Down
3 changes: 2 additions & 1 deletion daemon/agents/perf/async_perf_ringbuffer_monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <chrono>
#include <cstddef>
#include <deque>
#include <map>
#include <memory>
#include <set>
#include <utility>
Expand Down Expand Up @@ -645,7 +646,7 @@ namespace agents::perf {
});
}, //
[st]() {
st->timer.expires_from_now(st->live_mode ? live_poll_interval : local_poll_interval);
st->timer.expires_after(st->live_mode ? live_poll_interval : local_poll_interval);

return st->timer.async_wait(use_continuation) //
| post_on(st->strand) //
Expand Down
4 changes: 2 additions & 2 deletions daemon/agents/perf/perf_capture_cpu_monitor.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2022-2024 by Arm Limited. All rights reserved. */
/* Copyright (C) 2022-2025 by Arm Limited. All rights reserved. */

#pragma once

Expand All @@ -17,9 +17,9 @@
#include <memory>
#include <set>

#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/io_context_strand.hpp>
#include <boost/asio/system_timer.hpp>
#include <boost/date_time/posix_time/posix_time_duration.hpp>

namespace agents::perf {
Expand Down
21 changes: 13 additions & 8 deletions daemon/agents/perf/perf_capture_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@

#include <boost/asio.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/error.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/posix/stream_descriptor.hpp>
#include <boost/asio/read_until.hpp>
#include <boost/asio/system_timer.hpp>
#include <boost/date_time/posix_time/posix_time_duration.hpp>
#include <boost/system/error_code.hpp>

Expand Down Expand Up @@ -827,8 +827,10 @@ namespace agents::perf {
void terminate(bool defer = false)
{
boost::asio::post(strand, [defer, st = this->shared_from_this()]() {
using namespace std::chrono_literals;

// delay to use when deferring shutdown
constexpr auto defer_delay_ms = boost::posix_time::milliseconds(1000);
constexpr auto defer_delay_ms = 1000ms;

// only perform the terminate once
auto timer = std::exchange(st->terminate_delay_timer, nullptr);
Expand Down Expand Up @@ -865,7 +867,7 @@ namespace agents::perf {
// defer the terminate() call to allow the async_perf_ringbuffer_monitor to receive any closed() events for the event fds it monitors
if (defer) {
LOG_FINE("Terminating pid monitoring... starting termination countdown.");
timer->expires_from_now(defer_delay_ms);
timer->expires_after(defer_delay_ms);
timer->async_wait(std::move(handler));
}
// otherwise, call the handler directly
Expand Down Expand Up @@ -903,7 +905,7 @@ namespace agents::perf {
return;
}

auto poll_delay_timer = std::make_shared<boost::asio::deadline_timer>(st->strand.context());
auto poll_delay_timer = std::make_shared<boost::asio::system_timer>(st->strand.context());

spawn("process scanner",
repeatedly(
Expand Down Expand Up @@ -960,10 +962,12 @@ namespace agents::perf {
| st->async_read_process_maps(use_continuation);
}) //
| then([poll_delay_timer]() {
using namespace std::chrono_literals;

// delay to use when deferring scanning
constexpr auto defer_delay_ms = boost::posix_time::milliseconds(100);
constexpr auto defer_delay_ms = 100ms;

poll_delay_timer->expires_from_now(defer_delay_ms);
poll_delay_timer->expires_after(defer_delay_ms);
return poll_delay_timer->async_wait(use_continuation);
})
| then([](auto /*ec*/) {
Expand All @@ -988,8 +992,9 @@ namespace agents::perf {
std::shared_ptr<async::async_wait_for_process_t<boost::asio::io_context::executor_type>> waiter {};
std::shared_ptr<async_perf_ringbuffer_monitor_t> async_perf_ringbuffer_monitor;
std::shared_ptr<async::proc::async_process_t> forked_command;
std::shared_ptr<boost::asio::deadline_timer> terminate_delay_timer {
new boost::asio::deadline_timer(strand.context())};
std::shared_ptr<boost::asio::system_timer> terminate_delay_timer {
new boost::asio::system_timer(strand.context()),
};
perf_capture_events_helper_t perf_capture_events_helper;
bool terminate_requested {false};

Expand Down
5 changes: 1 addition & 4 deletions daemon/async/async_byte_reader.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2022-2023 by Arm Limited. All rights reserved. */
/* Copyright (C) 2022-2025 by Arm Limited. All rights reserved. */

#pragma once

Expand All @@ -25,9 +25,6 @@ namespace async {
public:
static constexpr std::size_t default_read_chunk_size = 65536;

// assumes that data returns a single item
static_assert(std::is_same_v<boost::asio::streambuf::const_buffers_type, boost::asio::const_buffers_1>);

/** Constructor */
explicit async_byte_reader_t(boost::asio::posix::stream_descriptor && sd,
std::size_t read_chunk_size = default_read_chunk_size)
Expand Down
108 changes: 52 additions & 56 deletions daemon/async/async_line_reader.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* Copyright (C) 2022-2023 by Arm Limited. All rights reserved. */
/* Copyright (C) 2022-2025 by Arm Limited. All rights reserved. */

#pragma once

#include "Logging.h"
#include "async/continuations/async_initiate.h"
#include "async/continuations/continuation.h"
#include "async/continuations/continuation_of.h"
Expand All @@ -12,9 +13,11 @@
#include <string_view>
#include <type_traits>

#include <boost/asio/async_result.hpp>
#include <boost/asio/posix/stream_descriptor.hpp>
#include <boost/asio/read_until.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/system/detail/error_code.hpp>
#include <boost/system/error_code.hpp>

namespace async {
Expand All @@ -34,64 +37,57 @@ namespace async {
template<typename CompletionToken>
auto async_read_line(CompletionToken && token)
{
using namespace async::continuations;

return async_initiate_cont(
[st = shared_from_this()]() {
return boost::asio::async_initiate<CompletionToken, void(boost::system::error_code, std::string_view)>(
[st = shared_from_this()](auto handler) {
// consume the bytes from the buffer, ready for the next loop
st->buffer.consume(std::exchange(st->n_to_consume, 0));

return boost::asio::async_read_until(st->stream_descriptor,
st->buffer,
'\n',
use_continuation) //
| then([st](boost::system::error_code const & ec, std::size_t n) {
// assumes that data returns a single item
static_assert(std::is_same_v<boost::asio::streambuf::const_buffers_type,
boost::asio::const_buffers_1>);

auto const is_eof = (ec == boost::asio::error::eof);

// handle errors
if ((!is_eof) && ec) {
LOG_DEBUG("Read failed with %s", ec.message().c_str());
return std::pair {ec, std::string_view()};
}

// process line of text

// find the modified buffer chunk
auto const input_area = st->buffer.data();
auto const read_area_length = std::min(n, input_area.size());

// first find the substr containing up-to the first '\n' marker
auto const read_area =
std::string_view(reinterpret_cast<char const *>(input_area.data()),
read_area_length);

auto const message = find_end_of_line(read_area);
st->n_to_consume = message.size();

// only report EOF once buffer is drained of complete lines
if (is_eof && message.empty()) {
// if there is some trailing, unterminated (by EOL) text, send it
if (input_area.size() > 0) {
st->n_to_consume = input_area.size();
return std::pair {
boost::system::error_code {},
std::string_view(reinterpret_cast<char const *>(input_area.data()),
input_area.size())};
}

// otherwise report the EOF
return std::pair {boost::system::error_code {boost::asio::error::eof},
std::string_view {}};
}

// report the line
return std::pair {boost::system::error_code {}, message};
}) //
| unpack_tuple();
return boost::asio::async_read_until(
st->stream_descriptor,
st->buffer,
'\n',
[st, handler = std::move(handler)](boost::system::error_code ec,
std::size_t n) mutable -> void {
// assumes that data returns a single item
auto const is_eof = (ec == boost::asio::error::eof);

// handle errors
if ((!is_eof) && ec) {
LOG_DEBUG("Read failed with %s", ec.message().c_str());
return handler(ec, std::string_view());
}

// process line of text

// find the modified buffer chunk
auto const input_area = st->buffer.data();
auto const read_area_length = std::min(n, input_area.size());

// first find the substr containing up-to the first '\n' marker
auto const read_area =
std::string_view(reinterpret_cast<char const *>(input_area.data()), read_area_length);

auto const message = find_end_of_line(read_area);
st->n_to_consume = message.size();

// only report EOF once buffer is drained of complete lines
if (is_eof && message.empty()) {
// if there is some trailing, unterminated (by EOL) text, send it
if (input_area.size() > 0) {
st->n_to_consume = input_area.size();
return handler(boost::system::error_code {},
std::string_view(reinterpret_cast<char const *>(input_area.data()),
input_area.size()));
}

// otherwise report the EOF
return handler(boost::system::error_code {boost::asio::error::eof},
std::string_view {});
}

// report the line
return handler(boost::system::error_code {}, message);
});
},
std::forward<CompletionToken>(token));
}
Expand Down
2 changes: 1 addition & 1 deletion daemon/cmake/compiler-flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ endif()
# Add strict warning settings for C++
# ###
IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(GCC_STRICT_WARNING_FLAGS_CXX "-Wall -Wextra -Wno-shadow -Wno-psabi")
set(GCC_STRICT_WARNING_FLAGS_CXX "-Wall -Wextra -Wno-shadow -Wno-psabi -Wno-error=maybe-uninitialized")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_STRICT_WARNING_FLAGS_CXX}")
ELSEIF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# disable this until the hwcpipe2 submodule is changed to a vcpkg port
Expand Down
6 changes: 3 additions & 3 deletions daemon/ipc/proto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (C) 2022 by Arm Limited. All rights reserved.
# Copyright (C) 2022-2025 by Arm Limited. All rights reserved.

find_package(Protobuf REQUIRED)
find_package(Protobuf CONFIG REQUIRED)

set(Protobuf_IMPORT_DIRS ${CMAKE_CURRENT_LIST_DIR})

Expand All @@ -18,7 +18,7 @@ target_include_directories(ipcproto
)

target_link_libraries(ipcproto
PRIVATE ${Protobuf_LITE_LIBRARIES}
PRIVATE ${Protobuf_LITE_LIBRARIES} protobuf::libprotobuf-lite
)

target_compile_options(ipcproto PRIVATE "-Wno-error")
Expand Down
20 changes: 14 additions & 6 deletions daemon/lib/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@
#include <string>
#include <system_error>

#include <boost/version.hpp>

#if BOOST_VERSION >= (108600)
#include <boost/process/v1/child.hpp>
#include <boost/process/v1/io.hpp>
namespace boost_process = boost::process::v1;
#else
#include <boost/process/child.hpp>
#include <boost/process/io.hpp>
namespace boost_process = boost::process;
#endif

#include <sys/prctl.h>

namespace bp = boost::process;

namespace gator::process {
int system(const std::string & cmd)
int system(const std::string & process_with_args)
{
// TODO: replace with Boost::Process once the dependency mechanism is agreed
return std::system(cmd.c_str());
return std::system(process_with_args.c_str());
}

void set_parent_death_signal(int signal)
Expand All @@ -38,8 +45,9 @@ namespace gator::process {
int runCommandAndRedirectOutput(const std::string & cmdToExecWithArgs,
const std::optional<std::string> & targetFile)
{
auto child = targetFile.has_value() ? bp::child(cmdToExecWithArgs, bp::std_out > targetFile.value())
: bp::child(cmdToExecWithArgs);
auto child = targetFile.has_value()
? boost_process::child(cmdToExecWithArgs, boost_process::std_out > targetFile.value())
: boost_process::child(cmdToExecWithArgs);

std::error_code ec;
child.wait(ec);
Expand Down
3 changes: 2 additions & 1 deletion daemon/lib/String.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2018-2024 by Arm Limited. All rights reserved. */
/* Copyright (C) 2018-2025 by Arm Limited. All rights reserved. */

#pragma once

Expand All @@ -13,6 +13,7 @@
#include <stdexcept>
#include <string>
#include <string_view>
#include <vector>

#include <boost/lexical_cast/try_lexical_convert.hpp>

Expand Down