js/src/devtools/vprof/vprof.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 //
     7 //  Here are a few examples of using the value-profiling utility:
     8 //
     9 //  _vprof (e);
    10 //    at the end of program execution, you'll get a dump of the source location of this probe,
    11 //    its min, max, average, the total sum of all instances of e, and the total number of times this probe was called.
    12 //
    13 //  _vprof (x > 0);
    14 //    shows how many times and what percentage of the cases x was > 0,
    15 //    that is the probablitiy that x > 0.
    16 //
    17 // _vprof (n % 2 == 0);
    18 //    shows how many times n was an even number
    19 //    as well as th probablitiy of n being an even number.
    20 //
    21 // _hprof (n, 4, 1000, 5000, 5001, 10000);
    22 //    gives you the histogram of n over the given 4 bucket boundaries:
    23 //        # cases <  1000
    24 //        # cases >= 1000 and < 5000
    25 //        # cases >= 5000 and < 5001
    26 //        # cases >= 5001 and < 10000
    27 //        # cases >= 10000
    28 //
    29 // _nvprof ("event name", value);
    30 //    all instances with the same name are merged
    31 //    so, you can call _vprof with the same event name at difference places
    32 //
    33 // _vprof (e, myProbe);
    34 //    value profile e and call myProbe (void* vprofID) at the profiling point.
    35 //    inside the probe, the client has the predefined variables:
    36 //    _VAL, _COUNT, _SUM, _MIN, _MAX, and the general purpose registers
    37 //    _IVAR1, ..., IVAR4      general integer registrs
    38 //    _I64VAR1, ..., I64VAR4  general integer64 registrs
    39 //    _DVAR1, ..., _DVAR4     general double registers
    40 //    _GENPTR a generic pointer that can be used by the client
    41 //    the number of registers can be changed in vprof.h
    42 //
    44 #ifndef devtools_vprof_vprof_h
    45 #define devtools_vprof_vprof_h
    46 //
    47 // If the application for which you want to use vprof is threaded, THREADED must be defined as 1, otherwise define it as 0
    48 //
    49 // If your application is not threaded, define THREAD_SAFE 0,
    50 // otherwise, you have the option of setting THREAD_SAFE to 1 which results in exact counts or to 0 which results in a much more efficient but non-exact counts
    51 //
    52 #define THREADED 0
    53 #define THREAD_SAFE 0
    55 #include "VMPI.h"
    57 // Note, this is not supported in configurations with more than one AvmCore running
    58 // in the same process.
    60 // portable align macro
    61 #if defined(_MSC_VER)
    62 	#define vprof_align8(t) __declspec(align(8)) t
    63 #elif defined(__GNUC__)
    64 	#define vprof_align8(t) t __attribute__ ((aligned (8)))
    65 #elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
    66 	#define vprof_align8(t) t __attribute__ ((aligned (8)))
    67 #elif defined(VMCFG_SYMBIAN)
    68 	#define vprof_align8(t) t __attribute__ ((aligned (8)))
    69 #endif
    71 #ifdef __cplusplus
    72 extern "C" {
    73 #endif
    75 int initValueProfile(void** id, char* file, int line, ...);
    76 int profileValue(void* id, int64_t value);
    77 int initHistProfile(void** id, char* file, int line, int nbins, ...);
    78 int histValue(void* id, int64_t value);
    79 uint64_t readTimestampCounter();
    81 #ifdef __cplusplus
    82 }
    83 #endif
    85 //#define DOPROF
    87 #ifndef DOPROF
    88 #define _nvprof(e,v)
    89 #ifndef VMCFG_SYMBIAN
    90 #define _vprof(v,...)
    91 #define _hprof(v,n,...)
    92 #define _nhprof(e,v,n,...)
    93 #define _ntprof_begin(e)
    94 #define _ntprof_end(e)
    95 #define _jvprof_init(id,...)
    96 #define _jnvprof_init(id,e,...)
    97 #define _jhprof_init(id,n,...)
    98 #define _jnhprof_init(id,e,n,...)
    99 #define _jvprof(id,v)
   100 #define _jhprof(id,v)
   101 #endif // ! VMCFG_SYMBIAN
   102 #else
   104 // Historical/compatibility note:
   105 // The macros below were originally written using conditional expressions, not if/else.  The original author
   106 // said that this was done to allow _vprof and _nvprof to be used in an expression context, but the old code
   107 // had already wrapped the macro bodies in { }, so it is not clear how this could have worked.  At present,
   108 // the profiling macros must appear in a statement context only.
   110 #define _vprof(v,...) \
   111 do { \
   112     static void* id = 0; \
   113     if (id == 0) \
   114         initValueProfile(&id, __FILE__, __LINE__, ##__VA_ARGS__, NULL); \
   115     profileValue(id, (int64_t) (v)); \
   116 } while (0)
   118 #define _nvprof(e,v) \
   119 do { \
   120     static void* id = 0; \
   121     if (id == 0) \
   122         initValueProfile(&id, (char*) (e), -1, NULL); \
   123     profileValue(id, (int64_t) (v)); \
   124 } while (0)
   126 #define _hprof(v,n,...) \
   127 do { \
   128     static void* id = 0; \
   129     if (id == 0) \
   130         initHistProfile(&id, __FILE__, __LINE__, (int) (n), ##__VA_ARGS__); \
   131     histValue(id, (int64_t) (v)); \
   132 } while (0)
   134 #define _nhprof(e,v,n,...) \
   135 do { \
   136     static void* id = 0; \
   137     if (id == 0) \
   138         initHistProfile(&id, (char*) (e), -1, (int) (n), ##__VA_ARGS__); \
   139     histValue(id, (int64_t) (v)); \
   140 } while (0)
   142 // Profile execution time between _ntprof_begin(e) and _ntprof_end(e).
   143 // The tag 'e' must match at the beginning and end of the region to
   144 // be timed.  Regions may be nested or overlap arbitrarily, as it is
   145 // the tag alone that defines the begin/end correspondence.
   147 #define _ntprof_begin(e) \
   148 do { \
   149     static void* id = 0; \
   150     if (id == 0) \
   151         initValueProfile(&id, (char*)(e), -1, NULL); \
   152     ((entry_t)id)->i64var[0] = readTimestampCounter(); \
   153 } while (0)
   155 // Assume 2.6 Ghz CPU
   156 #define TICKS_PER_USEC 2600
   158 #define _ntprof_end(e) \
   159 do { \
   160     static void* id = 0; \
   161     uint64_t stop = readTimestampCounter(); \
   162     if (id == 0) \
   163         initValueProfile(&id, (char*)(e), -1, NULL); \
   164     uint64_t start = ((entry_t)id)->i64var[0]; \
   165     uint64_t usecs = (stop - start) / TICKS_PER_USEC; \
   166     profileValue(id, usecs); \
   167 } while (0)
   169 // These macros separate the creation of a profile record from its later usage.
   170 // They are intended for profiling JIT-generated code.  Once created, the JIT can
   171 // bind a pointer to the profile record into the generated code, which can then
   172 // record profile events during execution.
   174 #define _jvprof_init(id,...) \
   175     if (*(id) == 0) \
   176         initValueProfile((id), __FILE__, __LINE__, ##__VA_ARGS__, NULL)
   178 #define _jnvprof_init(id,e,...) \
   179     if (*(id) == 0) \
   180         initValueProfile((id), (char*) (e), -1, ##__VA_ARGS__, NULL)
   182 #define _jhprof_init(id,n,...) \
   183     if (*(id) == 0) \
   184         initHistProfile((id), __FILE__, __LINE__, (int) (n), ##__VA_ARGS__)
   186 #define _jnhprof_init(id,e,n,...) \
   187     if (*(id) == 0) \
   188         initHistProfile((id), (char*) (e), -1, (int) (n), ##__VA_ARGS__)
   190 // Calls to the _jvprof and _jhprof macros must be wrapped in a non-inline
   191 // function in order to be invoked from JIT-compiled code.
   193 #define _jvprof(id,v) \
   194     profileValue((id), (int64_t) (v))
   196 #define _jhprof(id,v) \
   197     histValue((id), (int64_t) (v))
   199 #endif
   201 #define NUM_EVARS 4
   203 enum {
   204     LOCK_IS_FREE = 0,
   205     LOCK_IS_TAKEN = 1
   206 };
   208 extern
   209 #ifdef __cplusplus
   210 "C"
   211 #endif
   212 long _InterlockedCompareExchange (
   213    long volatile * Destination,
   214    long Exchange,
   215    long Comperand
   216 );
   218 typedef struct hist hist;
   220 typedef struct hist {
   221     int nbins;
   222     int64_t* lb;
   223     int64_t* count;
   224 } *hist_t;
   226 typedef struct entry entry;
   228 typedef struct entry {
   229     long lock;
   230     char* file;
   231     int line;
   232     int64_t value;
   233     int64_t count;
   234     int64_t sum;
   235     int64_t min;
   236     int64_t max;
   237     void (*func)(void*);
   238     hist* h;
   240     entry* next;
   242     // exposed to the clients
   243     void* genptr;
   244     int ivar[NUM_EVARS];
   245     vprof_align8(int64_t) i64var[NUM_EVARS];
   246     vprof_align8(double) dvar[NUM_EVARS];
   247     //
   249     char pad[128]; // avoid false sharing
   250 } *entry_t;
   252 #define _VAL ((entry_t)vprofID)->value
   253 #define _COUNT ((entry_t)vprofID)->count
   254 #define _SUM ((entry_t)vprofID)->sum
   255 #define _MIN ((entry_t)vprofID)->min
   256 #define _MAX ((entry_t)vprofID)->max
   258 #define _GENPTR ((entry_t)vprofID)->genptr
   260 #define _IVAR0 ((entry_t)vprofID)->ivar[0]
   261 #define _IVAR1 ((entry_t)vprofID)->ivar[1]
   262 #define _IVAR2 ((entry_t)vprofID)->ivar[2]
   263 #define _IVAR3 ((entry_t)vprofID)->ivar[3]
   265 #define _I64VAR0 ((entry_t)vprofID)->i64var[0]
   266 #define _I64VAR1 ((entry_t)vprofID)->i64var[1]
   267 #define _I64VAR2 ((entry_t)vprofID)->i64var[2]
   268 #define _I64VAR3 ((entry_t)vprofID)->i64var[3]
   270 #define _DVAR0 ((entry_t)vprofID)->dvar[0]
   271 #define _DVAR1 ((entry_t)vprofID)->dvar[1]
   272 #define _DVAR2 ((entry_t)vprofID)->dvar[2]
   273 #define _DVAR3 ((entry_t)vprofID)->dvar[3]
   275 #endif /* devtools_vprof_vprof_h */

mercurial