LCOV - code coverage report
Current view: top level - tools/memory-profiler - NativeProfilerImpl.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 38 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 9 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
       5             :  * You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #include "NativeProfilerImpl.h"
       8             : 
       9             : #include "UncensoredAllocator.h"
      10             : 
      11             : namespace mozilla {
      12             : 
      13           0 : NativeProfilerImpl::NativeProfilerImpl()
      14             : {
      15           0 :   mLock = PR_NewLock();
      16           0 : }
      17             : 
      18           0 : NativeProfilerImpl::~NativeProfilerImpl()
      19             : {
      20           0 :   if (mLock) {
      21           0 :     PR_DestroyLock(mLock);
      22             :   }
      23           0 : }
      24             : 
      25             : nsTArray<nsCString>
      26           0 : NativeProfilerImpl::GetNames() const
      27             : {
      28           0 :   return mTraceTable.GetNames();
      29             : }
      30             : 
      31             : nsTArray<TrieNode>
      32           0 : NativeProfilerImpl::GetTraces() const
      33             : {
      34           0 :   return mTraceTable.GetTraces();
      35             : }
      36             : 
      37             : const nsTArray<AllocEvent>&
      38           0 : NativeProfilerImpl::GetEvents() const
      39             : {
      40           0 :   return mAllocEvents;
      41             : }
      42             : 
      43             : void
      44           0 : NativeProfilerImpl::reset()
      45             : {
      46           0 :   mTraceTable.Reset();
      47           0 :   mAllocEvents.Clear();
      48           0 :   mNativeEntries.Clear();
      49           0 : }
      50             : 
      51             : void
      52           0 : NativeProfilerImpl::sampleNative(void* addr, uint32_t size)
      53             : {
      54           0 :   AutoUseUncensoredAllocator ua;
      55           0 :   AutoMPLock lock(mLock);
      56           0 :   size_t nSamples = AddBytesSampled(size);
      57           0 :   if (nSamples > 0) {
      58           0 :     nsTArray<nsCString> trace = GetStacktrace();
      59           0 :     AllocEvent ai(mTraceTable.Insert(trace), nSamples * mSampleSize, TimeStamp::Now());
      60           0 :     mNativeEntries.Put(addr, AllocEntry(mAllocEvents.Length()));
      61           0 :     mAllocEvents.AppendElement(ai);
      62             :   }
      63           0 : }
      64             : 
      65             : void
      66           0 : NativeProfilerImpl::removeNative(void* addr)
      67             : {
      68           0 :   AutoUseUncensoredAllocator ua;
      69           0 :   AutoMPLock lock(mLock);
      70             : 
      71           0 :   AllocEntry entry;
      72           0 :   if (!mNativeEntries.Get(addr, &entry)) {
      73           0 :     return;
      74             :   }
      75             : 
      76           0 :   AllocEvent& oldEvent = mAllocEvents[entry.mEventIdx];
      77           0 :   AllocEvent newEvent(oldEvent.mTraceIdx, -oldEvent.mSize, TimeStamp::Now());
      78           0 :   mAllocEvents.AppendElement(newEvent);
      79           0 :   mNativeEntries.Remove(addr);
      80             : }
      81             : 
      82             : } // namespace mozilla

Generated by: LCOV version 1.13