skia2/tools/trace/SkChromeTracingTracer.h
Brian Osman b6f8212bff Optimize the size of our JSON
Catapult (Chrome tracing) has a hard upper limit of 256 MB of JSON data.
This is independent of the number of events, because V8 can't store a
single string longer than that. Before these changes, longer traces
(eg all GL GMs, which was my test case) would be much larger (306 MB).

This CL includes four changes that help to reduce the text size:

1) Offset timestamps (saved 7.3 MB)
2) Limit timestamps and durations to 3 digits (saved 10.7 MB)
3) Shorten thread IDs (saved 7.2 MB)
4) Omit categories from JSON (saved 25.7 MB)

Note that category filtering still works, this just prevents us from
writing the categories to the JSON, which was of limited value.

At this point, my 306 MB file is now 255.3 MB, and loads.

Bug: skia:
Change-Id: Iaafc84025ddd52904f1ce9c1c2e9cbca65113079
Reviewed-on: https://skia-review.googlesource.com/35523
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Brian Osman <brianosman@google.com>
2017-08-17 11:51:26 +00:00

80 lines
2.3 KiB
C++

/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkChromeTracingTracer_DEFINED
#define SkChromeTracingTracer_DEFINED
#include "SkEventTracer.h"
#include "SkEventTracingPriv.h"
#include "SkSpinlock.h"
#include "SkString.h"
#include "SkTHash.h"
class SkJSONWriter;
/**
* A SkEventTracer implementation that logs events to JSON for viewing with chrome://tracing.
*/
class SkChromeTracingTracer : public SkEventTracer {
public:
SkChromeTracingTracer(const char* filename);
~SkChromeTracingTracer() override;
SkEventTracer::Handle addTraceEvent(char phase,
const uint8_t* categoryEnabledFlag,
const char* name,
uint64_t id,
int numArgs,
const char** argNames,
const uint8_t* argTypes,
const uint64_t* argValues,
uint8_t flags) override;
void updateTraceEventDuration(const uint8_t* categoryEnabledFlag,
const char* name,
SkEventTracer::Handle handle) override;
const uint8_t* getCategoryGroupEnabled(const char* name) override {
return fCategories.getCategoryGroupEnabled(name);
}
const char* getCategoryGroupName(const uint8_t* categoryEnabledFlag) override {
return fCategories.getCategoryGroupName(categoryEnabledFlag);
}
private:
void flush();
enum {
// Events are variable size, but most commonly 48 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,
};
typedef std::unique_ptr<uint8_t[]> BlockPtr;
struct TraceEventBlock {
BlockPtr fBlock;
int fEventsInBlock;
};
void createBlock();
Handle appendEvent(const void* data, size_t size);
SkString fFilename;
SkSpinlock fMutex;
SkEventTracingCategories fCategories;
TraceEventBlock fCurBlock;
size_t fCurBlockUsed;
SkTArray<TraceEventBlock> fBlocks;
};
#endif