sl@0: /* sl@0: * LIBOIL - Library of Optimized Inner Loops sl@0: * Copyright (c) 2003,2004 David A. Schleef sl@0: * All rights reserved. sl@0: * sl@0: * Redistribution and use in source and binary forms, with or without sl@0: * modification, are permitted provided that the following conditions sl@0: * are met: sl@0: * 1. Redistributions of source code must retain the above copyright sl@0: * notice, this list of conditions and the following disclaimer. sl@0: * 2. Redistributions in binary form must reproduce the above copyright sl@0: * notice, this list of conditions and the following disclaimer in the sl@0: * documentation and/or other materials provided with the distribution. sl@0: * sl@0: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR sl@0: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED sl@0: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE sl@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, sl@0: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES sl@0: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR sl@0: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) sl@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, sl@0: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING sl@0: * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE sl@0: * POSSIBILITY OF SUCH DAMAGE. sl@0: */ sl@0: //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. sl@0: sl@0: #ifdef HAVE_CONFIG_H sl@0: #include sl@0: #endif sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #ifdef HAVE_SYS_TIME_H sl@0: #include sl@0: #endif sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: #ifdef __ARMCC__ sl@0: #pragma diag_remark 68 sl@0: #endif//__ARMCC__ sl@0: #endif//__SYMBIAN32__ sl@0: sl@0: /** sl@0: * SECTION:liboilprofile sl@0: * @title:OilProfile sl@0: * @short_description: sl@0: * Measuring the length of time needed to execute Liboil functions. sl@0: * sl@0: */ sl@0: sl@0: /** sl@0: * oil_profile_init: sl@0: * @prof: the OilProfile structure sl@0: * sl@0: * Initializes a profiling structure. sl@0: */ sl@0: #ifdef __SYMBIAN32__ sl@0: EXPORT_C sl@0: #endif sl@0: void sl@0: oil_profile_init (OilProfile *prof) sl@0: { sl@0: memset(prof, 0, sizeof(OilProfile)); sl@0: sl@0: prof->min = -1; sl@0: sl@0: } sl@0: sl@0: /** sl@0: * oil_profile_stop_handle: sl@0: * @prof: the OilProfile structure sl@0: * sl@0: * Handles post-processing of a single profiling run. sl@0: * sl@0: * FIXME: need more info sl@0: */ sl@0: #ifdef __SYMBIAN32__ sl@0: EXPORT_C sl@0: #endif sl@0: void sl@0: oil_profile_stop_handle (OilProfile *prof) sl@0: { sl@0: int i; sl@0: sl@0: prof->last = prof->stop - prof->start; sl@0: sl@0: prof->total += prof->last; sl@0: prof->n++; sl@0: sl@0: if (prof->last < prof->min) prof->min = prof->last; sl@0: sl@0: for(i=0;ihist_n;i++) { sl@0: if (prof->last == prof->hist_time[i]) { sl@0: prof->hist_count[i]++; sl@0: break; sl@0: } sl@0: } sl@0: if (i == prof->hist_n && prof->hist_n < OIL_PROFILE_HIST_LENGTH) { sl@0: prof->hist_time[prof->hist_n] = prof->last; sl@0: prof->hist_count[prof->hist_n] = 1; sl@0: prof->hist_n++; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * oil_profile_get_ave_std: sl@0: * @prof: the OilProfile structure sl@0: * @ave_p: pointer to average sl@0: * @std_p: pointer to standard deviation sl@0: * sl@0: * Calculates the average and standard deviation of a number of sl@0: * profiling runs, and places the results in the locations sl@0: * provided by @ave_p and @std_p. Either @ave_p and @std_p may sl@0: * be NULL, in which case the values will not be written. sl@0: */ sl@0: #ifdef __SYMBIAN32__ sl@0: EXPORT_C sl@0: #endif sl@0: void sl@0: oil_profile_get_ave_std (OilProfile *prof, double *ave_p, double *std_p) sl@0: { sl@0: double ave; sl@0: double std; sl@0: int max_i; sl@0: double off; sl@0: double s; sl@0: double s2; sl@0: int i; sl@0: int n; sl@0: double x; sl@0: sl@0: do { sl@0: s = s2 = 0; sl@0: n = 0; sl@0: max_i = -1; sl@0: for(i=0;i<10;i++){ sl@0: x = prof->hist_time[i]; sl@0: s2 += x * x * prof->hist_count[i]; sl@0: s += x * prof->hist_count[i]; sl@0: n += prof->hist_count[i]; sl@0: if (prof->hist_count[i] > 0) { sl@0: if (max_i == -1 || prof->hist_time[i] > prof->hist_time[max_i]) { sl@0: max_i = i; sl@0: } sl@0: } sl@0: } sl@0: sl@0: ave = s / n; sl@0: std = sqrt (s2 - s * s / n + n*n) / (n-1); sl@0: off = (prof->hist_time[max_i] - ave)/std; sl@0: sl@0: if (off > 4.0) { sl@0: prof->hist_count[max_i] = 0; sl@0: } sl@0: } while (off > 4.0); sl@0: sl@0: if (ave_p) *ave_p = ave; sl@0: if (std_p) *std_p = std; sl@0: } sl@0: sl@0: unsigned long (*_oil_profile_stamp)(void); sl@0: sl@0: /** sl@0: * oil_profile_stamp: sl@0: * sl@0: * Creates a timestamp based on a CPU-specific high-frequency sl@0: * counter, if available. sl@0: * sl@0: * Returns: a timestamp sl@0: */ sl@0: #ifdef __SYMBIAN32__ sl@0: EXPORT_C sl@0: #endif sl@0: unsigned long sl@0: oil_profile_stamp (void) sl@0: { sl@0: return _oil_profile_stamp(); sl@0: } sl@0: