LCOV - code coverage report
Current view: directory - js/src/gc - Statistics.h (source / functions) Found Hit Coverage
Test: app.info Lines: 21 20 95.2 %
Date: 2012-04-07 Functions: 10 9 90.0 %

       1                 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2                 :  * vim: set ts=8 sw=4 et tw=78:
       3                 :  *
       4                 :  * ***** BEGIN LICENSE BLOCK *****
       5                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       6                 :  *
       7                 :  * The contents of this file are subject to the Mozilla Public License Version
       8                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       9                 :  * the License. You may obtain a copy of the License at
      10                 :  * http://www.mozilla.org/MPL/
      11                 :  *
      12                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      13                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      14                 :  * for the specific language governing rights and limitations under the
      15                 :  * License.
      16                 :  *
      17                 :  * The Original Code is SpiderMonkey JavaScript engine.
      18                 :  *
      19                 :  * The Initial Developer of the Original Code is
      20                 :  * the Mozilla Foundation.
      21                 :  * Portions created by the Initial Developer are Copyright (C) 2011
      22                 :  * the Initial Developer. All Rights Reserved.
      23                 :  *
      24                 :  * Contributor(s):
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      28                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #ifndef jsgc_statistics_h___
      41                 : #define jsgc_statistics_h___
      42                 : 
      43                 : #include <string.h>
      44                 : 
      45                 : #include "jsfriendapi.h"
      46                 : #include "jspubtd.h"
      47                 : #include "jsutil.h"
      48                 : 
      49                 : struct JSCompartment;
      50                 : 
      51                 : namespace js {
      52                 : namespace gcstats {
      53                 : 
      54                 : enum Phase {
      55                 :     PHASE_GC_BEGIN,
      56                 :     PHASE_WAIT_BACKGROUND_THREAD,
      57                 :     PHASE_PURGE,
      58                 :     PHASE_MARK,
      59                 :     PHASE_MARK_ROOTS,
      60                 :     PHASE_MARK_DELAYED,
      61                 :     PHASE_MARK_OTHER,
      62                 :     PHASE_FINALIZE_START,
      63                 :     PHASE_SWEEP,
      64                 :     PHASE_SWEEP_COMPARTMENTS,
      65                 :     PHASE_SWEEP_OBJECT,
      66                 :     PHASE_SWEEP_STRING,
      67                 :     PHASE_SWEEP_SCRIPT,
      68                 :     PHASE_SWEEP_SHAPE,
      69                 :     PHASE_DISCARD_CODE,
      70                 :     PHASE_DISCARD_ANALYSIS,
      71                 :     PHASE_DISCARD_TI,
      72                 :     PHASE_SWEEP_TYPES,
      73                 :     PHASE_CLEAR_SCRIPT_ANALYSIS,
      74                 :     PHASE_FINALIZE_END,
      75                 :     PHASE_DESTROY,
      76                 :     PHASE_GC_END,
      77                 : 
      78                 :     PHASE_LIMIT
      79                 : };
      80                 : 
      81                 : enum Stat {
      82                 :     STAT_NEW_CHUNK,
      83                 :     STAT_DESTROY_CHUNK,
      84                 : 
      85                 :     STAT_LIMIT
      86                 : };
      87                 : 
      88                 : class StatisticsSerializer;
      89                 : 
      90                 : struct Statistics {
      91                 :     Statistics(JSRuntime *rt);
      92                 :     ~Statistics();
      93                 : 
      94                 :     void beginPhase(Phase phase);
      95                 :     void endPhase(Phase phase);
      96                 : 
      97                 :     void beginSlice(int collectedCount, int compartmentCount, gcreason::Reason reason);
      98                 :     void endSlice();
      99                 : 
     100              27 :     void reset(const char *reason) { slices.back().resetReason = reason; }
     101           38240 :     void nonincremental(const char *reason) { nonincrementalReason = reason; }
     102                 : 
     103           80982 :     void count(Stat s) {
     104           80982 :         JS_ASSERT(s < STAT_LIMIT);
     105           80982 :         counts[s]++;
     106           80982 :     }
     107                 : 
     108                 :     jschar *formatMessage();
     109                 :     jschar *formatJSON(uint64_t timestamp);
     110                 : 
     111                 :   private:
     112                 :     JSRuntime *runtime;
     113                 : 
     114                 :     int64_t startupTime;
     115                 : 
     116                 :     FILE *fp;
     117                 :     bool fullFormat;
     118                 : 
     119                 :     int collectedCount;
     120                 :     int compartmentCount;
     121                 :     const char *nonincrementalReason;
     122                 : 
     123           38481 :     struct SliceData {
     124           38481 :         SliceData(gcreason::Reason reason, int64_t start)
     125           38481 :           : reason(reason), resetReason(NULL), start(start)
     126                 :         {
     127           38481 :             PodArrayZero(phaseTimes);
     128           38481 :         }
     129                 : 
     130                 :         gcreason::Reason reason;
     131                 :         const char *resetReason;
     132                 :         int64_t start, end;
     133                 :         int64_t phaseTimes[PHASE_LIMIT];
     134                 : 
     135               0 :         int64_t duration() const { return end - start; }
     136                 :     };
     137                 : 
     138                 :     Vector<SliceData, 8, SystemAllocPolicy> slices;
     139                 : 
     140                 :     /* Most recent time when the given phase started. */
     141                 :     int64_t phaseStarts[PHASE_LIMIT];
     142                 : 
     143                 :     /* Total time in a given phase for this GC. */
     144                 :     int64_t phaseTimes[PHASE_LIMIT];
     145                 : 
     146                 :     /* Total time in a given phase over all GCs. */
     147                 :     int64_t phaseTotals[PHASE_LIMIT];
     148                 : 
     149                 :     /* Number of events of this type for this GC. */
     150                 :     unsigned int counts[STAT_LIMIT];
     151                 : 
     152                 :     /* Allocated space before the GC started. */
     153                 :     size_t preBytes;
     154                 : 
     155                 :     void beginGC();
     156                 :     void endGC();
     157                 : 
     158                 :     int64_t gcDuration();
     159                 :     void printStats();
     160                 :     bool formatData(StatisticsSerializer &ss, uint64_t timestamp);
     161                 : 
     162                 :     double computeMMU(int64_t resolution);
     163                 : };
     164                 : 
     165                 : struct AutoGCSlice {
     166           38481 :     AutoGCSlice(Statistics &stats, int collectedCount, int compartmentCount, gcreason::Reason reason
     167                 :                 JS_GUARD_OBJECT_NOTIFIER_PARAM)
     168           38481 :       : stats(stats)
     169                 :     {
     170           38481 :         JS_GUARD_OBJECT_NOTIFIER_INIT;
     171           38481 :         stats.beginSlice(collectedCount, compartmentCount, reason);
     172           38481 :     }
     173           38481 :     ~AutoGCSlice() { stats.endSlice(); }
     174                 : 
     175                 :     Statistics &stats;
     176                 :     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
     177                 : };
     178                 : 
     179                 : struct AutoPhase {
     180         1051317 :     AutoPhase(Statistics &stats, Phase phase JS_GUARD_OBJECT_NOTIFIER_PARAM)
     181         1051317 :       : stats(stats), phase(phase) { JS_GUARD_OBJECT_NOTIFIER_INIT; stats.beginPhase(phase); }
     182         1051317 :     ~AutoPhase() { stats.endPhase(phase); }
     183                 : 
     184                 :     Statistics &stats;
     185                 :     Phase phase;
     186                 :     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
     187                 : };
     188                 : 
     189                 : } /* namespace gcstats */
     190                 : } /* namespace js */
     191                 : 
     192                 : #endif /* jsgc_statistics_h___ */

Generated by: LCOV version 1.7