Update contrib.
2 * LIBOIL - Library of Optimized Inner Loops
3 * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
27 //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
33 #include <liboil/liboilprofile.h>
34 #include <liboil/liboildebug.h>
36 #ifdef HAVE_SYS_TIME_H
45 #pragma diag_remark 68
50 * SECTION:liboilprofile
53 * Measuring the length of time needed to execute Liboil functions.
59 * @prof: the OilProfile structure
61 * Initializes a profiling structure.
67 oil_profile_init (OilProfile *prof)
69 memset(prof, 0, sizeof(OilProfile));
76 * oil_profile_stop_handle:
77 * @prof: the OilProfile structure
79 * Handles post-processing of a single profiling run.
81 * FIXME: need more info
87 oil_profile_stop_handle (OilProfile *prof)
91 prof->last = prof->stop - prof->start;
93 prof->total += prof->last;
96 if (prof->last < prof->min) prof->min = prof->last;
98 for(i=0;i<prof->hist_n;i++) {
99 if (prof->last == prof->hist_time[i]) {
100 prof->hist_count[i]++;
104 if (i == prof->hist_n && prof->hist_n < OIL_PROFILE_HIST_LENGTH) {
105 prof->hist_time[prof->hist_n] = prof->last;
106 prof->hist_count[prof->hist_n] = 1;
112 * oil_profile_get_ave_std:
113 * @prof: the OilProfile structure
114 * @ave_p: pointer to average
115 * @std_p: pointer to standard deviation
117 * Calculates the average and standard deviation of a number of
118 * profiling runs, and places the results in the locations
119 * provided by @ave_p and @std_p. Either @ave_p and @std_p may
120 * be NULL, in which case the values will not be written.
126 oil_profile_get_ave_std (OilProfile *prof, double *ave_p, double *std_p)
143 x = prof->hist_time[i];
144 s2 += x * x * prof->hist_count[i];
145 s += x * prof->hist_count[i];
146 n += prof->hist_count[i];
147 if (prof->hist_count[i] > 0) {
148 if (max_i == -1 || prof->hist_time[i] > prof->hist_time[max_i]) {
155 std = sqrt (s2 - s * s / n + n*n) / (n-1);
156 off = (prof->hist_time[max_i] - ave)/std;
159 prof->hist_count[max_i] = 0;
163 if (ave_p) *ave_p = ave;
164 if (std_p) *std_p = std;
167 unsigned long (*_oil_profile_stamp)(void);
172 * Creates a timestamp based on a CPU-specific high-frequency
173 * counter, if available.
175 * Returns: a timestamp
181 oil_profile_stamp (void)
183 return _oil_profile_stamp();