michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: The two files vprof.h and vprof.cpp implement a simple value-profiling mechanism. By including these two files in avmplus (or any other project), you can value profile data as you wish (currently integers). michael@0: michael@0: Usage: michael@0: #include "vprof.h" // in the source file you want to use it michael@0: michael@0: _vprof (value); michael@0: michael@0: At the end of the execution, for each probe you'll get the data associated with the probe, such as: michael@0: michael@0: File line avg [min : max] total count michael@0: ..\..\pcre\pcre_valid_utf8.cpp 182 50222.75916 [0 : 104947] 4036955604 80381 michael@0: michael@0: The probe is defined at line 182 of file pcre_vali_utf8.cpp. It was called 80381 times. The min value of the probe was 0 while its max was 10497 and its average was 50222.75916. The total sum of all values of the probe is 4036955604. Later, I plan to add more options on the spectrum of data among others. michael@0: michael@0: A few typical uses michael@0: ------------------ michael@0: michael@0: To see how many times a given function gets executed do: michael@0: michael@0: void f() michael@0: { michael@0: _vprof(1); michael@0: ... michael@0: } michael@0: michael@0: void f() michael@0: { michael@0: _vprof(1); michael@0: ... michael@0: if (...) { michael@0: _vprof(1); michael@0: ... michael@0: } else { michael@0: _vprof(1); michael@0: ... michael@0: } michael@0: } michael@0: michael@0: Here are a few examples of using the value-profiling utility: michael@0: michael@0: _vprof (e); michael@0: at the end of program execution, you'll get a dump of the source location of this probe, michael@0: its min, max, average, the total sum of all instances of e, and the total number of times this probe was called. michael@0: michael@0: _vprof (x > 0); michael@0: shows how many times and what percentage of the cases x was > 0, michael@0: that is the probablitiy that x > 0. michael@0: michael@0: _vprof (n % 2 == 0); michael@0: shows how many times n was an even number michael@0: as well as th probablitiy of n being an even number. michael@0: michael@0: _hprof (n, 4, 1000, 5000, 5001, 10000); michael@0: gives you the histogram of n over the given 4 bucket boundaries: michael@0: # cases < 1000 michael@0: # cases >= 1000 and < 5000 michael@0: # cases >= 5000 and < 5001 michael@0: # cases >= 5001 and < 10000 michael@0: # cases >= 10000 michael@0: michael@0: _nvprof ("event name", value); michael@0: all instances with the same name are merged michael@0: so, you can call _vprof with the same event name at difference places michael@0: michael@0: _vprof (e, myProbe); michael@0: value profile e and call myProbe (void* vprofID) at the profiling point. michael@0: inside the probe, the client has the predefined variables: michael@0: _VAL, _COUNT, _SUM, _MIN, _MAX, and the general purpose registers michael@0: _IVAR1, ..., IVAR4 general integer registrs michael@0: _I64VAR1, ..., I64VAR4 general integer64 registrs michael@0: _DVAR1, ..., _DVAR4 general double registers michael@0: _GENPTR a generic pointer that can be used by the client michael@0: the number of registers can be changed in vprof.h michael@0: michael@0: Named Events michael@0: ------------ michael@0: _nvprof ("event name", value); michael@0: all instances with the same name are merged michael@0: so, you can call _vprof with the same event name at difference places michael@0: michael@0: michael@0: Custom Probes michael@0: -------------- michael@0: You can call your own custom probe at the profiling point. michael@0: _vprof (v, myProbe); michael@0: value profile v and call myProbe (void* vprofID) at the profiling point michael@0: inside the probe, the client has the predefined variables: michael@0: _VAL, _COUNT, _SUM, _MIN, _MAX, and the general purpose registers michael@0: _IVAR1, ..., IVAR4 general integer registrs michael@0: _I64VAR1, ..., I64VAR4 general integer64 registrs michael@0: _DVAR1, ..., _DVAR4 general double registers michael@0: the number of registers can be changed in vprof.h michael@0: _GENPTR a generic pointer that can be used for almost anything