2017-07-20 19:43:35 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
2017-07-21 15:06:24 +00:00
|
|
|
#include "SkEventTracingPriv.h"
|
2017-07-20 19:43:35 +00:00
|
|
|
#include "SkJSONCPP.h"
|
2017-07-24 15:38:01 +00:00
|
|
|
#include "SkSpinlock.h"
|
2017-07-20 19:43:35 +00:00
|
|
|
#include "SkString.h"
|
2017-08-01 14:23:38 +00:00
|
|
|
#include "SkTHash.h"
|
2017-07-20 19:43:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A SkEventTracer implementation that logs events to JSON for viewing with chrome://tracing.
|
|
|
|
*/
|
|
|
|
class SkChromeTracingTracer : public SkEventTracer {
|
|
|
|
public:
|
2017-07-24 15:38:01 +00:00
|
|
|
SkChromeTracingTracer(const char* filename);
|
|
|
|
~SkChromeTracingTracer() override;
|
2017-07-20 19:43:35 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2017-07-21 15:06:24 +00:00
|
|
|
const uint8_t* getCategoryGroupEnabled(const char* name) override {
|
|
|
|
return fCategories.getCategoryGroupEnabled(name);
|
|
|
|
}
|
2017-07-20 19:43:35 +00:00
|
|
|
|
|
|
|
const char* getCategoryGroupName(const uint8_t* categoryEnabledFlag) override {
|
2017-07-21 15:06:24 +00:00
|
|
|
return fCategories.getCategoryGroupName(categoryEnabledFlag);
|
2017-07-20 19:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void flush();
|
|
|
|
|
2017-07-24 15:38:01 +00:00
|
|
|
enum {
|
2017-08-01 14:23:38 +00:00
|
|
|
// Events are currently 88 bytes, assuming 64-bit pointers and reasonable packing.
|
2017-07-24 15:38:01 +00:00
|
|
|
// 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,
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
2017-08-01 14:23:38 +00:00
|
|
|
uint64_t fID;
|
2017-07-24 15:38:01 +00:00
|
|
|
uint64_t fClockBegin;
|
|
|
|
uint64_t fClockEnd;
|
|
|
|
SkThreadID fThreadID;
|
|
|
|
|
|
|
|
const char* fArgNames[kMaxArgs];
|
|
|
|
uint64_t fArgValues[kMaxArgs];
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::unique_ptr<TraceEvent[]> BlockPtr;
|
|
|
|
BlockPtr createBlock();
|
2017-08-01 14:23:38 +00:00
|
|
|
|
|
|
|
typedef SkTHashMap<uint64_t, const char*> BaseTypeResolver;
|
2017-07-24 15:38:01 +00:00
|
|
|
TraceEvent* appendEvent(const TraceEvent&);
|
2017-08-01 14:23:38 +00:00
|
|
|
Json::Value traceEventToJson(const TraceEvent&, BaseTypeResolver* baseTypeResolver);
|
2017-07-24 15:38:01 +00:00
|
|
|
|
2017-07-20 19:43:35 +00:00
|
|
|
SkString fFilename;
|
2017-07-24 15:38:01 +00:00
|
|
|
SkSpinlock fMutex;
|
2017-07-21 15:06:24 +00:00
|
|
|
SkEventTracingCategories fCategories;
|
2017-07-24 15:38:01 +00:00
|
|
|
BlockPtr fCurBlock;
|
|
|
|
int fEventsInCurBlock;
|
|
|
|
SkTArray<BlockPtr> fBlocks;
|
2017-07-20 19:43:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|