SkATrace.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright 2016 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkATrace_DEFINED
  8. #define SkATrace_DEFINED
  9. #include "include/utils/SkEventTracer.h"
  10. /**
  11. * This class is used to support ATrace in android apps. It hooks into the SkEventTracer system. It
  12. * currently supports the macros TRACE_EVENT*, TRACE_EVENT_INSTANT*, and TRACE_EVENT_BEGIN/END*.
  13. * For versions of these calls that take additoinal args and value pairs we currently just drop them
  14. * and report only the name. Since ATrace is a simple push and pop system (all traces are fully
  15. * nested), if using BEGIN and END you should also make sure your calls are properly nested (i.e. if
  16. * startA is before startB, then endB is before endA).
  17. */
  18. class SkATrace : public SkEventTracer {
  19. public:
  20. SkATrace();
  21. SkEventTracer::Handle addTraceEvent(char phase,
  22. const uint8_t* categoryEnabledFlag,
  23. const char* name,
  24. uint64_t id,
  25. int numArgs,
  26. const char** argNames,
  27. const uint8_t* argTypes,
  28. const uint64_t* argValues,
  29. uint8_t flags) override;
  30. void updateTraceEventDuration(const uint8_t* categoryEnabledFlag,
  31. const char* name,
  32. SkEventTracer::Handle handle) override;
  33. const uint8_t* getCategoryGroupEnabled(const char* name) override;
  34. const char* getCategoryGroupName(const uint8_t* categoryEnabledFlag) override {
  35. static const char* category = "skiaATrace";
  36. return category;
  37. }
  38. private:
  39. void (*fBeginSection)(const char*);
  40. void (*fEndSection)(void);
  41. bool (*fIsEnabled)(void);
  42. };
  43. #endif