Platform/Memory Reporting: Difference between revisions

Jump to navigation Jump to search
Line 87: Line 87:
   class MyStringReporter MOZ_FINAL : public MemoryUniReporter
   class MyStringReporter MOZ_FINAL : public MemoryUniReporter
   {
   {
    MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf)
   public:
   public:
     MyStringReporter()
     NS_DECL_ISUPPORTS
      : MemoryUniReporter("mystring", KIND_HEAP, UNITS_BYTES,
 
                          "Memory used for MyString.")
     NS_IMETHOD
     {}
     CollectReports(nsIHandleReportCallback* aHandleReport, nsISupports* aData)
  private:
     int64_t Amount() MOZ_OVERRIDE
     {
     {
       // BTW: If gMyString wasn't a pointer, you'd use
       // BTW: If gMyString wasn't a pointer, you'd use
       // |gMyString.SizeOfExcludingThis(MallocSizeOf)| instead.
       // |gMyString.SizeOfExcludingThis(MallocSizeOf)| instead.
       return gMyString->SizeOfIncludingThis(MallocSizeOf);  
       return MOZ_COLLECT_REPORT(
        "explicit/mystring", KIND_HEAP, UNITS_BYTES,
        gMyString->SizeOfIncludingThis(MallocSizeOf),
        "Memory used for MyString.");
     }
     }
   };
   };


<tt>MemoryUniReporter</tt> is a class that avoids most of the boilerplate code, and can be
  NS_IMPL_ISUPPORTS1(MyStringReporter, nsIMemoryReporter)
used for most uni-reporters.  Note that <tt>MallocSizeOf</tt> is a member of <tt>MemoryUniReporter</tt>.  It is a function of type <tt>nsMallocSizeOfFun</tt> that is specific to this memory reporter (and will be identified as such in DMD's output).
 
Note that <tt>MOZ_DEFINE_MALLOC_SIZE_OF</tt> defines a function of type <tt>nsMallocSizeOfFun</tt> that is specific to this memory reporter (and will be identified as such in DMD's output).


=== An Example Involving Inheritance ===
=== An Example Involving Inheritance ===
Confirmed users
1,345

edits

Navigation menu