⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 delirpt.c

📁 oracle数据库tpcc(在线事务处理能力)测试的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
*
* RETURNS: int ERR_CANNOT_OPEN_RESULTS_FILE Cannot create results log file.
* ERR_SUCCESS Log file successfully opened
*
*
* COMMENTS: None
*
*/
static int OpenLogFile(void)
{
   fpLog = fopen("delilog", "rb");
   if ( !fpLog )
      return ERR_CANNOT_OPEN_RESULTS_FILE;
   return ERR_SUCCESS;
}
/* FUNCTION: int CloseLogFile(void)
*
* PURPOSE: This function closes the delivery log file.
*
* ARGUMENTS: None
*
* RETURNS: None
*
* COMMENTS: None
*
*/
static void CloseLogFile(void)
{
   if ( fpLog )
   fclose(fpLog);
   return;
}
/* FUNCTION: static void ResetLogFile(void)
*
* PURPOSE: This function prepares the delilog. file for reading
*
* ARGUMENTS: None
*
* RETURNS: None
*
* COMMENTS: None
*
*/
static void ResetLogFile(void)
{
   fseek(fpLog, 0L, SEEK_SET);
   LogEOF(LOGFILE_CLEAR_EOF);
   return;
}
/* FUNCTION: static BOOL LogEOF(int iOperation)
*
* PURPOSE: This function tracks and reports the end of file condition
* on the delilog file.
*
* ARGUMENTS: int iOperation requested operation this can be:
* LOGFILE_READ_EOF check log file flag return current state
* LOGFILE_CLEAR_EOF clear end of log file flag
* LOGFILE_SET_EOF set flag end of log file reached
*
*
* RETURNS: None
*
* COMMENTS: None
*
*/
static BOOL LogEOF(int iOperation)
{
   static BOOL bEOF;
   switch(iOperation)
   {
      case LOGFILE_READ_EOF:
         return bEOF;
         break;
      case LOGFILE_CLEAR_EOF:
         bEOF = FALSE;
         break;
      case LOGFILE_SET_EOF:
         bEOF = TRUE;
         break;
   }
   return FALSE;
}
/* FUNCTION: static BOOL ReadReportLine(char *szBuffer, PRPTLINE pRptLine)
*
* PURPOSE: This function reads a text line from the delilog file.
* on the delilog file.
*
* ARGUMENTS: char *szBuffer buffer to placed read delilog file line into.
* PRPTLINE pRptLine returned structure containing parsed delilog
* report line.
*
* RETURNS: FALSE if successfull or TRUE if an error occurs.
*
* COMMENTS: None
*
*/
static BOOL ReadReportLine(char *szBuffer, PRPTLINE pRptLine)
{
   int i = 0;
   int ch;
   int iEof;
   while( i < 128 )
   {
      ch = fgetc(fpLog);
      if ( iEof = feof(fpLog) )
         break;
      if ( ch == '\r' )
      {
         if ( i )
            break;
         continue;
      }
      if ( ch == '\n' )
      {
         continue;
      }
      szBuffer[i++] = ch;
   }
//delivery item format is to long cannot be a valid
   delivery item
   if ( i >= 128 )
      return TRUE;
   szBuffer[i] = 0;
   if ( iEof )
   {
      LogEOF(LOGFILE_SET_EOF);
      if ( i == 0 )
         return FALSE;
   }
   if ( szBuffer[0] == '*' )
   {
//error line ignore
      return FALSE;
   }
   return ParseReportLine(szBuffer, pRptLine);
}
/* FUNCTION: static BOOL ParseReportLine(char *szLine, PRPTLINE pRptLine)
*
* PURPOSE: This function reads a text line from the delilog file.
* on the delilog file.
*
* ARGUMENTS: char *szLine buffer containing the delilog file line to be parsed.
* PRPTLINE pRptLine returned structure containing parsed delilog
* report line values.
*
* RETURNS: FALSE if successfull or TRUE if an error occurs.
*
* COMMENTS: None
*
*/
static BOOL ParseReportLine(char *szLine, PRPTLINE pRptLine)
{
   int i;
   if ( ParseDate(szLine, (DelTime *) &pRptLine->start) )
      return TRUE;
   pRptLine->end.dtime.tm_year = pRptLine->start.dtime.tm_year;
   pRptLine->end.dtime.tm_mon = pRptLine->start.dtime.tm_mon;
   pRptLine->end.dtime.tm_mday = pRptLine->start.dtime.tm_mday;
   pRptLine->day=(pRptLine->start.dtime.tm_mon*100) + pRptLine->start.dtime.tm_mday;
   if (StartDay == 0) 
   {
      StartDay=pRptLine->day;
      printf("Setting Start Day to %d\n", StartDay);
   }
   if ( !(szLine = strchr(szLine, ',')) )
      return TRUE;
   szLine++;
   if ( ParseTime(szLine, (DelTime *) &pRptLine->start) )
      return TRUE;
   if ( !(szLine = strchr(szLine, ',')) )
      return TRUE;
   szLine++;
   if ( ParseTime(szLine, (DelTime *) &pRptLine->end) )
      return TRUE;
   if ( !(szLine = strchr(szLine, ',')) )
      return TRUE;
   szLine++;
   if ( !IsNumeric(szLine) )
      return TRUE;
   pRptLine->response = atoi(szLine);
   if ( !(szLine = strchr(szLine, ',')) )
      return TRUE;
   szLine++;
   if ( !IsNumeric(szLine) )
      return TRUE;
   pRptLine->w_id = atoi(szLine);
   if ( !(szLine = strchr(szLine, ',')) )
      return TRUE;
   szLine++;
   if ( !IsNumeric(szLine) )
      return TRUE;
   pRptLine->o_carrier_id = atoi(szLine);
   if ( !(szLine = strchr(szLine, ',')) )
      return TRUE;
   szLine++;
   for(i=0; i<10; i++)
   {
      if ( !IsNumeric(szLine) )
         return TRUE;
      pRptLine->items[i] = atoi(szLine);
      if ( i<9 && !(szLine = strchr(szLine, ',')) )
         return TRUE;
      szLine++;
   }
   return FALSE;
}
/* FUNCTION: static BOOL ParseDate(char *szDate, DelTime *pTime)
*
* PURPOSE: This function validates and extracts a date string in the format
* yy/mm/dd into an DelTime structure.
*
* ARGUMENTS: char *szDate buffer containing the date to be parsed.
* DelTime *pTime system time structure where date will be placed.
*
* RETURNS: FALSE if successfull or TRUE if an error occurs.
*
* COMMENTS: None
*
*/
static BOOL ParseDate(char *szDate, DelTime *pTime)
{
   if ( !isdigit(*szDate) || !isdigit(*(szDate+1)) ||
   !isdigit(*(szDate+2)) || !isdigit(*(szDate+3)) || *(szDate+4) != '/' ||
   !isdigit(*(szDate+5)) || !isdigit(*(szDate+6)) || *(szDate+7) != '/' ||
   !isdigit(*(szDate+8)) || !isdigit(*(szDate+9)))
      return TRUE;
   pTime->dtime.tm_year = atoi(szDate);
   pTime->dtime.tm_mon= atoi(szDate+5);
   pTime->dtime.tm_mday = atoi(szDate+8);
   if ( pTime->dtime.tm_mon > 12 || pTime->dtime.tm_mon < 0
   || pTime->dtime.tm_mday > 31 || pTime->dtime.tm_mday < 0 )
      return TRUE;
   return FALSE;
}
/* FUNCTION: static BOOL ParseTime(char *szTime, DelTime *pTime)
*
* PURPOSE: This function validates and extracts a time string in the format
* hh:mm:ss:mmm into an DelTime structure.
*
* ARGUMENTS: char *szTime buffer containing the time to be parsed.
* DelTime *pTime system time structure where date will be placed.
*
* RETURNS: FALSE if successfull or TRUE if an error occurs.
*
* COMMENTS: None
*
*/
static BOOL ParseTime(char *szTime, DelTime *pTime)
{
   if ( !isdigit(*szTime) || !isdigit(*(szTime+1)) || *(szTime+2) != ':' ||
        !isdigit(*(szTime+3)) || !isdigit(*(szTime+4)) || *(szTime+5) != ':' ||
        !isdigit(*(szTime+6)) || !isdigit(*(szTime+7)) || *(szTime+8) != ':' ||
        !isdigit(*(szTime+9)) || !isdigit(*(szTime+10)) || !isdigit(*(szTime+11)) )
       return TRUE;
   pTime->dtime.tm_hour = atoi(szTime);
   pTime->dtime.tm_min = atoi(szTime+3);
   pTime->dtime.tm_sec = atoi(szTime+6);
   pTime->wMilliseconds = atoi(szTime+9);
   if ( pTime->dtime.tm_hour > 23 || pTime->dtime.tm_hour < 0 ||
        pTime->dtime.tm_min > 59 || pTime->dtime.tm_min < 0 ||
        pTime->dtime.tm_sec > 59 || pTime->dtime.tm_sec < 0 ||
        pTime->wMilliseconds < 0 )
       return TRUE;
   if ( pTime->wMilliseconds > 999 )
   {
      pTime->dtime.tm_sec += (pTime->wMilliseconds/1000);
      pTime->wMilliseconds = pTime->wMilliseconds %1000;
   }
   return FALSE;
}
/* FUNCTION: void ErrorMessage(int iError)
*
* PURPOSE: This function displays an error message in the delivery executable's console window.
*
* ARGUMENTS: int iError error id to be displayed
*
* RETURNS: None
*
* COMMENTS: None
*
*/
static void ErrorMessage(int iError)
{
   int i;
   static SERRORMSG errorMsgs[] =
   {{ ERR_SUCCESS,"Success, no error."},
    { ERR_CANNOT_OPEN_RESULTS_FILE,"Cannot open delivery results file delilog."},
    { ERR_READING_LOGFILE,"Reading delivery log file,Delivery item format incorrect." },
    { ERR_INSUFFICIENT_MEMORY,"insufficient memory to process 90th percentile report." },
    { 0,""}};
   for(i=0; errorMsgs[i].szMsg[0]; i++)
   {
      if ( iError == errorMsgs[i].iError )
      {
         printf("\nError(%d): %s\n", iError,
         errorMsgs[i].szMsg);
         return;
      }
   }
   printf("Error(%d): %s", errorMsgs[0].szMsg);
   return;
}
/* FUNCTION: BOOL GetParameters(int argc, char *argv[])
*
* PURPOSE: This function parses the command line passed in to the delivery executable, initializing
* and filling in global variable parameters.
*
* ARGUMENTS: int argc number of command line arguments passed to delivery
* char *argv[] array of command line argument pointers
*
* RETURNS: BOOL FALSE parameter read successfull
* TRUE user has requested parameter information screen be displayed.
*
* COMMENTS: None
*
*/
static BOOL GetParameters(int argc, char *argv[])
{
   int i;
   DelTime startTime;
   DelTime endTime;
   iStartTime = 0;
   iEndTime = 0;
   iReport = 4;
   for(i=0; i<argc; i++)
   {
      if ( argv[i][0] == '-' || argv[i][0] == '/' )
      {
         switch(argv[i][1])
         {
            case 'S':
            case 's':
               if (ParseTime(argv[i]+2, &startTime) )
	          return true;
	       iStartTime = (startTime.dtime.tm_hour * 3600000) + (startTime.dtime.tm_min *
                             60000) + (startTime.dtime.tm_sec * 1000) + startTime.wMilliseconds;
               break;
	    case 'E':
	    case 'e':
	       if (ParseTime(argv[i]+2, &endTime) )
		  return TRUE;
	       iEndTime = (endTime.dtime.tm_hour * 3600000) + (endTime.dtime.tm_min * 60000)
			  + (endTime.dtime.tm_sec * 1000) + endTime.wMilliseconds;
	       if (iStartTime > iEndTime)
		  OverMidnight=1;
	       break;
	    case 'R':
	    case 'r':
	       iReport = atoi(argv[i]+2);
	       if ( iReport > 4 || iReport < 1 )
		  iReport = 4;
	       break;
	    case '?':
	       return TRUE;
	 }
      }
   }
   return FALSE;
}
/* FUNCTION: void PrintParameters(void)
*
* PURPOSE: This function displays the supported command line flags.
*
* ARGUMENTS: None
*
* RETURNS: None
*
* COMMENTS: None
*
*/
static void PrintParameters(void)
{
   printf("DELIRPT:\n\n");
   printf("Parameter Default\n");
   printf("-------------------------------------------------
          ----------------------\n");
   printf("-S Start Time HH:MM:SS:MMM All \n");
   printf("-E End Time HH:MM:SS:MMM All \n");
   printf("-R 1)Average Response, 2)90th 3) Skipped 4) All All \n");
   printf("-? This help screen\n\n");
   printf("Note: Command line switches are NOT case sensitive.\n");
   return;
}
/* FUNCTION: void cls(void)
*
* PURPOSE: This function clears the console window
*
* ARGUMENTS: None
*
* RETURNS: None
*
* COMMENTS: None
*
*/
static void cls(void)
{
   system("clear");
   return;
}
/* FUNCTION: BOOL IsNumeric(char *ptr)
*
* PURPOSE: This function determines if a string is numeric. It fails if any characters other
* than numeric and null terminator are present.
*
* ARGUMENTS: char *ptr pointer to string to check.
*
* RETURNS: BOOL FALSE if string is not all numeric
* TRUE if string contains only numeric characters i.e. '0' - '9'
*
* COMMENTS: A comma is counted as a valid delimiter.
*
*/
static BOOL IsNumeric(char *ptr)
{
   if ( *ptr == 0 )
      return FALSE;
   while( *ptr && isdigit(*ptr) )
      ptr++;
   if ( !*ptr || *ptr == ',' )
      return TRUE;
   else
      return FALSE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -