home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / xp / xp_tracker.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.3 KB  |  162 lines

  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19.  
  20. #ifndef __XPTRACKER__
  21. #define    __XPTRACKER__
  22.  
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26.  
  27. #define    kStackDepth                23
  28. #define    kBlockTagStringLength    750
  29.  
  30.  
  31. // Block State
  32. enum {
  33.     kBlockFree = 0,
  34.     kBlockAllocated = 1
  35. };
  36.  
  37. /*
  38.  * Binary Log tags
  39.  */
  40.  
  41. #define    kSET_BLOCK_LIST            'setb'
  42. #define    kALLOCATION_SITE_LIST    'allc'
  43. #define    kSIZE_HISTOGRAM            'shst'
  44.  
  45. /* a log header */
  46. typedef struct LogHeader {
  47.     unsigned long            logTag;
  48.     unsigned long            logSize;
  49. } LogHeader;
  50.  
  51. /* a single entry in an allocation site binary log */
  52. typedef struct AllocationSiteLogEntry {
  53.     unsigned long    currentBlocks;
  54.     unsigned long    currentMemUsed;
  55.     unsigned long    maxMemUsed;
  56.     unsigned long    maxBlocks;
  57.     unsigned long    totalBlocks;
  58.     unsigned long    totalMemUsed;
  59.     unsigned long    tag;
  60.     char            stackNames[ kBlockTagStringLength ];
  61. } AllocationSiteLogEntry;
  62.  
  63. typedef struct AllocationSiteLog {
  64.     LogHeader                header;
  65.     unsigned long            numEntries;
  66.     AllocationSiteLogEntry    log[];
  67. } AllocationSiteLog;
  68.  
  69. /* single entry in a allocation set log */
  70. typedef struct AllocationSetLogEntry {
  71.     unsigned long            address;
  72.     unsigned long            blockNumber;
  73.     unsigned long            size;
  74.     unsigned long            siteIndex;
  75.     unsigned char            blockState;
  76.     unsigned char            overhead;
  77.     unsigned char            pad[ 2 ];
  78. } AllocationSetLogEntry;
  79.  
  80. typedef struct AllocationSetLog {
  81.     LogHeader                header;
  82.     unsigned long            numEntries;
  83.     unsigned long            totalAllocation;
  84.     unsigned long            currentAllocation;
  85.     unsigned long            maxAllocation;
  86.     char                    name[ 256 ];
  87.     AllocationSetLogEntry    log[];
  88. } AllocationSetLog;
  89.  
  90. /* histogram log */
  91. #define    kMaxRecordedSize            256
  92. #define    kNumHistogramEntries        ((kMaxRecordedSize / 4) + 2)
  93. #define    CONVERT_SIZE_TO_INDEX(s)    ((s) > kMaxRecordedSize ? (kNumHistogramEntries - 1) : ((s) + 3) >> 2)
  94.  
  95. typedef struct HistogramLogEntry {
  96.     UInt32    total;
  97.     UInt32    max;
  98.     UInt32    current;
  99. } HistogramLogEntry;
  100.  
  101. typedef struct HistogramLog {
  102.     LogHeader                header;
  103.     HistogramLogEntry        count[ kNumHistogramEntries ];
  104. } HistogramLog;
  105.  
  106. /*
  107.  * Routines to initialize the memory tracker
  108.  */
  109. void InitializeMemoryTracker ( void );
  110. void ExitMemoryTracker ( void );
  111. void DumpMemoryTrackerState ( void );
  112. void DumpAllocationSites ( void );
  113.  
  114. void DisableMemoryTracker ( void );
  115. void EnableMemoryTracker ( void );
  116.  
  117. /*
  118.  * Decoder Function. This function is called with the data attached to
  119.  * an active block when the log is being written out. resultString points
  120.  * at a string of length kBlockTagStringLength.
  121.  */
  122. typedef void (*DecoderProc) ( void ** data, char * resultString );
  123.  
  124. /*
  125.  * Call this function to set the decoder proc for a given data tag.
  126.  * The most common thing here will be a stack crawl decoder that will
  127.  * convert an array of address to a list of function names and offsets
  128.  */
  129. void SetTrackerDataDecoder ( UInt32 tag, DecoderProc proc );
  130.  
  131.  
  132. /*
  133.  * Call these functions to add a new item to be tracked and then release it later
  134.  */
  135. void TrackItem ( void * address, size_t blockSize, size_t overhead, UInt32 tag,
  136.     void * decoderData );
  137. void ReleaseItem ( void * address );
  138.  
  139.  
  140. /*
  141.  *    Allocation Sets.
  142.  */
  143. typedef struct AllocationSet AllocationSet;
  144.  
  145. /* Options */
  146. enum {
  147.     kTrackAllBlocks = 0x00000001,
  148.     kKeepFreeBlocks = 0x00000002
  149. };
  150.  
  151. AllocationSet * NewAllocationSet ( unsigned long trackingOptions, char * name );
  152. void DisposeAllocationSet ( AllocationSet * set );
  153. void LogAllocationSetState ( AllocationSet * set );
  154. void EnableAllocationSet ( AllocationSet * set );
  155. void DisableAllocationSet ( AllocationSet * set );
  156.  
  157. #ifdef __cplusplus
  158. }
  159. #endif
  160.  
  161. #endif    /* __XPTRACKER__ */
  162.