[rtems-tools commit] record: Add filter base class

Sebastian Huber sebh at rtems.org
Thu Mar 19 06:38:42 UTC 2020


Module:    rtems-tools
Branch:    master
Commit:    bfc8f2de784825448e0b44b83e32b9378d01d465
Changeset: http://git.rtems.org/rtems-tools/commit/?id=bfc8f2de784825448e0b44b83e32b9378d01d465

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Mar 16 07:03:06 2020 +0100

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(-)

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 <csignal>
 #include <cstring>
 #include <iostream>
+#include <list>
 #include <map>
 #include <stdexcept>
 #include <string>
@@ -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<Filter*> 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<size_t>(n));
+    void* p = &buf[0];
+    size_t k = static_cast<size_t>(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<size_t>(n);
   }
+
+  Flush();
 }
 
 void Client::Destroy() {



More information about the vc mailing list