Record all trace event data inline, with variable sized entries

Removes the need for strdup with copied strings, paves the way for
more (and richer) payload, and shrinks the average event way down.

Bug: skia:
Change-Id: I9604fe713c34cfc877dce84563af89c579abd65b
Reviewed-on: https://skia-review.googlesource.com/35166
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/tools/trace/SkChromeTracingTracer.h b/tools/trace/SkChromeTracingTracer.h
index c6411bb..34fbbae 100644
--- a/tools/trace/SkChromeTracingTracer.h
+++ b/tools/trace/SkChromeTracingTracer.h
@@ -50,45 +50,30 @@
     void flush();
 
     enum {
-        // Events are currently 88 bytes, assuming 64-bit pointers and reasonable packing.
-        // This is a first guess at a number that balances memory usage vs. time overhead of
-        // allocating blocks.
-        kEventsPerBlock = 10000,
-
-        // Our current tracing macros only support up to 2 arguments
-        kMaxArgs = 2,
+        // Events are variable size, but most commonly 56 bytes, assuming 64-bit pointers and
+        // reasonable packing. This is a first guess at a number that balances memory usage vs.
+        // time overhead of allocating blocks.
+        kBlockSize = 512 * 1024,
     };
 
-    struct TraceEvent {
-        // Fields are ordered to minimize size due to alignment
-        char fPhase;
-        uint8_t fNumArgs;
-        uint8_t fArgTypes[kMaxArgs];
-
-        const char* fName;
-        const char* fCategory;
-        uint64_t fID;
-        uint64_t fClockBegin;
-        uint64_t fClockEnd;
-        SkThreadID fThreadID;
-
-        const char* fArgNames[kMaxArgs];
-        uint64_t fArgValues[kMaxArgs];
+    typedef std::unique_ptr<uint8_t[]> BlockPtr;
+    struct TraceEventBlock {
+        BlockPtr fBlock;
+        int fEventsInBlock;
     };
 
-    typedef std::unique_ptr<TraceEvent[]> BlockPtr;
-    BlockPtr createBlock();
+    void createBlock();
 
-    typedef SkTHashMap<uint64_t, const char*> BaseTypeResolver;
-    TraceEvent* appendEvent(const TraceEvent&);
-    void traceEventToJson(SkJSONWriter*, const TraceEvent&, BaseTypeResolver* baseTypeResolver);
+    Handle appendEvent(const void* data, size_t size);
 
     SkString fFilename;
     SkSpinlock fMutex;
     SkEventTracingCategories fCategories;
-    BlockPtr fCurBlock;
-    int fEventsInCurBlock;
-    SkTArray<BlockPtr> fBlocks;
+
+    TraceEventBlock fCurBlock;
+    size_t fCurBlockUsed;
+
+    SkTArray<TraceEventBlock> fBlocks;
 };
 
 #endif