67static double TotalFrameTimes;
68static bool ProfileCollecting;
71static unsigned ProfileStringCount;
215 for (i=0;i<
recursion;++i) {
string+=
"\t"; }
218 file->
Write(
string.Peek_Buffer(),
string.Get_Length());
269 if ( child->
Name == name ) {
362bool WWProfileManager::IsProfileEnabled=
false;
366int WWProfileManager::FrameCounter = 0;
367__int64 WWProfileManager::ResetTime = 0;
369static unsigned int ThreadID =
static_cast<unsigned int>(-1);
392 if (::GetCurrentThreadId() != ThreadID) {
397 if (name != CurrentNode->Get_Name()) {
398 CurrentNode = CurrentNode->Get_Sub_Node( name );
406 if (::GetCurrentThreadId() != ThreadID) {
410 if (name != CurrentRootNode->Get_Name()) {
411 CurrentRootNode = CurrentRootNode->Get_Sub_Node( name );
414 CurrentRootNode->Call();
432 if (::GetCurrentThreadId() != ThreadID) {
438 if (CurrentNode->Return()) {
439 CurrentNode = CurrentNode->Get_Parent();
445 if (::GetCurrentThreadId() != ThreadID) {
451 if (CurrentRootNode->Return()) {
452 CurrentRootNode = CurrentRootNode->Get_Parent();
474 ThreadID = ::GetCurrentThreadId();
496 if (ProfileCollecting) {
498 TotalFrameTimes+=time;
502 ProfileCollectVector.Add(new_root);
572 ProfileCollecting=
true;
579 if (filename && ProfileCollectVector.Count()!=0) {
588 float avg_frame_time=TotalFrameTimes/float(ProfileCollectVector.Count());
590 "Total frames: %d, average frame time: %fms\r\n"
591 "All frames taking more than twice the average frame time are marked with keyword SPIKE.\r\n\r\n",
592 ProfileCollectVector.Count(),avg_frame_time*1000.0f);
601 if (name[i]==
'\t') name[i]=
'-';
602 if (name[i]==
' ') name[i]=
'_';
603 if (name[i]==
',') name[i]=
'.';
604 if (name[i]==
';') name[i]=
':';
613 for (i=0;i<ProfileCollectVector.Count();++i) {
614 float frame_time=ProfileCollectVector[i]->Get_Total_Time();
615 str.
Format(
"FRAME: %d %2.2f %s ",i,frame_time*1000.0f,frame_time>avg_frame_time*2.0f ?
"SPIKE" :
"OK");
616 ProfileCollectVector[i]->Add_To_String_Compact(str,0);
629 for (i=0;i<ProfileCollectVector.Count();++i) {
630 delete ProfileCollectVector[i];
631 ProfileCollectVector[i]=0;
633 ProfileCollectVector.Delete_All();
634 ProfileCollecting=
false;
637static unsigned Read_Line(
char* memory,
unsigned pos,
unsigned maxpos)
640 if (memory[pos++]==
'\n') {
647static unsigned Seek_Char(
char* memory,
unsigned pos,
unsigned maxpos,
char c)
650 if (memory[pos++]==c) {
657unsigned Read_Int(
char* memory,
unsigned pos,
unsigned maxpos,
unsigned& number)
661 char c=memory[pos++];
671unsigned Read_String(
char* memory,
unsigned pos,
unsigned maxpos,
char*
string)
675 char c=memory[pos++];
685unsigned Read_Float(
char* memory,
unsigned pos,
unsigned maxpos,
float& fnumber)
690 char c=memory[pos++];
699 char c=memory[pos++];
702 ftfloat+=float(c-
'0');
712 ftfloat+=float(ftint);
718static unsigned Read_ID(
char* memory,
unsigned pos,
unsigned maxpos,
StringClass&
string,
unsigned&
id)
725 pos=
Read_Int(memory,pos,maxpos,idnumber);
732 return Read_Line(memory,pos,maxpos);
737 char statusstring[256];
738 unsigned framenumber=0;
747 pos=
Read_Int(memory,pos,maxpos,framenumber);
757 unsigned lineend=Read_Line(memory,pos,maxpos);
758 while (pos<lineend) {
760 if (isdigit(memory[pos])) {
768 pos=
Read_Int(memory,pos,maxpos,count);
774 id_hash.
Get(
id,name);
778 parent->Set_Child(new_node);
783 if (root==
NULL) root=new_node;
785 else if (memory[pos]==
'{') {
789 else if (memory[pos]==
'}') {
791 parent=parent->Get_Parent();
800 return Read_Line(memory,pos,maxpos);
821 unsigned size=file->
Size();
822 char* memory=
new char[size];
823 file->
Read(memory,size);
829 if (tmp[0]==
'I' && tmp[1]==
'D' && tmp[2]==
':') {
832 pos=Read_ID(memory,pos,size,
string,
id);
833 string_hash.
Insert(
string,
id);
834 id_hash.
Insert(
id,
string);
836 else if (tmp[0]==
'F' && tmp[1]==
'R' && tmp[2]==
'A' && tmp[3]==
'M' && tmp[4]==
'E' && tmp[5]==
':') {
838 pos=Read_Frame(memory,pos,size,node,id_hash);
844 pos=Read_Line(memory,pos,size);
852 for (i=0;i<count;++i) {
1011 WWDEBUG_SAY((
"*** WWTIMEIT *** %s took %1.9f\n", Name, time ));
1054 for (
unsigned i=0;i<
TabCount;++i) tmp+=
"\t";
1063 for (
unsigned i=0;i<
TabCount;++i) tmp+=
"\t";
1069 WWRELEASE_SAY((
"IN TOTAL %s took %d.%3.3d s, did %d memory allocations of %d bytes\n",
1085 for (
unsigned i=0;i<
TabCount;++i) tmp+=
"\t";
1086 WWRELEASE_SAY((
"%s%s took %d.%3.3d s, did %d memory allocations of %d bytes\n",
static double Get_Inv_Processor_Ticks_Per_Second()
static FastAllocatorGeneral * Get_Allocator()
unsigned Get_Total_Allocated_Size()
unsigned Get_Total_Allocation_Count()
virtual bool Is_Available(int forced=false)=0
virtual int Read(void *buffer, int size)=0
virtual void Close(void)=0
virtual int Open(char const *filename, int rights=READ)=0
virtual int Write(void const *buffer, int size)=0
ValueType Get(const KeyType &s) const
void Insert(const KeyType &s, const ValueType &d)
const KeyType & Peek_Key()
bool Add(T const &object, int new_size_hint=0)
int _cdecl Format(const TCHAR *format,...)
int Get_Length(void) const
TCHAR * Peek_Buffer(void)
WWMeasureItClass(float *p_result)
WWProfileHierachyInfoClass * Sibling
void Set_Sibling(WWProfileHierachyInfoClass *node)
WWProfileHierachyInfoClass * Child
~WWProfileHierachyInfoClass(void)
WWProfileHierachyInfoClass(const char *name, WWProfileHierachyInfoClass *parent)
void Set_Total_Time(float time)
void Set_Total_Calls(int calls)
WWProfileHierachyInfoClass * Parent
WWProfileHierachyNodeClass * Sibling
~WWProfileHierachyNodeClass(void)
void Add_To_String_Compact(StringClass &string, int recursion)
WWProfileHierachyNodeClass * Get_Sub_Node(const char *name)
WWProfileHierachyNodeClass(const char *name, WWProfileHierachyNodeClass *parent)
WWProfileHierachyNodeClass * Child
void Write_To_File(FileClass *file, int recursion)
void Set_Total_Calls(int calls)
void Set_Total_Time(float time)
WWProfileHierachyNodeClass * Parent
WWProfileHierachyNodeClass * Clone_Hierarchy(WWProfileHierachyNodeClass *parent)
WWProfileHierachyNodeClass * CurrentNode
WWProfileInOrderIterator(void)
WWProfileIterator(WWProfileHierachyNodeClass *start)
WWProfileHierachyNodeClass * CurrentParent
WWProfileHierachyNodeClass * CurrentChild
static WWProfileIterator * Get_Iterator(void)
static void Release_In_Order_Iterator(WWProfileInOrderIterator *iterator)
static WWProfileInOrderIterator * Get_In_Order_Iterator(void)
static void Begin_Collecting()
static void Stop_Profile(void)
static void Start_Profile(const char *name)
static void Release_Iterator(WWProfileIterator *iterator)
static void Increment_Frame_Counter(void)
static void Load_Profile_Log(const char *filename, WWProfileHierachyInfoClass **&array, unsigned &count)
static void End_Collecting(const char *filename)
static void Start_Root_Profile(const char *name)
friend class WWProfileInOrderIterator
static void Stop_Root_Profile(void)
static float Get_Time_Since_Reset(void)
WWTimeItClass(const char *name)
RawFileFactoryClass * _TheWritingFileFactory
FileFactoryClass * _TheFileFactory
void recursion(int level)
void Log_Intermediate(const char *text)
unsigned IntermediateTimeStart
int IntermediateAllocSizeStart
WWMemoryAndTimeLog(const char *name)
int IntermediateAllocCountStart
WWINLINE double WWProfile_Get_Inv_Processor_Ticks_Per_Second(void)
unsigned Read_String(char *memory, unsigned pos, unsigned maxpos, char *string)
void WWProfile_Get_Ticks(_int64 *ticks)
unsigned WWProfile_Get_System_Time()
unsigned Read_Float(char *memory, unsigned pos, unsigned maxpos, float &fnumber)
unsigned Read_Int(char *memory, unsigned pos, unsigned maxpos, unsigned &number)
unsigned WWProfile_Get_System_Time()