You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by ad...@apache.org on 2020/03/30 18:56:40 UTC

[kudu] 06/07: tracing: remove kudu::Bind usage from various callbacks

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

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

commit c497253f0d95313dc6ea5d3a6dbf64ef0787115b
Author: Adar Dembo <ad...@cloudera.com>
AuthorDate: Sat Mar 28 01:44:14 2020 -0700

    tracing: remove kudu::Bind usage from various callbacks
    
    Change-Id: I0ecad2771dd77b8532bffb983866898e26ef8aa3
    Reviewed-on: http://gerrit.cloudera.org:8080/15580
    Tested-by: Kudu Jenkins
    Reviewed-by: Alexey Serbin <as...@cloudera.com>
    Reviewed-by: Andrew Wong <aw...@cloudera.com>
---
 src/kudu/util/debug/trace_event_impl.cc | 38 +++++++++++++++++----------------
 src/kudu/util/debug/trace_event_impl.h  |  9 ++++----
 2 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/src/kudu/util/debug/trace_event_impl.cc b/src/kudu/util/debug/trace_event_impl.cc
index 6388243..a03808c 100644
--- a/src/kudu/util/debug/trace_event_impl.cc
+++ b/src/kudu/util/debug/trace_event_impl.cc
@@ -21,8 +21,6 @@
 
 #include <gflags/gflags.h>
 
-#include "kudu/gutil/bind.h"
-#include "kudu/gutil/bind_helpers.h"
 #include "kudu/gutil/dynamic_annotations.h"
 #include "kudu/gutil/map-util.h"
 #include "kudu/gutil/mathlimits.h"
