00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "src/common/shared.hpp"
00019 #include "src/common/qsort.hpp"
00020 #include "src/memory/memset.hpp"
00021 #include "src/memory/align.hpp"
00022 #include "src/memory/heap.hpp"
00023 #include "src/common/profiler.hpp"
00024
00028 namespace Debug {
00029 namespace Profiler {
00030
00031 #ifdef PROFILER_ENABLE
00032 uint32 ProfilerCount= 0;
00033 struct profiling_s ProfilerBuf[MAX_PROFILER];
00034
00035 inline uint32 strlen(char *ch)
00036 {
00037 char *c2=ch;
00038 while ( *c2 ) c2++;
00039 return (uint32)(c2-ch);
00040 }
00041
00042
00043 int voidnull()
00044 { _Pf("voidnull");
00045 preturn(42); }
00046
00047 void stats(bool SortBySlowest)
00048 {_Pf("Profiler::Stats");
00049 voidnull();
00050 uint32 i;
00051 struct profiling_s *pf,*pBase;
00052 uint32 SavedProfilerCount;
00053
00054
00055 SavedProfilerCount= ProfilerCount;
00056 if (SortBySlowest)
00057 {
00058
00059 pBase= pf=(struct profiling_s*) Memory::Heap::heap0.malloc(SavedProfilerCount*sizeof(struct profiling_s), NO_ALIGN, "ProfilerBuffer", NULL);
00060 memmove(pBase, ProfilerBuf, SavedProfilerCount*sizeof(struct profiling_s));
00061
00062 qsort(pBase, SavedProfilerCount, sizeof(struct profiling_s), &ProfilingCompar, NULL);
00063 } else pf= ProfilerBuf;
00064
00065 cout(const_cast<char*>("\n>>>>>>>>\n\tDebuf::Profiler::stats()\n"));
00066 cout(const_cast<char*>("Name\t\t\t Time\t\t\t\t Calls\t\t Active\t\tAvrgCallTime\n"));
00067 for (i=0;i<SavedProfilerCount;i++)
00068 {
00069 uint32 n=0;
00070 if (pf->Name) { n=strlen(pf->Name); cout(pf->Name); }
00071 else cout(const_cast<char*>("\t\t"));
00072 n= MIN(19,n);
00073 while (19 - (n++)) cout(const_cast<char*>(" "));
00074 if (pf->Time>>32)
00075 coutnum(active_console, (uint32)(pf->Time>>32), 16, 0x10000000, 'A', '-');
00076 else cout(const_cast<char*>("--------"));
00077
00078 coutnum(active_console, (uint32)pf->Time&0xffffffff, 16, 0x10000000, 'A', '-');
00079
00080 cout(const_cast<char*>("\t "));
00081 coutnum(active_console, pf->Calls, 16, 0x10000000, 'A', '-');
00082
00083 cout(const_cast<char*>("\t "));
00084 coutnum(active_console, pf->Active, 16, 0x10000000, 'A', '-');
00085
00086 cout(const_cast<char*>("\t"));
00087 if (pf->Calls==0) cout(const_cast<char*>("---------Unkn.--"));
00088 else {
00089 if ((uint32)((pf->Time/pf->Calls)>>32))
00090 coutnum(active_console, (uint32)((pf->Time/pf->Calls)>>32), 16, 0x10000000, 'A', '-');
00091 else cout(const_cast<char*>("--------"));
00092
00093 coutnum(active_console,(uint32)(pf->Time/pf->Calls)&0xffffffff, 16, 0x10000000, 'A', '-'); }
00094
00095 cout(const_cast<char*>("\n"));
00096 pf++;
00097 }
00098
00099 if (pBase)
00100 Memory::Heap::heap0.free(pBase);
00101 Preturn();
00102 }
00103
00104
00105 int ProfilingCompar(const void *A,const void *B)
00106 {
00107 struct profiling_s *a=(struct profiling_s*)A ,*b=(struct profiling_s*)B;
00108 uint64 a1, b1;
00109
00110 if (a->Calls == 0) return -1;
00111 if (b->Calls == 0) return 1;
00112
00113 a1= a->Time/a->Calls;b1= b->Time/b->Calls;
00114 if (a1>b1) return 1;
00115 if (a1==b1) return 0;
00116 return -1;
00117 }
00118
00119 #endif
00120
00121 };
00122 };
00123
00124
00125
00126
00127
00128
00129