Example #1
0
/************************************************************************
method CompilerTrackingInfo::logCompilerStatusOnInterval

Dump the fields of this class out to a file (or to repository) if
the tracking compiler interval has expired

************************************************************************/
void
CompilerTrackingInfo::logCompilerStatusOnInterval(Int32 intervalLengthMins)
{

  if( intervalExpired(intervalLengthMins) )
  {
    //
    // this interval is now done/expired
    endIntervalTime_ = getCurrentTimestamp();
    //
    // get the latest cache stats once per interval
    if (!CURRENTQCACHE->getCompilationCacheStats(currentQCacheStats_))
    {
       // if query is disabled, clear the cache counters
       clearQCacheCounters();
    }

    //
    // log this interval
    if( NULL != getCompilerTrackingLogFilename() )
    {
      printToFile();      
    }

    //
    // log directly to a private table using dynamic SQL 
    // instead of using the Repository infrastructure to
    // populate repository table
    if (CmpCommon::getDefault(COMPILER_TRACKING_LOGTABLE) == DF_ON)
    {
       logIntervalInPrivateTable();    
    }

//
// This table doesn't exist on Windows, so don't log there
    // always log to the repository table
    Int32 rc = logIntervalInRepository();    
    if (rc)
    {
       // raise a warning that compiler process is unable to log 
       // its status and health information to the repository
       *CmpCommon::diags() << DgSqlCode(2242);
    }

    //
    // since the interval is expired, reset to begin tracking new interval
    resetInterval();        
  }
}
/************************************************************************
method CompilerTrackingInfo::logCompilerStatusOnInterval

Dump the fields of this class out to a file (or to repository) if
the tracking compiler interval has expired

************************************************************************/
void
CompilerTrackingInfo::logCompilerStatusOnInterval(Int32 intervalLengthMins)
{

  if( intervalExpired(intervalLengthMins) )
  {
    //
    // this interval is now done/expired
    endIntervalTime_ = getCurrentTimestamp();
    //
    // get the latest cache stats once per interval
    if (!CURRENTQCACHE->getCompilationCacheStats(currentQCacheStats_))
    {
       // if query is disabled, clear the cache counters
       clearQCacheCounters();
    }

    //
    // log this interval
    if( NULL != getCompilerTrackingLogFilename() )
    {
      printToFile();      
    }

    //
    // log directly to a private table using dynamic SQL 
    if (CmpCommon::getDefault(COMPILER_TRACKING_LOGTABLE) == DF_ON)
    {
       logIntervalInPrivateTable();    
    }

    // always log to log4cxx log
    logIntervalInLog4Cxx();
        
    // since the interval is expired, reset to begin tracking new interval
    resetInterval();        
  }
}
/************************************************************************
method CompilerTrackingInfo::printToFile

helper to simply print the tracker info into the specified file. 

************************************************************************/
void
CompilerTrackingInfo::printToFile()
{
  const char *trackerLogFilename = getCompilerTrackingLogFilename();

  CMPASSERT( NULL != trackerLogFilename );

  // the pointer to the process info for this tracker
  CmpProcess *p = processInfo_;

  CMPASSERT( NULL != p );

  ofstream fileout(trackerLogFilename, ios::app);
    
  fileout << "--------------------------------\n";
  fileout << "         Start Interval\n";
  fileout << endl;
  char beginTime[100];
  char endTime[100];  
  getTimestampAsBuffer(beginIntervalTime(), beginTime);
  getTimestampAsBuffer(endIntervalTime(), endTime);
  fileout << "Logged Interval At\t: " << endTime << endl;
  fileout << "Interval Start Time\t: " << beginTime << endl;  
  fileout << "Interval Duration\t: " << currentIntervalDuration(endIntervalTime()) 
                << " minutes" << endl;

  fileout << endl;
     
  char compilerId[COMPILER_ID_LEN];
  p->getCompilerId(compilerId, COMPILER_ID_LEN);
  fileout << "Compiler ID\t\t: " << compilerId << endl; 
  fileout << "Process ID\t\t: " << p->getPin() << endl;  
  fileout << "Compiler Age\t\t: " << compilerAge() << " minutes\n";
  fileout << "Successful Compilations : " << successfulQueryCount() << endl;
  fileout << "Failed Compilations \t: " << failedQueryCount() << endl;
  fileout << "Recompiles \t\t: " << qCacheRecompiles() << endl;
  fileout << "Sessions \t\t: " << sessionCount() << endl;
  fileout << "Caught Exceptions \t: " << caughtExceptionCount() << endl;
  fileout << endl;
  fileout << "Interval CPU time\t: " << cpuPathLength() << endl;
  fileout << "Longest Compile (CPU)\t: " << longestCompile() << endl;
  //
  // additional compiler info
  fileout << endl;
  fileout << "Compiler Info\t\t: " << compilerInfo() << endl;
  //
  // heap/cache table
  fileout << endl;  
  fileout.width(CACHE_HEAP_HEADER_LEN);
  fileout << "";
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << "CurrentSize";
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << "HighWaterMark";
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << "Hits";
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << "Lookups";
  fileout << endl;

  fileout.width(CACHE_HEAP_HEADER_LEN);
  fileout << "";
  fileout.width(CACHE_HEAP_VALUE_LEN*4);
  fileout << "----------------------------------------------------------------";
  fileout << "\n\n";    
  //
  // system heap
  fileout.width(CACHE_HEAP_HEADER_LEN);
  fileout << "System Heap: ";
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << p->getCurrentSystemHeapSize();
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << systemHeapIntervalWaterMark();
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << "N/A";
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << "N/A";
  fileout << endl;
  //
  // context heap
  fileout.width(CACHE_HEAP_HEADER_LEN);
  fileout << "Context Heap: ";
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << cxtHeapCurrentSize();
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << cxtHeapIntervalWaterMark();
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << "N/A";
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << "N/A";
  fileout << endl;
  //
  // statement heap
  fileout.width(CACHE_HEAP_HEADER_LEN);
  fileout << "Statement Heap: "; 
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << "N/A";
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << stmtHeapIntervalWaterMark();
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << "N/A";
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << "N/A";
  fileout << endl;
  //
  // metadata cache
  fileout.width(CACHE_HEAP_HEADER_LEN);
  fileout << "Metadata Cache: ";
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << metaDataCacheCurrentSize();
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << metaDataCacheIntervalWaterMark();
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << metaDataCacheHits();
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << metaDataCacheLookups();  
  fileout << endl;
  //
  // query cache
  fileout.width(CACHE_HEAP_HEADER_LEN);
  fileout << "Query Cache: ";
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << qCacheCurrentSize();
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << qCacheIntervalWaterMark();
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << qCacheHits();
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << qCacheLookups();    
  fileout << endl;
  //
  // histogram cache
  fileout.width(CACHE_HEAP_HEADER_LEN);
  fileout << "Histogram Cache: ";
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << hCacheCurrentSize();
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << hCacheIntervalWaterMark();
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << hCacheHits();
  fileout.width(CACHE_HEAP_VALUE_LEN);
  fileout << hCacheLookups();    
  fileout << endl;  
  
  fileout << endl;
  fileout << "         End Interval\n";
  fileout << "--------------------------------\n";
  fileout.close();
}