@@ -871,11 +869,15 @@ string TraceResultBuffer::FlushTraceLogToStringButLeaveBufferIntact() {
 
 string TraceResultBuffer::DoFlush(bool leave_intact) {
   TraceResultBuffer buf;
+  auto* buf_ptr = &buf;
   TraceLog* tl = TraceLog::GetInstance();
+  auto cb = [buf_ptr](const scoped_refptr<RefCountedString>& s, bool has_more_events) {
+    buf_ptr->Collect(s, has_more_events);
+  };
   if (leave_intact) {
-    tl->FlushButLeaveBufferIntact(Bind(&TraceResultBuffer::Collect, Unretained(&buf)));
+    tl->FlushButLeaveBufferIntact(cb);
   } else {
-    tl->Flush(Bind(&TraceResultBuffer::Collect, Unretained(&buf)));
+    tl->Flush(cb);
   }
   buf.json_.append("]}\n");
   return buf.json_;
@@ -908,7 +910,7 @@ void TraceResultBuffer::Collect(
 ////////////////////////////////////////////////////////////////////////////////
 class TraceBucketData;
 
-typedef Callback<void(TraceBucketData*)> TraceSampleCallback;
+typedef std::function<void(TraceBucketData*)> TraceSampleCallback;
 
 class TraceBucketData {
  public:
@@ -930,7 +932,7 @@ class TraceSamplingThread {
 
   void ThreadMain();
 
-  static void DefaultSamplingCallback(TraceBucketData* bucekt_data);
+  static void DefaultSamplingCallback(TraceBucketData* bucket_data);
 
   void Stop();
 
@@ -990,7 +992,7 @@ void TraceSamplingThread::DefaultSamplingCallback(
 void TraceSamplingThread::GetSamples() {
   for (auto& sample_bucket : sample_buckets_) {
     TraceBucketData* bucket_data = &sample_bucket;
-    bucket_data->callback.Run(bucket_data);
+    bucket_data->callback(bucket_data);
   }
 }
 
@@ -1349,15 +1351,15 @@ void TraceLog::SetEnabled(const CategoryFilter& category_filter,
       sampling_thread_->RegisterSampleBucket(
           &g_trace_state[0],
           "bucket0",
-          Bind(&TraceSamplingThread::DefaultSamplingCallback));
+          &TraceSamplingThread::DefaultSamplingCallback);
       sampling_thread_->RegisterSampleBucket(
           &g_trace_state[1],
           "bucket1",
-          Bind(&TraceSamplingThread::DefaultSamplingCallback));
+          &TraceSamplingThread::DefaultSamplingCallback);
       sampling_thread_->RegisterSampleBucket(
           &g_trace_state[2],
           "bucket2",
-          Bind(&TraceSamplingThread::DefaultSamplingCallback));
+          &TraceSamplingThread::DefaultSamplingCallback);
 
       Status s = Thread::CreateWithFlags(
           "tracing", "sampler",
@@ -1559,8 +1561,8 @@ void TraceLog::Flush(const TraceLog::OutputCallback& cb) {
     // - deschedule the calling thread on some platforms causing inaccurate
     //   timing of the trace events.
     scoped_refptr<RefCountedString> empty_result = new RefCountedString;
-    if (!cb.is_null())
-      cb.Run(empty_result, false);
+    if (cb)
+      cb(empty_result, false);
     LOG(WARNING) << "Ignored TraceLog::Flush called when tracing is enabled";
     return;
   }
@@ -1620,7 +1622,7 @@ void TraceLog::ConvertTraceEventsToTraceFormat(
     unique_ptr<TraceBuffer> logged_events,
     const TraceLog::OutputCallback& flush_output_callback) {
 
-  if (flush_output_callback.is_null())
+  if (!flush_output_callback)
     return;
 
   // The callback need to be called at least once even if there is no events
@@ -1643,7 +1645,7 @@ void TraceLog::ConvertTraceEventsToTraceFormat(
       }
     }
 
-    flush_output_callback.Run(json_events_str_ptr, has_more_events);
+    flush_output_callback(json_events_str_ptr, has_more_events);
   } while (has_more_events);
   logged_events.reset();
 }
@@ -1673,7 +1675,7 @@ void TraceLog::FlushButLeaveBufferIntact(
     SpinLockHolder lock(&lock_);
     if (mode_ == DISABLED || (trace_options_ & RECORD_CONTINUOUSLY) == 0) {
       scoped_refptr<RefCountedString> empty_result = new RefCountedString;
-      flush_output_callback.Run(empty_result, false);
+      flush_output_callback(empty_result, false);
       LOG(WARNING) << "Ignored TraceLog::FlushButLeaveBufferIntact when monitoring is not enabled";
       return;
     }
@@ -1901,8 +1903,8 @@ TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp(
       watch_event_callback_copy = watch_event_callback_;
     }
     if (event_name_matches) {
-      if (!watch_event_callback_copy.is_null())
-        watch_event_callback_copy.Run();
+      if (watch_event_callback_copy)
+        watch_event_callback_copy();
     }
   }
 
@@ -2062,7 +2064,7 @@ void TraceLog::CancelWatchEvent() {
   SpinLockHolder lock(&lock_);
   base::subtle::NoBarrier_Store(&watch_category_, 0);
   watch_event_name_ = "";
-  watch_event_callback_.Reset();
+  watch_event_callback_ = nullptr;
 }
 
 void TraceLog::AddMetadataEventsWhileLocked() {
diff --git a/src/kudu/util/debug/trace_event_impl.h b/src/kudu/util/debug/trace_event_impl.h
index 4503e0e..5be70c2 100644
--- a/src/kudu/util/debug/trace_event_impl.h
+++ b/src/kudu/util/debug/trace_event_impl.h
@@ -5,6 +5,7 @@
 
 #include <cstddef>
 #include <cstdint>
+#include <functional>
 #include <iosfwd>
 #include <memory>
 #include <stack>
@@ -16,7 +17,6 @@
 #include <gtest/gtest_prod.h>
 
 #include "kudu/gutil/atomicops.h"
-#include "kudu/gutil/callback.h"
 #include "kudu/gutil/macros.h"
 #include "kudu/gutil/ref_counted.h"
 #include "kudu/gutil/spinlock.h"
@@ -436,7 +436,6 @@ class TraceLog {
   float GetBufferPercentFull() const;
   bool BufferIsFull() const;
 
-  // Not using kudu::Callback because of its limited by 7 parameters.
   // Also, using primitive type allows directly passing callback from WebCore.
   // WARNING: It is possible for the previously set callback to be called
   // after a call to SetEventCallbackEnabled() that replaces or a call to
@@ -470,8 +469,8 @@ class TraceLog {
   // done when tracing is enabled. If called when tracing is enabled, the
   // callback will be called directly with (empty_string, false) to indicate
   // the end of this unsuccessful flush.
-  typedef kudu::Callback<void(const scoped_refptr<kudu::RefCountedString>&,
-                              bool has_more_events)> OutputCallback;
+  typedef std::function<void(const scoped_refptr<kudu::RefCountedString>&,
+                             bool has_more_events)> OutputCallback;
   void Flush(const OutputCallback& cb);
   void FlushButLeaveBufferIntact(const OutputCallback& flush_output_callback);
 
@@ -523,7 +522,7 @@ class TraceLog {
                                 TraceEventHandle handle);
 
   // For every matching event, the callback will be called.
-  typedef kudu::Callback<void()> WatchEventCallback;
+  typedef std::function<void()> WatchEventCallback;
   void SetWatchEvent(const std::string& category_name,
                      const std::string& event_name,
                      const WatchEventCallback& callback);