Skip to content

Commit

Permalink
tracing: remove kudu::Bind usage from various callbacks
Browse files Browse the repository at this point in the history
Change-Id: I0ecad2771dd77b8532bffb983866898e26ef8aa3
Reviewed-on: http://gerrit.cloudera.org:8080/15580
Tested-by: Kudu Jenkins
Reviewed-by: Alexey Serbin <[email protected]>
Reviewed-by: Andrew Wong <[email protected]>
  • Loading branch information
adembo committed Mar 30, 2020
1 parent ea9243a commit c497253
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
38 changes: 20 additions & 18 deletions src/kudu/util/debug/trace_event_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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_;
Expand Down Expand Up @@ -908,7 +910,7 @@ void TraceResultBuffer::Collect(
////////////////////////////////////////////////////////////////////////////////
class TraceBucketData;

typedef Callback<void(TraceBucketData*)> TraceSampleCallback;
typedef std::function<void(TraceBucketData*)> TraceSampleCallback;

class TraceBucketData {
public:
Expand All @@ -930,7 +932,7 @@ class TraceSamplingThread {

void ThreadMain();

static void DefaultSamplingCallback(TraceBucketData* bucekt_data);
static void DefaultSamplingCallback(TraceBucketData* bucket_data);

void Stop();

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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();
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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() {
Expand Down
9 changes: 4 additions & 5 deletions src/kudu/util/debug/trace_event_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <cstddef>
#include <cstdint>
#include <functional>
#include <iosfwd>
#include <memory>
#include <stack>
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c497253

Please sign in to comment.