os/ossrv/genericopenlibs/liboil/src/liboilprofile.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/liboil/src/liboilprofile.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,185 @@
     1.4 +/*
     1.5 + * LIBOIL - Library of Optimized Inner Loops
     1.6 + * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
     1.7 + * All rights reserved.
     1.8 + *
     1.9 + * Redistribution and use in source and binary forms, with or without
    1.10 + * modification, are permitted provided that the following conditions
    1.11 + * are met:
    1.12 + * 1. Redistributions of source code must retain the above copyright
    1.13 + *    notice, this list of conditions and the following disclaimer.
    1.14 + * 2. Redistributions in binary form must reproduce the above copyright
    1.15 + *    notice, this list of conditions and the following disclaimer in the
    1.16 + *    documentation and/or other materials provided with the distribution.
    1.17 + * 
    1.18 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    1.19 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    1.20 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.21 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
    1.22 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    1.23 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    1.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.25 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    1.26 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
    1.27 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    1.28 + * POSSIBILITY OF SUCH DAMAGE.
    1.29 + */
    1.30 +//Portions Copyright (c)  2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
    1.31 +
    1.32 +#ifdef HAVE_CONFIG_H
    1.33 +#include <config.h>
    1.34 +#endif
    1.35 +
    1.36 +#include <liboil/liboilprofile.h>
    1.37 +#include <liboil/liboildebug.h>
    1.38 +
    1.39 +#ifdef HAVE_SYS_TIME_H
    1.40 +#include <sys/time.h>
    1.41 +#endif
    1.42 +#include <time.h>
    1.43 +#include <string.h>
    1.44 +#include <math.h>
    1.45 +
    1.46 +#ifdef __SYMBIAN32__
    1.47 +#ifdef __ARMCC__
    1.48 +#pragma diag_remark 68
    1.49 +#endif//__ARMCC__
    1.50 +#endif//__SYMBIAN32__
    1.51 +
    1.52 +/**
    1.53 + * SECTION:liboilprofile
    1.54 + * @title:OilProfile
    1.55 + * @short_description:
    1.56 + * Measuring the length of time needed to execute Liboil functions.
    1.57 + *
    1.58 + */
    1.59 +
    1.60 +/**
    1.61 + * oil_profile_init:
    1.62 + * @prof: the OilProfile structure
    1.63 + *
    1.64 + * Initializes a profiling structure.
    1.65 + */
    1.66 +#ifdef __SYMBIAN32__
    1.67 +EXPORT_C
    1.68 +#endif
    1.69 +void
    1.70 +oil_profile_init (OilProfile *prof)
    1.71 +{
    1.72 +  memset(prof, 0, sizeof(OilProfile));
    1.73 +
    1.74 +  prof->min = -1;
    1.75 +
    1.76 +}
    1.77 +
    1.78 +/**
    1.79 + * oil_profile_stop_handle:
    1.80 + * @prof: the OilProfile structure
    1.81 + *
    1.82 + * Handles post-processing of a single profiling run.
    1.83 + *
    1.84 + * FIXME: need more info
    1.85 + */
    1.86 + #ifdef __SYMBIAN32__
    1.87 +EXPORT_C
    1.88 +#endif
    1.89 +void
    1.90 +oil_profile_stop_handle (OilProfile *prof)
    1.91 +{
    1.92 +  int i;
    1.93 +
    1.94 +  prof->last = prof->stop - prof->start;
    1.95 +
    1.96 +  prof->total += prof->last;
    1.97 +  prof->n++;
    1.98 +
    1.99 +  if (prof->last < prof->min) prof->min = prof->last;
   1.100 +  
   1.101 +  for(i=0;i<prof->hist_n;i++) {
   1.102 +    if (prof->last == prof->hist_time[i]) {
   1.103 +      prof->hist_count[i]++;
   1.104 +      break;
   1.105 +    }
   1.106 +  }
   1.107 +  if (i == prof->hist_n && prof->hist_n < OIL_PROFILE_HIST_LENGTH) {
   1.108 +    prof->hist_time[prof->hist_n] = prof->last;
   1.109 +    prof->hist_count[prof->hist_n] = 1;
   1.110 +    prof->hist_n++;
   1.111 +  }
   1.112 +}
   1.113 +
   1.114 +/**
   1.115 + * oil_profile_get_ave_std:
   1.116 + * @prof: the OilProfile structure
   1.117 + * @ave_p: pointer to average
   1.118 + * @std_p: pointer to standard deviation
   1.119 + *
   1.120 + * Calculates the average and standard deviation of a number of
   1.121 + * profiling runs, and places the results in the locations
   1.122 + * provided by @ave_p and @std_p.  Either @ave_p and @std_p may
   1.123 + * be NULL, in which case the values will not be written.
   1.124 + */
   1.125 + #ifdef __SYMBIAN32__
   1.126 +EXPORT_C
   1.127 +#endif
   1.128 +void
   1.129 +oil_profile_get_ave_std (OilProfile *prof, double *ave_p, double *std_p)
   1.130 +{
   1.131 +  double ave;
   1.132 +  double std;
   1.133 +  int max_i;
   1.134 +  double off;
   1.135 +  double s;
   1.136 +  double s2;
   1.137 +  int i;
   1.138 +  int n;
   1.139 +  double x;
   1.140 +
   1.141 +  do {
   1.142 +    s = s2 = 0;
   1.143 +    n = 0;
   1.144 +    max_i = -1;
   1.145 +    for(i=0;i<10;i++){
   1.146 +      x = prof->hist_time[i];
   1.147 +      s2 += x * x * prof->hist_count[i];
   1.148 +      s += x * prof->hist_count[i];
   1.149 +      n += prof->hist_count[i];
   1.150 +      if (prof->hist_count[i] > 0) {
   1.151 +        if (max_i == -1 || prof->hist_time[i] > prof->hist_time[max_i]) {
   1.152 +          max_i = i;
   1.153 +        }
   1.154 +      }
   1.155 +    }
   1.156 +
   1.157 +    ave = s / n;
   1.158 +    std = sqrt (s2 - s * s / n + n*n) / (n-1);
   1.159 +    off = (prof->hist_time[max_i] - ave)/std;
   1.160 +
   1.161 +    if (off > 4.0) {
   1.162 +      prof->hist_count[max_i] = 0;
   1.163 +    }
   1.164 +  } while (off > 4.0);
   1.165 +
   1.166 +  if (ave_p) *ave_p = ave;
   1.167 +  if (std_p) *std_p = std;
   1.168 +}
   1.169 +
   1.170 +unsigned long (*_oil_profile_stamp)(void);
   1.171 +
   1.172 +/**
   1.173 + * oil_profile_stamp:
   1.174 + *
   1.175 + * Creates a timestamp based on a CPU-specific high-frequency
   1.176 + * counter, if available.
   1.177 + *
   1.178 + * Returns: a timestamp
   1.179 + */
   1.180 + #ifdef __SYMBIAN32__
   1.181 +EXPORT_C
   1.182 +#endif
   1.183 +unsigned long
   1.184 +oil_profile_stamp (void)
   1.185 +{
   1.186 +  return _oil_profile_stamp();
   1.187 +}
   1.188 +