This is an automated email from the ASF dual-hosted git repository.

cmcfarlen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 5976cd611f remove ts_bwf.cc and update locations where its used 
(#10899)
5976cd611f is described below

commit 5976cd611f7067d84d6ad5834e2dd3dcb5dfcef0
Author: Chris McFarlen <[email protected]>
AuthorDate: Mon Dec 11 14:15:33 2023 -0600

    remove ts_bwf.cc and update locations where its used (#10899)
    
    * remove ts_bwf.cc and update locations where its used
    
    * add anonymous namespace
    
    ---------
    
    Co-authored-by: Chris McFarlen <[email protected]>
---
 src/tscore/Diags.cc           | 42 ++++++++++++++++++--
 src/tscpp/util/CMakeLists.txt |  2 +-
 src/tscpp/util/ts_bwf.cc      | 92 -------------------------------------------
 3 files changed, 40 insertions(+), 96 deletions(-)

diff --git a/src/tscore/Diags.cc b/src/tscore/Diags.cc
index 326e42f4c3..f4102da60d 100644
--- a/src/tscore/Diags.cc
+++ b/src/tscore/Diags.cc
@@ -46,6 +46,7 @@
 #include "tscore/Regression.h"
 #include "tscore/Diags.h"
 #include "ts/ts.h"
+#include <string_view>
 
 int DiagsConfigState::_enabled[2] = {0, 0};
 
@@ -213,6 +214,42 @@ Diags::~Diags()
   deactivate_all(DiagsTagType_Action);
 }
 
+namespace
+{
+
+struct DiagTimestamp {
+  std::chrono::time_point<std::chrono::system_clock> ts = 
std::chrono::system_clock::now();
+};
+
+swoc::BufferWriter &
+bwformat(swoc::BufferWriter &w, swoc::bwf::Spec const &spec, DiagTimestamp 
const &ts)
+{
+  auto epoch = std::chrono::system_clock::to_time_t(ts.ts);
+  swoc::LocalBufferWriter<48> lw;
+
+  ctime_r(&epoch, lw.aux_data());
+  lw.commit(19); // keep only leading text.
+  lw.print(".{:03}", 
std::chrono::time_point_cast<std::chrono::milliseconds>(ts.ts).time_since_epoch().count()
 % 1000);
+  w.write(lw.view().substr(4));
+
+  return w;
+}
+
+struct DiagThreadname {
+  char name[32];
+
+  DiagThreadname() { ink_get_thread_name(name, sizeof(name)); }
+};
+
+swoc::BufferWriter &
+bwformat(swoc::BufferWriter &w, swoc::bwf::Spec const &spec, DiagThreadname 
const &n)
+{
+  bwformat(w, spec, std::string_view{n.name});
+  return w;
+}
+
+} // namespace
+
 //////////////////////////////////////////////////////////////////////////////
 //
 //      void Diags::print_va(...)
@@ -250,11 +287,10 @@ Diags::print_va(const char *debug_tag, DiagsLevel 
diags_level, const SourceLocat
   // Save room for optional newline and terminating NUL bytes.
   format_writer.restrict(2);
 
-  format_writer.print("[{timestamp}] "_tv);
+  format_writer.print("[{}] ", DiagTimestamp{});
   auto timestamp_offset = format_writer.size();
 
-  format_writer.print("{thread-name}");
-  format_writer.print(" {}: ", level_name(diags_level));
+  format_writer.print("{} {}: ", DiagThreadname{}, level_name(diags_level));
 
   if (location(loc, show_location, diags_level)) {
     format_writer.print("<{}> ", *loc);
diff --git a/src/tscpp/util/CMakeLists.txt b/src/tscpp/util/CMakeLists.txt
index 8fbf0ae17b..fa4a3ea9fd 100644
--- a/src/tscpp/util/CMakeLists.txt
+++ b/src/tscpp/util/CMakeLists.txt
@@ -15,7 +15,7 @@
 #
 #######################
 
-add_library(tscpputil SHARED ts_bwf.cc ts_ip.cc ts_diags.cc YamlCfg.cc 
ts_unit_parser.cc Regex.cc)
+add_library(tscpputil SHARED ts_ip.cc ts_diags.cc YamlCfg.cc ts_unit_parser.cc 
Regex.cc)
 add_library(ts::tscpputil ALIAS tscpputil)
 target_link_libraries(tscpputil PUBLIC PCRE::PCRE libswoc::libswoc 
yaml-cpp::yaml-cpp)
 set(TSCPPUTIL_PUBLIC_HEADERS
diff --git a/src/tscpp/util/ts_bwf.cc b/src/tscpp/util/ts_bwf.cc
deleted file mode 100644
index f163ff620e..0000000000
--- a/src/tscpp/util/ts_bwf.cc
+++ /dev/null
@@ -1,92 +0,0 @@
-/** @file
-
-    Local extensions for @c swoc::BufferWriter
-
-    @section license License
-
-    Licensed to the Apache Software Foundation (ASF) under one
-    or more contributor license agreements.  See the NOTICE file
-    distributed with this work for additional information
-    regarding copyright ownership.  The ASF licenses this file
-    to you under the Apache License, Version 2.0 (the
-    "License"); you may not use this file except in compliance
-    with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
- */
-
-#include <unistd.h>
-#include <sys/param.h>
-#include <cctype>
-#include <ctime>
-#include <cmath>
-#include <cmath>
-#include <array>
-#include <chrono>
-#include <exception>
-
-#include "tscpp/util/ts_bw_format.h"
-#include "tscore/ink_thread.h"
-
-using namespace std::literals;
-using namespace swoc::literals;
-
-namespace
-{
-swoc::BufferWriter &
-BWF_Timestamp(swoc::BufferWriter &w, swoc::bwf::Spec const &spec)
-{
-  auto now   = std::chrono::system_clock::now();
-  auto epoch = std::chrono::system_clock::to_time_t(now);
-  swoc::LocalBufferWriter<48> lw;
-
-  ctime_r(&epoch, lw.aux_data());
-  lw.commit(19); // keep only leading text.
-  lw.print(".{:03}", 
std::chrono::time_point_cast<std::chrono::milliseconds>(now).time_since_epoch().count()
 % 1000);
-  w.write(lw.view().substr(4));
-  return w;
-}
-
-swoc::BufferWriter &
-BWF_Now(swoc::BufferWriter &w, swoc::bwf::Spec const &spec)
-{
-  return bwformat(w, spec, 
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()));
-}
-
-swoc::BufferWriter &
-BWF_Tick(swoc::BufferWriter &w, swoc::bwf::Spec const &spec)
-{
-  return bwformat(w, spec, 
std::chrono::high_resolution_clock::now().time_since_epoch().count());
-}
-
-swoc::BufferWriter &
-BWF_ThreadID(swoc::BufferWriter &w, swoc::bwf::Spec const &spec)
-{
-  return bwformat(w, spec, pthread_self());
-}
-
-swoc::BufferWriter &
-BWF_ThreadName(swoc::BufferWriter &w, swoc::bwf::Spec const &spec)
-{
-  char name[32]; // manual says at least 16, bump that up a bit.
-  ink_get_thread_name(name, sizeof(name));
-  return bwformat(w, spec, std::string_view{name});
-}
-
-static bool BW_INITIALIZED __attribute__((unused)) = []() -> bool {
-  auto &global_table = swoc::bwf::Global_Names;
-  global_table.assign("now", &BWF_Now);
-  global_table.assign("tick", &BWF_Tick);
-  global_table.assign("timestamp", &BWF_Timestamp);
-  global_table.assign("thread-id", &BWF_ThreadID);
-  global_table.assign("thread-name", &BWF_ThreadName);
-  return true;
-}();
-
-} // namespace

Reply via email to