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

Unified Diff: gpu/common/gpu_trace_event.cc

Issue 6877101: Replaced std::string argument storage in gpu_trace_event with faster TraceAnyType (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: scheib feedback Created 9 years, 8 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
« gpu/common/gpu_trace_event.h ('K') | « gpu/common/gpu_trace_event.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/common/gpu_trace_event.cc
diff --git a/gpu/common/gpu_trace_event.cc b/gpu/common/gpu_trace_event.cc
index 882b0b8be9a9643a6e8d40e2ad8d8b04c23a703b..845b1423a81a19a3067a14e1d7ca061828181d26 100644
--- a/gpu/common/gpu_trace_event.cc
+++ b/gpu/common/gpu_trace_event.cc
@@ -39,6 +39,83 @@ TraceCategory::~TraceCategory() {
////////////////////////////////////////////////////////////////////////////////
//
+// TraceAnyType
+//
+////////////////////////////////////////////////////////////////////////////////
+
+void TraceAnyType::Destroy() {
+ if (type_ == STRING) {
+ free(value_.as_string);
+ value_.as_string = NULL;
+ }
+ type_ = NONE;
+}
+
+TraceAnyType& TraceAnyType::operator=(const TraceAnyType& rhs) {
+ DCHECK(sizeof(value_) == sizeof(uint64));
+ Destroy();
+ type_ = rhs.type_;
+ if (rhs.type_ == STRING) {
+ value_.as_string = strdup(rhs.value_.as_string);
+ } else {
+ // Copy all 64 bits for all other types.
+ value_.as_uint = rhs.value_.as_uint;
+ }
+ return *this;
+}
+
+bool TraceAnyType::operator==(const TraceAnyType& rhs) const {
+ if (type_ != rhs.type())
+ return false;
+ if (rhs.type_ == STRING) {
+ return (strcmp(value_.as_string, rhs.value_.as_string) == 0);
+ } else {
+ // Compare all 64 bits for all other types. Unused bits are set to zero
+ // by the constructors of types that may be less than 64 bits.
+ return (value_.as_uint == rhs.value_.as_uint);
+ }
+}
+
+void TraceAnyType::AppendAsJSON(std::string* out) const {
+ char temp_string[128];
+ std::string::size_type start_pos;
+ switch (type_) {
+ case BOOLEAN:
+ *out += as_bool()? "true" : "false";
+ break;
+ case UINT:
+ snprintf(temp_string, sizeof(temp_string), "%llu",
+ (unsigned long long)as_uint());
+ *out += temp_string;
+ break;
+ case INT:
+ snprintf(temp_string, sizeof(temp_string), "%lld", (long long)as_int());
+ *out += temp_string;
+ break;
+ case DOUBLE:
+ snprintf(temp_string, sizeof(temp_string), "%f", as_double());
+ *out += temp_string;
+ break;
+ case POINTER:
+ snprintf(temp_string, sizeof(temp_string), "%p", as_pointer());
+ *out += temp_string;
+ break;
+ case STRING:
+ *out += "'";
nduca 2011/04/21 22:15:44 double quotes
jbates 2011/04/21 23:57:53 Done.
+ start_pos = out->size();
+ *out += as_string();
+ // replace ' character with ` to avoid javascript errors
+ std::replace(out->begin() + start_pos, out->end(), '\'', '`');
+ *out += "'";
+ break;
+ default:
+ *out += "''";
nduca 2011/04/21 22:15:44 double quotes
jbates 2011/04/21 23:57:53 Done.
+ break;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
// TraceEvent
//
////////////////////////////////////////////////////////////////////////////////
@@ -108,9 +185,8 @@ void TraceEvent::AppendAsJSON(std::string* out) const {
if (i > 0)
*out += ",";
*out += argNames[i];
nduca 2011/04/21 22:15:44 check with @scheib/bauman --- might need to quote
jbates 2011/04/21 23:57:53 Done.
- *out += ":'";
- *out += argValues[i];
- *out += "'";
+ *out += ":";
+ argValues[i].AppendAsJSON(out);
}
*out += "}}";
}
@@ -213,8 +289,8 @@ void TraceLog::AddTraceEvent(TraceEventPhase phase,
const char* file, int line,
TraceCategory* category,
const char* name,
- const char* arg1name, const char* arg1val,
- const char* arg2name, const char* arg2val) {
+ const char* arg1name, TraceAnyType arg1val,
+ const char* arg2name, TraceAnyType arg2val) {
DCHECK(file && name);
#ifdef USE_UNRELIABLE_NOW
TimeTicks now = TimeTicks::HighResNow();
@@ -234,9 +310,9 @@ void TraceLog::AddTraceEvent(TraceEventPhase phase,
event.category = category;
event.name = name;
event.argNames[0] = arg1name;
- event.argValues[0] = arg1name ? arg1val : "";
+ event.argValues[0] = arg1val;
event.argNames[1] = arg2name;
- event.argValues[1] = arg2name ? arg2val : "";
+ event.argValues[1] = arg2val;
COMPILE_ASSERT(TRACE_MAX_NUM_ARGS == 2, TraceEvent_arc_count_out_of_sync);
if (logged_events_.size() == TRACE_EVENT_BUFFER_SIZE &&
buffer_full_callback_.get())
« gpu/common/gpu_trace_event.h ('K') | « gpu/common/gpu_trace_event.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698