From bfc8f2de784825448e0b44b83e32b9378d01d465 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 16 Mar 2020 07:03:06 +0100 Subject: record: Add filter base class Update #3904. --- trace/record/client.h | 21 ++++++++++++++++++++- trace/record/record-client-base.cc | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) (limited to 'trace') diff --git a/trace/record/client.h b/trace/record/client.h index 2fe8d51..636fb0b 100644 --- a/trace/record/client.h +++ b/trace/record/client.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* - * Copyright (C) 2018, 2019 embedded brains GmbH (http://www.embedded-brains.de) + * Copyright (C) 2018, 2020 embedded brains GmbH (http://www.embedded-brains.de) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -98,6 +99,19 @@ class ConfigFile { const char* value); }; +class Filter { + public: + Filter() = default; + + Filter(const Filter&) = default; + + Filter& operator=(const Filter&) = default; + + virtual ~Filter() = default; + + virtual bool Run(void** buf, size_t* n) = 0; +}; + class Client { public: Client() = default; @@ -114,6 +128,8 @@ class Client { void RequestStop() { stop_ = 1; } + void AddFilter(Filter* filter) { filters_.push_back(filter); } + void Destroy(); void set_limit(uint64_t limit) { limit_ = limit; } @@ -127,9 +143,12 @@ class Client { private: rtems_record_client_context base_; + std::list filters_; FileDescriptor input_; sig_atomic_t stop_ = 0; uint64_t limit_ = 0; + + void Flush(); }; #endif // RTEMS_TOOLS_TRACE_RECORD_CLIENT_H_ diff --git a/trace/record/record-client-base.cc b/trace/record/record-client-base.cc index 8c467d4..f022db4 100644 --- a/trace/record/record-client-base.cc +++ b/trace/record/record-client-base.cc @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-2-Clause */ /* - * Copyright (C) 2018, 2019 embedded brains GmbH (http://www.embedded-brains.de) + * Copyright (C) 2018, 2020 embedded brains GmbH (http://www.embedded-brains.de) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -144,6 +144,24 @@ int ConfigFile::INIHandler(void* user, return 0; } +void Client::Flush() { + while (true) { + void* p = nullptr; + size_t n = 0; + for (auto filter : filters_) { + if (!filter->Run(&p, &n)) { + break; + } + } + + if (n > 0) { + rtems_record_client_run(&base_, p, n); + } else { + break; + } + } +} + void Client::Run() { uint64_t todo = UINT64_MAX; @@ -159,9 +177,20 @@ void Client::Run() { break; } - rtems_record_client_run(&base_, buf, static_cast(n)); + void* p = &buf[0]; + size_t k = static_cast(n); + for (auto filter : filters_) { + if (!filter->Run(&p, &k)) { + std::cerr << "error: input filter failure" << std::endl; + return; + } + } + + rtems_record_client_run(&base_, p, k); todo -= static_cast(n); } + + Flush(); } void Client::Destroy() { -- cgit v1.2.3