os/ossrv/genericopenlibs/liboil/src/liboilprofile.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
 * LIBOIL - Library of Optimized Inner Loops
sl@0
     3
 * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
sl@0
     4
 * All rights reserved.
sl@0
     5
 *
sl@0
     6
 * Redistribution and use in source and binary forms, with or without
sl@0
     7
 * modification, are permitted provided that the following conditions
sl@0
     8
 * are met:
sl@0
     9
 * 1. Redistributions of source code must retain the above copyright
sl@0
    10
 *    notice, this list of conditions and the following disclaimer.
sl@0
    11
 * 2. Redistributions in binary form must reproduce the above copyright
sl@0
    12
 *    notice, this list of conditions and the following disclaimer in the
sl@0
    13
 *    documentation and/or other materials provided with the distribution.
sl@0
    14
 * 
sl@0
    15
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
sl@0
    16
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
sl@0
    17
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
sl@0
    18
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
sl@0
    19
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
sl@0
    20
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
sl@0
    21
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
sl@0
    22
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
sl@0
    23
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
sl@0
    24
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
sl@0
    25
 * POSSIBILITY OF SUCH DAMAGE.
sl@0
    26
 */
sl@0
    27
//Portions Copyright (c)  2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
sl@0
    28
sl@0
    29
#ifdef HAVE_CONFIG_H
sl@0
    30
#include <config.h>
sl@0
    31
#endif
sl@0
    32
sl@0
    33
#include <liboil/liboilprofile.h>
sl@0
    34
#include <liboil/liboildebug.h>
sl@0
    35
sl@0
    36
#ifdef HAVE_SYS_TIME_H
sl@0
    37
#include <sys/time.h>
sl@0
    38
#endif
sl@0
    39
#include <time.h>
sl@0
    40
#include <string.h>
sl@0
    41
#include <math.h>
sl@0
    42
sl@0
    43
#ifdef __SYMBIAN32__
sl@0
    44
#ifdef __ARMCC__
sl@0
    45
#pragma diag_remark 68
sl@0
    46
#endif//__ARMCC__
sl@0
    47
#endif//__SYMBIAN32__
sl@0
    48
sl@0
    49
/**
sl@0
    50
 * SECTION:liboilprofile
sl@0
    51
 * @title:OilProfile
sl@0
    52
 * @short_description:
sl@0
    53
 * Measuring the length of time needed to execute Liboil functions.
sl@0
    54
 *
sl@0
    55
 */
sl@0
    56
sl@0
    57
/**
sl@0
    58
 * oil_profile_init:
sl@0
    59
 * @prof: the OilProfile structure
sl@0
    60
 *
sl@0
    61
 * Initializes a profiling structure.
sl@0
    62
 */
sl@0
    63
#ifdef __SYMBIAN32__
sl@0
    64
EXPORT_C
sl@0
    65
#endif
sl@0
    66
void
sl@0
    67
oil_profile_init (OilProfile *prof)
sl@0
    68
{
sl@0
    69
  memset(prof, 0, sizeof(OilProfile));
sl@0
    70
sl@0
    71
  prof->min = -1;
sl@0
    72
sl@0
    73
}
sl@0
    74
sl@0
    75
/**
sl@0
    76
 * oil_profile_stop_handle:
sl@0
    77
 * @prof: the OilProfile structure
sl@0
    78
 *
sl@0
    79
 * Handles post-processing of a single profiling run.
sl@0
    80
 *
sl@0
    81
 * FIXME: need more info
sl@0
    82
 */
sl@0
    83
 #ifdef __SYMBIAN32__
sl@0
    84
EXPORT_C
sl@0
    85
#endif
sl@0
    86
void
sl@0
    87
