SkTraceMemoryDump.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 2015 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 SkTraceMemoryDump_DEFINED
  8. #define SkTraceMemoryDump_DEFINED
  9. #include "include/core/SkTypes.h"
  10. class SkDiscardableMemory;
  11. /**
  12. * Interface for memory tracing.
  13. * This interface is meant to be passed as argument to the memory dump methods of Skia objects.
  14. * The implementation of this interface is provided by the embedder.
  15. */
  16. class SK_API SkTraceMemoryDump {
  17. public:
  18. /**
  19. * Enum to specify the level of the requested details for the dump from the Skia objects.
  20. */
  21. enum LevelOfDetail {
  22. // Dump only the minimal details to get the total memory usage (Usually just the totals).
  23. kLight_LevelOfDetail,
  24. // Dump the detailed breakdown of the objects in the caches.
  25. kObjectsBreakdowns_LevelOfDetail
  26. };
  27. /**
  28. * Appends a new memory dump (i.e. a row) to the trace memory infrastructure.
  29. * If dumpName does not exist yet, a new one is created. Otherwise, a new column is appended to
  30. * the previously created dump.
  31. * Arguments:
  32. * dumpName: an absolute, slash-separated, name for the item being dumped
  33. * e.g., "skia/CacheX/EntryY".
  34. * valueName: a string indicating the name of the column.
  35. * e.g., "size", "active_size", "number_of_objects".
  36. * This string is supposed to be long lived and is NOT copied.
  37. * units: a string indicating the units for the value.
  38. * e.g., "bytes", "objects".
  39. * This string is supposed to be long lived and is NOT copied.
  40. * value: the actual value being dumped.
  41. */
  42. virtual void dumpNumericValue(const char* dumpName,
  43. const char* valueName,
  44. const char* units,
  45. uint64_t value) = 0;
  46. virtual void dumpStringValue(const char* /*dumpName*/,
  47. const char* /*valueName*/,
  48. const char* /*value*/) { }
  49. /**
  50. * Sets the memory backing for an existing dump.
  51. * backingType and backingObjectId are used by the embedder to associate the memory dumped via
  52. * dumpNumericValue with the corresponding dump that backs the memory.
  53. */
  54. virtual void setMemoryBacking(const char* dumpName,
  55. const char* backingType,
  56. const char* backingObjectId) = 0;
  57. /**
  58. * Specialization for memory backed by discardable memory.
  59. */
  60. virtual void setDiscardableMemoryBacking(
  61. const char* dumpName,
  62. const SkDiscardableMemory& discardableMemoryObject) = 0;
  63. /**
  64. * Returns the type of details requested in the dump. The granularity of the dump is supposed to
  65. * match the LevelOfDetail argument. The level of detail must not affect the total size
  66. * reported, but only granularity of the child entries.
  67. */
  68. virtual LevelOfDetail getRequestedDetails() const = 0;
  69. /**
  70. * Returns true if we should dump wrapped objects. Wrapped objects come from outside Skia, and
  71. * may be independently tracked there.
  72. */
  73. virtual bool shouldDumpWrappedObjects() const { return true; }
  74. protected:
  75. virtual ~SkTraceMemoryDump() { }
  76. };
  77. #endif