Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1176)

Unified Diff: base/pending_task.cc

Issue 2374193002: Make base::PendingTask support ConvertableToTraceFormat (Closed)
Patch Set: JsonWriter::Write requires a temp var Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/pending_task.cc
diff --git a/base/pending_task.cc b/base/pending_task.cc
index 73834bd46071ab61c0f902b599497a72a494c35c..a7938fcf16d1c46fb3a95cfd4ce894dd4f28f102 100644
--- a/base/pending_task.cc
+++ b/base/pending_task.cc
@@ -4,10 +4,38 @@
#include "base/pending_task.h"
+#include "base/json/json_writer.h"
+#include "base/logging.h"
+#include "base/memory/ptr_util.h"
+#include "base/trace_event/trace_event.h"
#include "base/tracked_objects.h"
+#include "base/values.h"
namespace base {
+PendingTask::TracingInfo::TracingInfo(
+ const tracked_objects::Location& posted_from)
+ : posted_from_(posted_from) {
+#if DCHECK_IS_ON()
+ // TracingInfo should only be obtained when tracing is enabled or it will
+ // generate unnecessary copies.
+ bool tracing_enabled;
caseq 2016/09/29 22:46:36 considering this is hot code, you really want to k
gab 2016/10/03 15:18:57 This is only hot code if both (1) dchecks are enab
+ TRACE_EVENT_CATEGORY_GROUP_ENABLED("toplevel", &tracing_enabled);
+ DCHECK(tracing_enabled);
+#endif // DCHECK_IS_ON()
+}
+
+PendingTask::TracingInfo::~TracingInfo() = default;
+
+void PendingTask::TracingInfo::AppendAsTraceFormat(std::string* out) const {
+ DictionaryValue dict;
+ dict.SetString("src_file", posted_from_.file_name());
+ dict.SetString("src_func", posted_from_.function_name());
+ std::string tmp;
+ JSONWriter::Write(dict, &tmp);
+ out->append(tmp);
+}
+
PendingTask::PendingTask(const tracked_objects::Location& posted_from,
base::Closure task)
: base::TrackingInfo(posted_from, TimeTicks()),
@@ -32,8 +60,7 @@ PendingTask::PendingTask(const tracked_objects::Location& posted_from,
PendingTask::PendingTask(PendingTask&& other) = default;
-PendingTask::~PendingTask() {
-}
+PendingTask::~PendingTask() = default;
PendingTask& PendingTask::operator=(PendingTask&& other) = default;
@@ -53,4 +80,9 @@ bool PendingTask::operator<(const PendingTask& other) const {
return (sequence_num - other.sequence_num) > 0;
}
+std::unique_ptr<trace_event::ConvertableToTraceFormat>
+PendingTask::GetTracingInfo() const {
+ return MakeUnique<TracingInfo>(posted_from);
+}
+
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698