oil_profile_stop_handle (OilProfile *prof)
sl@0
    88
{
sl@0
    89
  int i;
sl@0
    90
sl@0
    91
  prof->last = prof->stop - prof->start;
sl@0
    92
sl@0
    93
  prof->total += prof->last;
sl@0
    94
  prof->n++;
sl@0
    95
sl@0
    96
  if (prof->last < prof->min) prof->min = prof->last;
sl@0
    97
  
sl@0
    98
  for(i=0;i<prof->hist_n;i++) {
sl@0
    99
    if (prof->last == prof->hist_time[i]) {
sl@0
   100
      prof->hist_count[i]++;
sl@0
   101
      break;
sl@0
   102
    }
sl@0
   103
  }
sl@0
   104
  if (i == prof->hist_n && prof->hist_n < OIL_PROFILE_HIST_LENGTH) {
sl@0
   105
    prof->hist_time[prof->hist_n] = prof->last;
sl@0
   106
    prof->hist_count[prof->hist_n] = 1;
sl@0
   107
    prof->hist_n++;
sl@0
   108
  }
sl@0
   109
}
sl@0
   110
sl@0
   111
/**
sl@0
   112
 * oil_profile_get_ave_std:
sl@0
   113
 * @prof: the OilProfile structure
sl@0
   114
 * @ave_p: pointer to average
sl@0
   115
 * @std_p: pointer to standard deviation
sl@0
   116
 *
sl@0
   117
 * Calculates the average and standard deviation of a number of
sl@0
   118
 * profiling runs, and places the results in the locations
sl@0
   119
 * provided by @ave_p and @std_p.  Either @ave_p and @std_p may
sl@0
   120
 * be NULL, in which case the values will not be written.
sl@0
   121
 */
sl@0
   122
 #ifdef __SYMBIAN32__
sl@0
   123
EXPORT_C
sl@0
   124
#endif
sl@0
   125
void
sl@0
   126
oil_profile_get_ave_std (OilProfile *prof, double *ave_p, double *std_p)
sl@0
   127
{
sl@0
   128
  double ave;
sl@0
   129
  double std;
sl@0
   130
  int max_i;
sl@0
   131
  double off;
sl@0
   132
  double s;
sl@0
   133
  double s2;
sl@0
   134
  int i;
sl@0
   135
  int n;
sl@0
   136
  double x;
sl@0
   137
sl@0
   138
  do {
sl@0
   139
    s = s2 = 0;
sl@0
   140
    n = 0;
sl@0
   141
    max_i = -1;
sl@0
   142
    for(i=0;i<10;i++){
sl@0
   143
      x = prof->hist_time[i];
sl@0
   144
      s2 += x * x * prof->hist_count[i];
sl@0
   145
      s += x * prof->hist_count[i];
sl@0
   146
      n += prof->hist_count[i];
sl@0
   147
      if (prof->hist_count[i] > 0) {
sl@0
   148
        if (max_i == -1 || prof->hist_time[i] > prof->hist_time[max_i]) {
sl@0
   149
          max_i = i;
sl@0
   150
        }
sl@0
   151
      }
sl@0
   152
    }
sl@0
   153
sl@0
   154
    ave = s / n;
sl@0
   155
    std = sqrt (s2 - s * s / n + n*n) / (n-1);
sl@0
   156
    off = (prof->hist_time[max_i] - ave)/std;
sl@0
   157
sl@0
   158
    if (off > 4.0) {
sl@0
   159
      prof->hist_count[max_i] = 0;
sl@0
   160
    }
sl@0
   161
  } while (off > 4.0);
sl@0
   162
sl@0
   163
  if (ave_p) *ave_p = ave;
sl@0
   164
  if (std_p) *std_p = std;
sl@0
   165
}
sl@0
   166
sl@0
   167
unsigned long (*_oil_profile_stamp)(void);
sl@0
   168
sl@0
   169
/**
sl@0
   170
 * oil_profile_stamp:
sl@0
   171
 *
sl@0
   172
 * Creates a timestamp based on a CPU-specific high-frequency
sl@0
   173
 * counter, if available.
sl@0
   174
 *
sl@0
   175
 * Returns: a timestamp
sl@0
   176
 */
sl@0
   177
 #ifdef __SYMBIAN32__
sl@0
   178
EXPORT_C
sl@0
   179
#endif
sl@0
   180
unsigned long
sl@0
   181
oil_profile_stamp (void)
sl@0
   182
{
sl@0
   183
  return _oil_profile_stamp();
sl@0
   184
}
sl@0
   185