source: trunk/src/opengl/glide/swlibs/fxmisc/tsc.c

Last change on this file was 2887, checked in by sandervl, 26 years ago

Created swlibs dir

File size: 2.6 KB
Line 
1/*
2** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY
3** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
4** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX
5** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE
6** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com).
7** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
8** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A
9** FULL TEXT OF THE NON-WARRANTY PROVISIONS.
10**
11** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
12** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
13** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013,
14** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
15** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
16** THE UNITED STATES.
17**
18** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
19*/
20#include <stdlib.h>
21#include <stdio.h>
22#include <string.h>
23
24#include <3dfx.h>
25#include <tsc.h>
26
27static FxU32 tsc_histogram[TSC_MAX_CLOCKS];
28
29FxU32 tsc_begin, tsc_end;
30static FxU32 tsc_bias;
31
32void
33tscInit( void ) {
34 FxU32 test = 100;
35 int i;
36
37
38 for ( i = 0; i < 10; i++ )
39 {
40 tscBegin();
41 tsc_end = tscReadTSC();
42 if ( ( tsc_end - tsc_begin ) < test )
43 test = tsc_end - tsc_begin;
44 }
45 tsc_bias = test;
46}
47
48/*
49** timing routines
50*/
51void tscStoreDelta( void )
52{
53 FxU32 value = tsc_end - tsc_begin;
54
55 if ( value < TSC_MAX_CLOCKS && value > tsc_bias )
56 tsc_histogram[value-tsc_bias]++;
57}
58
59void tscPrintHistogram( void )
60{
61 float total = 0.0F;
62 int i;
63
64 for ( i = 0; i < TSC_MAX_CLOCKS; i++ )
65 total += tsc_histogram[i];
66
67 for ( i = 0; i < TSC_MAX_CLOCKS; i++ )
68 {
69 float percent = ( tsc_histogram[i] * 100.0F ) / total;
70
71 if ( percent > 1.0 )
72 {
73 printf( "%04d: %3.2f\n", i, percent );
74 }
75 }
76}
77
78FxU32
79tscGetMostFrequent(void) {
80 float total = 0.0F;
81 int i;
82 float
83 maxPercent = 0.f;
84 FxU32
85 mostFrequentClockCount;
86
87 for ( i = 0; i < TSC_MAX_CLOCKS; i++ )
88 total += tsc_histogram[i];
89
90 for ( i = 0; i < TSC_MAX_CLOCKS; i++ ) {
91 float percent = ( tsc_histogram[i] * 100.0F ) / total;
92
93 if ( percent > maxPercent ) {
94 maxPercent = percent;
95 mostFrequentClockCount = i;
96 }
97 }
98 return mostFrequentClockCount;
99}
100
101FxU32 *tscGetHistogram( void )
102{
103 return tsc_histogram;
104}
105
106void tscResetHistogram(void)
107{
108 int i;
109
110 for (i = 0; i < TSC_MAX_CLOCKS; i++)
111 tsc_histogram[i] = 0;
112}
113
Note: See TracBrowser for help on using the repository browser.