Bug 896737 - Limit the length of Slow SQL statements reported to Telemetry. r=vdjeric
authorKamil Muszynski <muszynski.kamil@gmail.com>
Tue, 03 Sep 2013 17:41:27 -0400
changeset 145347 98c209ce24081449952d9bbecfc2651ddecb319d
parent 145346 40b6e77191019a552bcf5848d120cfe3e63a911f
child 145376 7af0a1d83403a51a375828887ffa3f24723fa862
push id33249
push uservdjeric@mozilla.com
push dateTue, 03 Sep 2013 21:41:43 +0000
treeherdermozilla-inbound@98c209ce2408 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvdjeric
bugs896737
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 896737 - Limit the length of Slow SQL statements reported to Telemetry. r=vdjeric
toolkit/components/telemetry/Telemetry.cpp
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -2009,38 +2009,51 @@ TelemetryImpl::SanitizeSQL(const nsACStr
   }
 
   if ((fragmentStart >= 0) && fragmentStart < length)
     output += nsDependentCSubstring(sql, fragmentStart, length - fragmentStart);
 
   return output;
 }
 
+// Slow SQL statements will be automatically
+// trimmed to kMaxSlowStatementLength characters.
+// This limit doesn't include the ellipsis and DB name,
+// that are appended at the end of the stored statement.
+const uint32_t kMaxSlowStatementLength = 1000;
+
 void
 TelemetryImpl::RecordSlowStatement(const nsACString &sql,
                                    const nsACString &dbName,
                                    uint32_t delay)
 {
   if (!sTelemetry || !sTelemetry->mCanRecord)
     return;
-
-  nsAutoCString fullSQL(sql);
-  fullSQL.AppendPrintf(" /* %s */", dbName.BeginReading());
-
+  
+  nsAutoCString dbNameComment;
+  dbNameComment.AppendPrintf(" /* %s */", dbName.BeginReading());
+  
   bool isFirefoxDB = sTelemetry->mTrackedDBs.Contains(dbName);
   if (isFirefoxDB) {
-    nsAutoCString sanitizedSQL(SanitizeSQL(fullSQL));
+    nsAutoCString sanitizedSQL(SanitizeSQL(sql));
+    if (sanitizedSQL.Length() > kMaxSlowStatementLength) {
+      sanitizedSQL.SetLength(kMaxSlowStatementLength);
+      sanitizedSQL += "...";
+      sanitizedSQL += dbNameComment;
+    }
     StoreSlowSQL(sanitizedSQL, delay, Sanitized);
   } else {
     // Report aggregate DB-level statistics for addon DBs
     nsAutoCString aggregate;
     aggregate.AppendPrintf("Untracked SQL for %s", dbName.BeginReading());
     StoreSlowSQL(aggregate, delay, Sanitized);
   }
 
+  nsAutoCString fullSQL(sql);
+  fullSQL += dbNameComment;
   StoreSlowSQL(fullSQL, delay, Unsanitized);
 }
 
 #if defined(MOZ_ENABLE_PROFILER_SPS)
 void
 TelemetryImpl::RecordChromeHang(uint32_t duration,
                                 Telemetry::ProcessedStack &aStack)
 {