00001 /************************************************************************** 00002 *** 00003 *** Copyright (c) 1995-2000 Regents of the University of California, 00004 *** Andrew E. Caldwell, Andrew B. Kahng and Igor L. Markov 00005 *** Copyright (c) 2000-2004 Regents of the University of Michigan, 00006 *** Saurabh N. Adya, Jarrod A. Roy and Igor L. Markov 00007 *** 00008 *** Contact author(s): abk@cs.ucsd.edu, imarkov@umich.edu 00009 *** Original Affiliation: UCLA, Computer Science Department, 00010 *** Los Angeles, CA 90095-1596 USA 00011 *** 00012 *** Permission is hereby granted, free of charge, to any person obtaining 00013 *** a copy of this software and associated documentation files (the 00014 *** "Software"), to deal in the Software without restriction, including 00015 *** without limitation 00016 *** the rights to use, copy, modify, merge, publish, distribute, sublicense, 00017 *** and/or sell copies of the Software, and to permit persons to whom the 00018 *** Software is furnished to do so, subject to the following conditions: 00019 *** 00020 *** The above copyright notice and this permission notice shall be included 00021 *** in all copies or substantial portions of the Software. 00022 *** 00023 *** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00024 *** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 00025 *** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00026 *** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 00027 *** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT 00028 *** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 00029 *** THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00030 *** 00031 *** 00032 ***************************************************************************/ 00033 00034 00035 00036 00037 00038 00039 00040 00041 #ifdef _MSC_VER 00042 #pragma warning(disable:4786) 00043 #endif 00044 00045 #include <vector> 00046 #include <list> 00047 #include "abktimer.h" 00048 #include "abkrand.h" 00049 #include "abkcpunorm.h" 00050 #include <stdio.h> 00051 00052 00053 static const double oneUpdateTakesXUltra1sec=0.41; 00054 static const unsigned updateSize=500000; 00055 00056 unsigned CPUNormalizer::_numUpdates=0; 00057 double CPUNormalizer::_totTime =0.0; 00058 char CPUNormalizer::_buffer[80]; 00059 00060 double CPUNormalizer::getNormalizingFactor() const 00061 { return (_numUpdates * oneUpdateTakesXUltra1sec) / _totTime; } 00062 00063 CPUNormalizer::operator const char*() const 00064 { 00065 if (_totTime<0) strcpy(_buffer," CPU time normalizer failed \n"); 00066 else 00067 sprintf(_buffer, 00068 "# Run-time conversion to Ultra-1 @143.5/71.5MHz, SunProCC4.2/-O5 : %f \n", 00069 getNormalizingFactor()); 00070 return _buffer; 00071 } 00072 00073 void CPUNormalizer::update() 00074 { 00075 Timer tm; 00076 if (_numUpdates>10000) { _numUpdates=0; _totTime=0.0; } 00077 00078 unsigned *sample1, *sample2, *sample3; // *sample4, *sample5; 00079 sample1=new unsigned[updateSize]; 00080 sample2=new unsigned[updateSize]; 00081 sample3=new unsigned[updateSize]; 00082 //sample4=new unsigned[updateSize]; 00083 //sample5=new unsigned[updateSize]; 00084 00085 RandomRawUnsigned ru("CPUNormalizer::update(),ru",999); 00086 for(unsigned k=0; k!=updateSize/3; k++) 00087 { 00088 unsigned addr=ru%updateSize; 00089 sample1[addr]=k / 3; 00090 sample2[addr]=k*k; 00091 sample3[addr]=0; 00092 // sample4[addr]=0; 00093 // sample5[addr]=0; 00094 } 00095 delete[] sample1; 00096 delete[] sample2; 00097 delete[] sample3; 00098 //delete[] sample4; 00099 //delete[] sample5; 00100 00101 /*list<unsigned> sampleList(sampleVec.size()); 00102 copy(sampleVec.begin(),sampleVec.end(),sampleList.begin()); 00103 */ 00104 tm.stop(); 00105 double newTime=tm.getUserTime(); 00106 if (newTime>0) _totTime+=newTime; 00107 else _totTime = -1.0; // failed 00108 _numUpdates++; 00109 //cout << "CPU sampling took : " << tm << endl; 00110 } 00111