LCOV - code coverage report
Current view: top level - mfbt - TaggedAnonymousMemory.h (source / functions) Hit Total Coverage
Test: output.info Lines: 2 4 50.0 %
Date: 2017-07-14 16:53:18 Functions: 1 2 50.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=8 sts=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
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : // Some Linux kernels -- specifically, newer versions of Android and
       8             : // some B2G devices -- have a feature for assigning names to ranges of
       9             : // anonymous memory (i.e., memory that doesn't have a "name" in the
      10             : // form of an underlying mapped file).  These names are reported in
      11             : // /proc/<pid>/smaps alongside system-level memory usage information
      12             : // such as Proportional Set Size (memory usage adjusted for sharing
      13             : // between processes), which allows reporting this information at a
      14             : // finer granularity than would otherwise be possible (e.g.,
      15             : // separating malloc() heap from JS heap).
      16             : //
      17             : // Existing memory can be tagged with MozTagAnonymousMemory(); it will
      18             : // tag the range of complete pages containing the given interval, so
      19             : // the results may be inexact if the range isn't page-aligned.
      20             : // MozTaggedAnonymousMmap() can be used like mmap() with an extra
      21             : // parameter, and will tag the returned memory if the mapping was
      22             : // successful (and if it was in fact anonymous).
      23             : //
      24             : // NOTE: The pointer given as the "tag" argument MUST remain valid as
      25             : // long as the mapping exists.  The referenced string is read when
      26             : // /proc/<pid>/smaps or /proc/<pid>/maps is read, not when the tag is
      27             : // established, so freeing it or changing its contents will have
      28             : // unexpected results.  Using a static string is probably best.
      29             : //
      30             : // Also note that this header can be used by both C and C++ code.
      31             : 
      32             : #ifndef mozilla_TaggedAnonymousMemory_h
      33             : #define mozilla_TaggedAnonymousMemory_h
      34             : 
      35             : #ifndef XP_WIN
      36             : 
      37             : #include <sys/types.h>
      38             : #include <sys/mman.h>
      39             : 
      40             : #include "mozilla/Types.h"
      41             : 
      42             : #ifdef ANDROID
      43             : 
      44             : #ifdef __cplusplus
      45             : extern "C" {
      46             : #endif
      47             : 
      48             : MFBT_API void
      49             : MozTagAnonymousMemory(const void* aPtr, size_t aLength, const char* aTag);
      50             : 
      51             : MFBT_API void*
      52             : MozTaggedAnonymousMmap(void* aAddr, size_t aLength, int aProt, int aFlags,
      53             :                          int aFd, off_t aOffset, const char* aTag);
      54             : 
      55             : MFBT_API int
      56             : MozTaggedMemoryIsSupported(void);
      57             : 
      58             : #ifdef __cplusplus
      59             : } // extern "C"
      60             : #endif
      61             : 
      62             : #else // ANDROID
      63             : 
      64             : static inline void
      65             : MozTagAnonymousMemory(const void* aPtr, size_t aLength, const char* aTag)
      66             : {
      67             : }
      68             : 
      69             : static inline void*
      70         121 : MozTaggedAnonymousMmap(void* aAddr, size_t aLength, int aProt, int aFlags,
      71             :                        int aFd, off_t aOffset, const char* aTag)
      72             : {
      73         121 :   return mmap(aAddr, aLength, aProt, aFlags, aFd, aOffset);
      74             : }
      75             : 
      76             : static inline int
      77           0 : MozTaggedMemoryIsSupported(void)
      78             : {
      79           0 :   return 0;
      80             : }
      81             : 
      82             : #endif // ANDROID
      83             : 
      84             : #endif // !XP_WIN
      85             : 
      86             : #endif // mozilla_TaggedAnonymousMemory_h

Generated by: LCOV version 1.13