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

📄 logfile_mod.c

📁 oracle数据库tpcc(在线事务处理能力)测试的源码
💻 C
字号:
/***************************
logfile_mod.c
***************************
/*+****************************************************************
**********
*
*
* COPYRIGHT (c) 1997 BY
*
* DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASSACHUSETTS.
*
* ALL RIGHTS RESERVED.
*
*
*
* THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED *
* ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE *
* INCLUSION OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE OR ANY OTHER *
* COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY *
* OTHER PERSON. NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY *
* TRANSFERRED.
*
*
*
* THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE *
* AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT *
* CORPORATION.
*
*
*
* DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS *
* SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.
*
*
*
*
*
*******************************************************************
*********/
/*+
* Abstract: This file contains the Digital created front end functions
* for the tpcc benchmark.
*
* Author: W Carr
* Creation Date: October 1997
*
*
* Modification history:
*
*
* 08/01/2002 Andrew Bond, HP
* - Conversion to run under Linux and Apache
*
*/
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include <sys/time.h>
#include <errno.h>
#include <unistd.h>
#include "apr_thread_mutex.h"
#include <oci.h>
#include <ocidfn.h>
#include <ociapr.h>
#include <tpccerr.h>
#include <tpccstruct.h>
#include <oracle_db8.h>
#include <tpccapi.h>
#include <tpcc.h>
static FILE *LogFile;
static char t1[1];
static apr_thread_mutex_t * ErrCriticalSection;
static apr_thread_mutex_t * LogCriticalSection;
/* FUNCTION: void TPCCOpenLog( void )
*
* PURPOSE: This function opens the log file.
*
* ARGUMENTS: None
*
* RETURNS: None
*
* COMMENTS: None
*
*/
bool TPCCOpenLog( apr_pool_t *pool )
{
   char szFile[FILENAMESIZE];
   apr_thread_mutex_create(&LogCriticalSection, 0, pool);
   strcpy( szFile, szTpccLogPath );
   strcat( szFile, "tpcclog" );
   if (LogFile = fopen( szFile, "a")) 
   {
      apr_thread_mutex_create(&ErrCriticalSection, 0, pool);
      return TRUE;
   }
   else
   {
      return FALSE;
   }
}
/* FUNCTION: void TPCCCloseLog( void )
*
* PURPOSE: This function closes the log file.
*
* ARGUMENTS: None
*
* RETURNS: None
*
* COMMENTS: None
*
*/
BOOL TPCCCloseLog( void )
{
   fclose( LogFile );
   return TRUE;
}
/* FUNCTION: void TPCCLog( char *szType, char *szStr )
*
* PURPOSE: This function reports the date, time, operation and
* string to the log file.
*
* ARGUMENTS: char *szType String containing the operation type
* i.e. Query or Response.
* char *szStr String associated with the operation.
*
* RETURNS: None
*
* COMMENTS: None
*
*/
void TPCCLog( char *fmt, ... )
{
   va_list marker;
   char szArg[4096];
   struct timezone tz;
   struct timeval tv;
   struct tm systemTime;
   struct tm *pst;
   int len, ret;
   va_start( marker, fmt );
   vsprintf( szArg, fmt, marker );
   va_end( marker );
   pst=&systemTime;
   ret=gettimeofday(&tv, &tz);
   apr_thread_mutex_lock( LogCriticalSection );
   pst=localtime(&tv.tv_sec);
   len = fprintf( stderr,"[%ld] %2.2d/%2.2d/%2.2d%2.2d:%2.2d:%2.2d\t%s\r\n",
                 getpid(),1900+pst->tm_year, pst->tm_mon+1, pst->tm_mday,
		 pst->tm_hour, pst->tm_min, pst->tm_sec,szArg );
   apr_thread_mutex_unlock( LogCriticalSection );
}
void TPCCErrInternal( char *szTmp, int len )
{
   int dwWriteLen;
   FILE *ErrFile;
   char szFile[FILENAMESIZE];
   apr_thread_mutex_lock( ErrCriticalSection );
   strcpy( szFile, szTpccLogPath );
   strcat( szFile, "tpccerr" );
   ErrFile = fopen( szFile, "a");
   if (ErrFile) 
   {
      len = fprintf( ErrFile, "%s\n", szTmp);
      fclose( ErrFile );
   }
   apr_thread_mutex_unlock( ErrCriticalSection );
}
void TPCCErr( char *fmt, ...)
{
   va_list marker;
   char szTmp[4096];
   char szArg[4096];
   struct timezone tz;
   struct timeval tv;
   struct tm systemTime;
   struct tm *pst;
   int len, ret;
   va_start( marker, fmt );
   vsprintf( szArg, fmt, marker );
   va_end( marker );
   pst=&systemTime;
   ret=gettimeofday(&tv, &tz);
   pst=localtime(&tv.tv_sec);
   len = sprintf( szTmp,"%2.2d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d\t%s\r\n",
		1900+pst->tm_year, pst->tm_mon+1, pst->tm_mday,
		pst->tm_hour, pst->tm_min, pst->tm_sec,szArg );
   TPCCErrInternal( szTmp, len );
}
void TPCCTransactionErr( pConnData pConn, char *fmt, ...)
{
   va_list marker;
   char szTmp[4096];
   char szArg[4096];
   struct timezone tz;
   struct timeval tv;
   struct tm systemTime;
   struct tm *pst;
   int len, ret;
   va_start( marker, fmt );
   vsprintf( szArg, fmt, marker );
   va_end( marker );
   pst=&systemTime;
   ret=gettimeofday(&tv, &tz);
   pst=localtime(&tv.tv_sec);
   len = sprintf( szTmp,"%2.2d/%2.2d/%2.2d
		%2.2d:%2.2d:%2.2d\tTransaction error. w_id: %d, ld_id: %d, pCC: %x,
		status: %d, dbstatus: %d, %s\r\n",
		1900+pst->tm_year, pst->tm_mon+1, pst->tm_mday,
		pst->tm_hour, pst->tm_min, pst->tm_sec,
		pConn->w_id, pConn->ld_id, pConn->pCC,
		pConn->status, pConn->dbstatus,szArg );
   TPCCErrInternal( szTmp, len );
}

⌨️ 快捷键说明

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