It is currently Mon Nov 20, 2017 7:44 pm

All times are UTC - 5 hours




 Page 1 of 1 [ 3 posts ] 
Author Message
 Post subject: Performance Logging
PostPosted: Tue Feb 14, 2012 2:25 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 449
I am in the middle of working in the Network VMK 19 right now, and I added a little feature of my own. This will be a great tool if anyone is interested. This bit of source will write to a file in text format for each time you run the app and writes the time down. If the file doesn't exist it will create a new one, if it does it will append to the original file. you need to include <io.h>

add this block of code after the statement
printf( "Conversion took %f seconds\n", fTime );

   char* szFilename = "PerformanceLog.pcl";
   FILE* fp;
   int iCount = 1;

   if ( (_access( "PerformanceLog.pcl", 0 ) ) != -1 ) {
      // File Exists
      fopen_s( &fp, szFilename, "at" );
      if ( !fp ) {
         return -1;
      } else {
         fprintf_s( fp, "Test#%d: %f\n", ++iCount, fTime );
      }
   } else {
      // Does Not Exist Create It
      fopen_s( &fp, szFilename, "wt" );
      if ( !fp ) {
         return -1;
      } else {
         fprintf_s( fp, "Float Conversion Peformance Test: Measured In Seconds\nTest#%d: %f\n", iCount, fTime );
      }
   }   

   fclose( fp );


I hope this will help speed up the proccess and you can log your results to a file


Offline
 Profile  
 
 Post subject: Re: Network VMK 19 - Float Conversion Tests
PostPosted: Tue Feb 14, 2012 7:40 pm 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 449
Im still working on the above code, I took it out side of the main and put it into its own function. The function returns a bool and takes a double..

I am just having trouble getting the code to open the file for reading and scan the last line of text in the file. Im tryin to use fseek but im not sure how to get the last line of text. This is the only line that I am interested in so I can get the number value of which test run was last saved. extract that to use it so I can increment the next test run results.


Offline
 Profile  
 
 Post subject: Re: Network VMK 19 - Float Conversion Tests
PostPosted: Wed Feb 15, 2012 2:49 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 449
I finally got it to work correctly. :) Here is the function. All numbers inside of function MUST remain how they are. It has a specific format to generate an incrementer for each new test line in the log file. And don't forget to include <io.h> for the _access() call. I am writing to text, however the file extension I am using is *.pcl which stands for performance conversion log. Instead of using just plain old ".txt". To read the file you will have to add it into your solution explorer's current project's resource filter after you run the program atleast once. If you don't have VS and can not open the file to read it, you can simply just change the .pcl to .txt in the char* szFilename declaration.

// -------------------------------------
// writeToPerformanceLog()
bool writeToPerformanceLog( double dTime ) {

   // Local Variables
   char* szFilename = "Float2String2Float.pcl";
   char  szData[6] = {0};
   FILE* fp;
   int  iCount;
   bool bExists;

   // Check To See If File Exist If Not Create It.
   if ( (_access( szFilename, 0 ) ) != -1 ) {
      // File Exists
      bExists = true;
      // Open Our File For Appeneding Text With + Option
      if ( fopen_s( &fp, szFilename, "a+t" ) == 0 ) {         
         // We Want Our File* At The First Character In The Last Line Of Text.
         // Seek To End And Traverse Backwords 18 Chars. This Will Give Us The
         // Number Of Our Previous Test Run For Use With This Conversion Performance.
         fseek( fp, -18, SEEK_END );         
         // Read Last Line Up To 6th Character This Is The One We Want.
         fread( szData, sizeof(char), 6, fp );
      } else {
         // Opening File For Appending Failed Return False
         return false;
      }
   } else {      
      // File Does Not Exist Create It
      bExists = false;
      if ( fopen_s( &fp, szFilename, "wt") != 0 ) {
         // Failed To Create File Return False
         return false;
      }
   }   

   if ( bExists ) {
      // File Exists - Our Previous Test Run Counter Has Already Been Extracted
      // We Need To Format/Convert It To Increment Our Counter Value Then
      // Print The Current Test's Results To The End Of Our File
      char* c = NULL;
      c = &szData[5];
      iCount = atoi( c ) + 1;
      // Fix Our File Pointer
      fseek( fp, 0L, SEEK_END );
      // Print New Results To End Of File
      fprintf_s( fp, "Test#%d: %f\n", iCount, dTime );
   } else {
      // File Doesn't Exist - Creating A New One
      // Our Test Run Counter = 1
      iCount = 1;
      // Print Our Filename
      fprintf_s( fp, "%s\n", szFilename );
      // File Description
      fprintf_s( fp, "Float Conversion Peformance Test: Measured In Seconds\n" );
      // First Test Results
      fprintf_s( fp, "Test#%d: %f\n", iCount, dTime );
   }

   fclose( fp );

   return true;
}


This is how I called the function inside of main() to check for error handling. I will not show the full main function only the section after the liStop is generated.

int _tmain( int argc, _TCHAR* argv[] ) {

// code below ....

// code above ...
   // ----------------------------------------------
   QueryPerformanceCounter( &liStop );
   __int64 ticks = liStop.QuadPart - liStart.QuadPart;

   double dTime = static_cast<double>( ticks ) / static_cast<double>( frequency );
   printf( "Conversion took %f seconds\n", dTime );

   if ( !writeToPerformanceLog( dTime ) ) {
      return -1;
   }


   return 0;
}


Please post any comments on this code segment I want to see your feed back. If this can be implemented in an easier and/or more efficient way please let me know.

A note. while working through this video, if you happen to use my above code. For different data type conversions you could either delete the file itself and start your first run or give the file a different name.
The second choice would be better so you can comapare all results between different files.


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

cron