void CompilerTrackingInfo::logIntervalInPrivateTable() { /* ------------------------------------------------------ -- for debugging purposes we may need to dump the tracking -- information in a private table. The DDL of this table -- should be as follows: (change the name as needed) create table STATE_TRACKING_COMPILERS_TABLE_PRIVATE ( LOGGED_AT_LCT_TS TIMESTAMP(6) NOT NULL, COMPILER_ID CHAR(28) CHARACTER SET UCS2 NOT NULL, PROCESS_ID INT UNSIGNED NOT NULL, INTERVAL_START_LCT_TS TIMESTAMP(6), INTERVAL_PATH_LEN LARGEINT, LONGEST_COMPILE_PATH LARGEINT, COMPILER_AGE LARGEINT, NUM_SESSIONS INT UNSIGNED, STMT_HEAP_HWTR_MARK LARGEINT, CONTEXT_HEAP_SIZE LARGEINT, CONTEXT_HEAP_HWTR_MARK LARGEINT, SYSTEM_HEAP_SIZE LARGEINT, SYSTEM_HEAP_HWTR_MARK LARGEINT, METADATA_CACHE_SIZE LARGEINT, METADATA_CACHE_HWTR_MARK LARGEINT, METADATA_CACHE_HITS LARGEINT, METADATA_CACHE_LOOKUPS LARGEINT, QUERY_CACHE_SIZE LARGEINT, QUERY_CACHE_HWTR_MARK LARGEINT, QUERY_CACHE_HITS LARGEINT, QUERY_CACHE_LOOKUPS LARGEINT, HISTOGRAM_CACHE_SIZE LARGEINT, HISTOGRAM_CACHE_HWTR_MARK LARGEINT, HISTOGRAM_CACHE_HITS LARGEINT, HISTOGRAM_CACHE_LOOKUPS LARGEINT, NUM_QUERIES_COMPILED LARGEINT, NUM_FAILED_QUERIES LARGEINT, NUM_CAUGHT_EXCEPTIONS LARGEINT, NUM_RECOMPILES LARGEINT, COMPILER_INFO VARCHAR(256) CHARACTER SET UCS2, primary key (LOGGED_AT_LCT_TS, COMPILER_ID) ); ------------------------------------------------------ */ // the pointer to the process info for this tracker CmpProcess *p = processInfo_; char beginTime[100]; char endTime[100]; char compilerId[COMPILER_ID_LEN]; CMPASSERT( NULL != p ); NAString dmlprep = "insert into %s values("; // INSERT INTO TABLE VALUES dmlprep += "timestamp '%s'"; // LOGGED_AT_LCT_TS dmlprep += ",'%s'"; // COMPILER_ID dmlprep += ",%d"; // PROCESS_ID dmlprep += ",timestamp '%s'"; // INTERVAL_START_LCT_TS dmlprep += ",%d"; // INTERVAL_PATH_LEN dmlprep += ",%d"; // LONGEST_COMPILE_PATH dmlprep += ",%d"; // COMPILER_AGE dmlprep += ",%d"; // NUM_SESSIONS dmlprep += ",%d"; // STMT_HEAP_HWTR_MARK dmlprep += ",%d"; // CONTEXT_HEAP_SIZE dmlprep += ",%d"; // CONTEXT_HEAP_HWTR_MARK dmlprep += ",%d"; // SYSTEM_HEAP_SIZE dmlprep += ",%d"; // SYSTEM_HEAP_HWTR_MARK dmlprep += ",%d"; // METADATA_CACHE_SIZE dmlprep += ",%d"; // METADATA_CACHE_HWTR_MARK dmlprep += ",%d"; // METADATA_CACHE_HITS dmlprep += ",%d"; // METADATA_CACHE_LOOKUPS dmlprep += ",%d"; // QUERY_CACHE_SIZE dmlprep += ",%d"; // QUERY_CACHE_HWTR_MARK dmlprep += ",%d"; // QUERY_CACHE_HITS dmlprep += ",%d"; // QUERY_CACHE_LOOKUPS dmlprep += ",%d"; // HISTOGRAM_CACHE_SIZE dmlprep += ",%d"; // HISTOGRAM_CACHE_HWTR_MARK dmlprep += ",%d"; // HISTOGRAM_CACHE_HITS dmlprep += ",%d"; // HISTOGRAM_CACHE_LOOKUPS dmlprep += ",%d"; // NUM_QUERIES_COMPILED dmlprep += ",%d"; // NUM_FAILED_QUERIES dmlprep += ",%d"; // NUM_CAUGHT_EXCEPTIONS dmlprep += ",%d"; // NUM_RECOMPILES dmlprep += ",'%s'"; // COMPILER_INFO dmlprep += ");"; getTimestampAsBuffer(beginIntervalTime(), beginTime); getTimestampAsBuffer(endIntervalTime(), endTime); p->getCompilerId(compilerId, COMPILER_ID_LEN); NAString tableName = ActiveSchemaDB()->getDefaultSchema().getSchemaNameAsAnsiString() + "." + COMPILER_TRACKING_TABLE_NAME_PRIVATE; // // update the fields char dmlbuffer[8192]; str_sprintf( dmlbuffer, (const char*)dmlprep, tableName.data(), endTime, compilerId, p->getPin(), beginTime, cpuPathLength(), longestCompile(), compilerAge(), sessionCount(), stmtHeapIntervalWaterMark(), cxtHeapCurrentSize(), cxtHeapIntervalWaterMark(), p->getCurrentSystemHeapSize(), systemHeapIntervalWaterMark(), metaDataCacheCurrentSize(), metaDataCacheIntervalWaterMark(), metaDataCacheHits(), metaDataCacheLookups(), qCacheCurrentSize(), qCacheIntervalWaterMark(), qCacheHits(), qCacheLookups(), hCacheCurrentSize(), hCacheIntervalWaterMark(), hCacheHits(), hCacheLookups(), successfulQueryCount(), failedQueryCount(), caughtExceptionCount(), qCacheRecompiles(), compilerInfo()); ExeCliInterface cliInterface( CmpCommon::statementHeap(), 0, 0, CmpCommon::context()->sqlSession()->getParentQid()); if( cliInterface.beginWork() >= 0 ) { if( cliInterface.executeImmediate(dmlbuffer) >= 0 ) cliInterface.commitWork(); else cliInterface.rollbackWork(); } }
/************************************************************************ 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(); }
// Don't log this on Windows since the repository table does not exist Int32 CompilerTrackingInfo::logIntervalInRepository() { #ifdef SP_DIS return 0; #else // declare a stack variable and populate sql::tracking_compilers trc_row; Int32 rc; if (!isAMQPConnectionEstablished()) { rc = createAMQPConnection (NULL, -1); if (rc) return rc; AMQPConnectionEstablished(TRUE); } // the pointer to the process info for this tracker CmpProcess *p = processInfo_; CMPASSERT( NULL != p ); // ============================================ // -- start filling up the message structure -- // ============================================ // -- compiler Id char compilerId[COMPILER_ID_LEN]; memset (compilerId, '\0', COMPILER_ID_LEN); p->getCompilerId(compilerId); trc_row.set_compiler_id(compilerId); // interval start time trc_row.set_interval_start_lct_ts(beginIntervalTimeUEpoch()); // -- the CPU usage of this interval trc_row.set_interval_path_len(cpuPathLength()); // -- longest CPU path length for single compile // -- within this interval trc_row.set_longest_compile_path(longestCompile()); // -- age of compiler being tracked trc_row.set_compiler_age(compilerAge()); // -- number of sessions during this interval trc_row.set_num_sessions(sessionCount()); // -- largest size of the statement heap so far trc_row.set_stmt_heap_hwtr_mark(stmtHeapIntervalWaterMark()); // -- number of bytes currently allocated for the // -- context heap of this process trc_row.set_context_heap_size(cxtHeapCurrentSize()); // -- largest size of the context heap so far trc_row.set_context_heap_hwtr_mark(cxtHeapIntervalWaterMark()); // -- number of bytes currently allocated for the // -- system heap of this process trc_row.set_system_heap_size(p->getCurrentSystemHeapSize()); // -- largest size of the system heap so far trc_row.set_system_heap_hwtr_mark(systemHeapIntervalWaterMark()); // -- number of bytes currently allocated for the // -- metadata cache trc_row.set_metadata_cache_size(metaDataCacheCurrentSize()); // -- largest size of the metadata cache so far trc_row.set_metadata_cache_hwtr_mark(metaDataCacheIntervalWaterMark()); // -- number of hits on the metadata cache trc_row.set_metadata_cache_hits(metaDataCacheHits()); // -- number of misses on the metadata cache trc_row.set_metadata_cache_lookups(metaDataCacheLookups()); // -- number of bytes currently allocated for the // -- query cache trc_row.set_query_cache_size(qCacheCurrentSize()); // -- largest size of the query cache so far trc_row.set_query_cache_hwtr_mark(qCacheIntervalWaterMark()); // -- number of hits on the query cache trc_row.set_query_cache_hits(qCacheHits()); // -- number of misses on the query cache trc_row.set_query_cache_lookups(qCacheLookups()); // -- number of bytes currently allocated for the // -- histogram cache trc_row.set_histogram_cache_size(hCacheCurrentSize()); // -- largest size of the histogram cache so far trc_row.set_histogram_cache_hwtr_mark(hCacheIntervalWaterMark()); // -- number of hits on the histogram cache trc_row.set_histogram_cache_hits(hCacheHits()); // -- number of misses on the histogram cache trc_row.set_histogram_cache_lookups(hCacheLookups()); // -- number of compiled queries (DDL and DML) trc_row.set_num_queries_compiled(successfulQueryCount()); // -- number of failed compilations trc_row.set_num_failed_queries(failedQueryCount()); // -- number of queries compiled successfully // -- but with warnings (2053 and 2078) trc_row.set_num_caught_exceptions(caughtExceptionCount()); // -- the number of recompiles trc_row.set_num_recompiles(qCacheRecompiles()); // -- extend any new counters trc_row.set_compiler_info(compilerInfo()); // ============================================ // -- done filling up the message structure -- // ============================================ // populate the info header common::info_header *infoHeader = NULL; infoHeader = trc_row.mutable_header(); rc = initAMQPInfoHeader(infoHeader, SQEVL_SQL); if (rc) { closeAMQPConnection(); AMQPConnectionEstablished(FALSE); return rc; } // set the routing key and send the message AMQPRoutingKey routingKey (SP_HEALTH_STATE, SP_SQLPACKAGE, SP_INSTANCE, SP_PUBLIC, SP_GPBPROTOCOL, "tracking_compilers"); try { rc = sendAMQPMessage (true, trc_row.SerializeAsString(), SP_CONTENT_TYPE_APP, routingKey); if (rc) throw 1; } catch (...) { if (rc == SP_SUCCESS) rc = SP_SEND_FAILED; closeAMQPConnection(); AMQPConnectionEstablished(FALSE); } return rc; #endif }