/* * GetNextThread - * NB - callers must continue to call this function until it returns FALSE */ BOOL GetNextThread( ThreadList *info, ThreadPlace *place, DWORD pid, BOOL first ) { DWORD curpid; PERF_COUNTER_DEFINITION *counter; BOOL error; error = FALSE; if( first ) { beginRead( FALSE ); initObj( ®Data, &threadObject, N_THREAD ); if( threadObject == NULL ) error = TRUE; if( !error ) { place->index = 0; place->obj = threadObject; place->pid = pid; place->inst = getFirstInstance( threadObject ); } } else { place->index ++; if( place->index < place->obj->NumInstances ) { place->inst = getNextInstance( place->inst ); } } if( !error ) { counter = findCounter( place->obj, N_PROCID ); if( counter == NULL ) error = TRUE; } if( !error ) { for( ; place->index < place->obj->NumInstances; place->index ++ ) { if( place->inst == NULL ) { error = TRUE; break; } curpid = getCounterDWORD( place->inst, counter ); if( curpid == place->pid ) break; place->inst = getNextInstance( place->inst ); } } if( !error && place->index >= place->obj->NumInstances ) error = TRUE; if( !error ) { counter = findCounter( place->obj, N_THREADID ); if( counter == NULL ) error = TRUE; } if( !error ) { info->tid = getCounterDWORD( place->inst, counter ); counter = findCounter( place->obj, N_BASE_PRIORITY ); if( counter == NULL ) error = TRUE; } if( !error ) { info->priority = getCounterDWORD( place->inst, counter ); } else { endRead( FALSE ); } return( !error ); }
/**Copy NAND Cypto to our region.*/ void FSNandInitCrypto(void) { uint8_t *ctrStart = findCounter(); uint8_t *ctrStore = NANDCTR; uint8_t i = 16; //CTR length if (!ctrStart) { return; } //Avoid copying from NULL ctrStart = ctrStart + 15; //The CTR is stored backwards in memory. while (i --) { *(ctrStore++) = *(ctrStart--); } }
void Hwmon::setupCounter(Counter &counter) { HwmonCounter *const hwmonCounter = findCounter(counter); if (hwmonCounter == NULL) { counter.setEnabled(false); return; } hwmonCounter->setEnabled(true); counter.setKey(hwmonCounter->getKey()); }
TR::DebugCounter *TR::DebugCounterGroup::createCounter(const char *name, int8_t fidelity, TR_PersistentMemory *persistentMemory) { // Get the denominator counter, if any, by looking for the rightmost separator character. // TR::DebugCounter *denominator = NULL; const char *separator = NULL; int verbatimDepth = 0; for (const char *c = name; c[0]; c++) { if (c[0] == VERBATIM_START) verbatimDepth++; else if (c[0] == VERBATIM_STOP) verbatimDepth--; if (verbatimDepth == 0) { if (c[0] == FRACTION_SEPARATOR || c[0] == RATIO_SEPARATOR) separator = c; } } if (separator) // There is a denominator counter { denominator = findCounter(name, separator-name); if (!denominator) { // Can't be lazy anymore; we really need to make a copy of part of the name string // char *denominatorName = (char*)persistentMemory->allocatePersistentMemory(separator-name+1); TR_ASSERT(denominatorName, "char *denominatorName must not be null. Ensure availability of persistent memory"); sprintf(denominatorName, "%.*s", (int)(separator-name), name); // Counter has negligible cost, assuming it's only used as a denominator // denominator = createCounter(denominatorName, TR::DebugCounter::Free, persistentMemory); } } // Create the desired counter // int8_t flags = 0; if (separator && separator[0] == FRACTION_SEPARATOR) { TR_ASSERT(denominator, "Debug counter with a fraction separator character must have a denominator"); flags |= TR::DebugCounter::ContributesToDenominator; } TR::DebugCounter *result = new (persistentMemory) TR::DebugCounter(name, fidelity, denominator, flags); TR_ASSERT(result, "DebugCounter *result must not be null. Ensure availability of persistent memory"); _counters.add(result); // There's a race here if we do parallel compilation OMR::CriticalSection createCounterLock(_countersMutex); _countersHashTable.Add(result->getName(), result); return result; }
/* * GetProcessInfo */ BOOL GetProcessInfo( DWORD pid, ProcStats *info ) { DWORD i; PERF_COUNTER_DEFINITION *counter; PERF_INSTANCE_DEFINITION *inst; DWORD curpid; BOOL error; beginRead( FALSE ); error = FALSE; initObj( ®Data, &processObject, N_PROCESS ); if( processObject == NULL ) error = TRUE; if( !error ) { counter = findCounter( processObject, N_PROCID ); if( counter == NULL ) error = TRUE; } if( !error ) { inst = getFirstInstance( processObject ); for( i=0; i < processObject->NumInstances; i++ ) { if( inst == NULL ) { error = TRUE; break; } curpid = getCounterDWORD( inst, counter ); if( curpid == pid ) break; inst = getNextInstance( inst ); } } if( !error && curpid == pid && info != NULL ) { info->pid = curpid; counter = findCounter( processObject, N_BASE_PRIORITY ); if( counter == NULL ) { error = TRUE; } else { info->priority = getCounterDWORD( inst, counter ); wsprintf( info->name, "%ls", (char *)inst + inst->NameOffset ); } } endRead( FALSE ); return( !error && curpid == pid ); }
/* * GetNextProcess * NB - callers must continue to call this function until it returns FALSE */ BOOL GetNextProcess( ProcList *info, ProcPlace *place, BOOL first ) { PERF_COUNTER_DEFINITION *counter; BOOL error; error = FALSE; if( first ) { beginRead( FALSE ); initObj( ®Data, &processObject, N_PROCESS ); if( processObject == NULL ) error = TRUE; if( !error ) { place->index = 0; place->obj = processObject; place->inst = getFirstInstance( processObject ); } } else { place->index ++; if( place->index >= processObject->NumInstances ) { endRead( FALSE ); return( FALSE ); } place->inst = getNextInstance( place->inst ); } if( place->inst == NULL ) error = TRUE; if( !error ) { counter = findCounter( place->obj, N_PROCID ); if( counter == NULL ) error = TRUE; } if( !error ) { info->pid = getCounterDWORD( place->inst, counter ); counter = findCounter( place->obj, N_BASE_PRIORITY ); if( counter == NULL ) error = TRUE; } if( !error ) { info->priority = getCounterDWORD( place->inst, counter ); wsprintf( info->name, "%ls", (char *)( place->inst ) + place->inst->NameOffset ); } else { endRead( FALSE ); } return( !error ); }
const char *TR::DebugCounterGroup::counterName(TR::Compilation *comp, const char *format, va_list args) { const char *name = comp->getDebug()->formattedString(NULL, 0, format, args, persistentAlloc); TR::DebugCounter *matchingCounter = findCounter(name, strlen(name)); if (matchingCounter) { comp->trMemory()->jitPersistentFree((void*)name); name = matchingCounter->getName(); } return name; }
TR::DebugCounter *TR::DebugCounterGroup::getCounter(TR::Compilation *comp, const char *name, int8_t fidelity) { // Note: we assume the name string passed in is safe to keep persistently. // If this is not the case, the caller must make a copy of it into // persistent memory. TR::DebugCounter *result = findCounter(name, strlen(name)); if (!result) result = createCounter(name, fidelity, comp->trPersistentMemory()); TR_ASSERT(result->getFidelity() >= fidelity, "Request for counter at fidelity %d is too high; counter only has fidelity %d: %s\n", fidelity, result->getFidelity(), name); result->_fidelity = fidelity; return result; }
void PerfDriver::setupCounter(Counter &counter) { PerfCounter *const perfCounter = findCounter(counter); if (perfCounter == NULL) { counter.setEnabled(false); return; } // Don't use the config from counters XML if it's not set, ex: software counters if (counter.getEvent() != -1) { perfCounter->setConfig(counter.getEvent()); } perfCounter->setCount(counter.getCount()); perfCounter->setEnabled(true); counter.setKey(perfCounter->getKey()); }
/* * GetThreadInfo */ BOOL GetThreadInfo( DWORD pid, DWORD tid, ThreadStats *info ) { PERF_COUNTER_DEFINITION *pid_counter; PERF_COUNTER_DEFINITION *tid_counter; PERF_COUNTER_DEFINITION *counter; PERF_INSTANCE_DEFINITION *inst; DWORD curid; DWORD i; BOOL error; error = FALSE; beginRead( FALSE ); initObj( ®Data, &threadObject, N_THREAD ); if( threadObject == NULL ) { error = TRUE; } if( !error ) { pid_counter = findCounter( threadObject, N_PROCID ); tid_counter = findCounter( threadObject, N_THREADID ); if( pid_counter == NULL || tid_counter == NULL ) error = TRUE; } if( !error ) { inst = getFirstInstance( threadObject ); for( i=0; i < threadObject->NumInstances; i++ ) { if( inst == NULL ) { error = TRUE; break; } curid = getCounterDWORD( inst, tid_counter ); if( curid == tid ) { curid = getCounterDWORD( inst, pid_counter ); if( curid == pid ) break; } inst = getNextInstance( inst ); } } if( !error && i == threadObject->NumInstances ) { error = TRUE; } else { info->tid = tid; info->pid = pid; counter = findCounter( threadObject, N_BASE_PRIORITY ); info->base_pri = getCounterDWORD( inst, counter ); counter = findCounter( threadObject, N_CUR_PRIORITY ); info->cur_pri = getCounterDWORD( inst, counter ); counter = findCounter( threadObject, N_THREAD_STATE ); info->state = getCounterDWORD( inst, counter ); counter = findCounter( threadObject, N_WAIT_REASON ); info->wait_reason = getCounterDWORD( inst, counter ); } endRead( FALSE ); return( !error ); }
/* * getProcessIndex */ static BOOL getProcessIndex( DWORD pid, DWORD *indexout ) { DWORD curpid; PERF_COUNTER_DEFINITION *counter; PERF_INSTANCE_DEFINITION *inst; DWORD index; counter = findCounter( processObject, N_PROCID ); if( counter == NULL ) return( FALSE ); inst = getFirstInstance( processObject ); if( inst == NULL ) return( FALSE ); for( index=0; index < processObject->NumInstances; index++ ) { if( inst == NULL ) break; curpid = getCounterDWORD( inst, counter ); if( curpid == pid ) { *indexout = index; return( TRUE ); } inst = getNextInstance( inst ); } return( FALSE ); }
void Stats::addToCounter( const QString& name, float value ) { int index = findCounter(name); if (index == -1) { index = _records[COUNTER].size(); Record newcounter; newcounter.name = name; newcounter.category = COUNTER; newcounter.value = value; newcounter.parent = &_headers[COUNTER]; _records[COUNTER].append(newcounter); _headers[COUNTER].children.append(&(_records[COUNTER][index])); _layout_changed = true; } else { _records[COUNTER][index].value += value; _data_changed = true; } _records[COUNTER][index].touches_since_last_reset++; }
bool Hwmon::claimCounter(const Counter &counter) const { return findCounter(counter) != NULL; }
/* * GetMemInfo */ BOOL GetMemInfo( DWORD procid, MemInfo *info ) { PERF_COUNTER_DEFINITION *counter; PERF_INSTANCE_DEFINITION *inst; DWORD curpid; DWORD i; beginRead( TRUE ); initObj( &costlyData, &procAddrObject, N_PROCESS_ADDR_SPACE ); if( procAddrObject == NULL ) { info->modlist = NULL; info->modcnt = 0; goto GETMEMINFO_ERROR; } info->modlist = GetModuleList( procid, &info->modcnt ); if( info->modlist == NULL ) goto GETMEMINFO_ERROR; counter = findCounter( procAddrObject, N_PROCID ); if( counter == NULL ) goto GETMEMINFO_ERROR; inst = getFirstInstance( procAddrObject ); for( i=0; ; i++ ) { if( i >= procAddrObject->NumInstances || inst == NULL ) { goto GETMEMINFO_ERROR; } curpid = getCounterDWORD( inst, counter ); if( curpid == procid ) break; inst = getNextInstance( inst ); } counter = findCounter( procAddrObject, N_MAP_SPACE_NO_ACC ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->mapped.noaccess = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_MAP_SPACE_READ ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->mapped.read = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_MAP_SPACE_WRITE ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->mapped.write = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_MAP_SPACE_COPY ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->mapped.copy = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_MAP_SPACE_EXEC ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->mapped.exec = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_MAP_SPACE_EXECREAD ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->mapped.execread = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_MAP_SPACE_EXECWRITE ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->mapped.execwrite = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_MAP_SPACE_EXECCOPY ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->mapped.execcopy = getCounterDWORD( inst, counter ); info->mapped.tot = info->mapped.noaccess + info->mapped.read + info->mapped.write + info->mapped.copy + info->mapped.exec + info->mapped.execread + info->mapped.execwrite + info->mapped.execcopy; counter = findCounter( procAddrObject, N_RES_SPACE_NO_ACC ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->res.noaccess = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_RES_SPACE_READ ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->res.read = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_RES_SPACE_WRITE ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->res.write = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_RES_SPACE_COPY ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->res.copy = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_RES_SPACE_EXEC ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->res.exec = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_RES_SPACE_EXECREAD ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->res.execread = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_RES_SPACE_EXECWRITE ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->res.execwrite = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_RES_SPACE_EXECCOPY ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->res.execcopy = getCounterDWORD( inst, counter ); info->res.tot = info->res.noaccess + info->res.read + info->res.write + info->res.copy + info->res.exec + info->res.execread + info->res.execwrite + info->res.execcopy; counter = findCounter( procAddrObject, N_IMAGE_SPACE_NO_ACC ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->image.noaccess = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_IMAGE_SPACE_READ ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->image.read = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_IMAGE_SPACE_WRITE ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->image.write = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_IMAGE_SPACE_COPY ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->image.copy = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_IMAGE_SPACE_EXEC ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->image.exec = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_IMAGE_SPACE_EXECREAD ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->image.execread = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_IMAGE_SPACE_EXECWRITE ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->image.execwrite = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_IMAGE_SPACE_EXECCOPY ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->image.execcopy = getCounterDWORD( inst, counter ); info->image.tot = info->image.noaccess + info->image.read + info->image.write + info->image.copy + info->image.exec + info->image.execread + info->image.execwrite + info->image.execcopy; endRead( TRUE ); return( TRUE ); GETMEMINFO_ERROR: FreeModuleList( info->modlist, info->modcnt ); endRead( TRUE ); return( FALSE ); }
/* * GetImageMemInfo */ BOOL GetImageMemInfo( DWORD procid, char *imagename, MemByType *imageinfo ) { DWORD index; DWORD i; BOOL ret; char buf[ _MAX_PATH ]; PERF_COUNTER_DEFINITION *counter; PERF_INSTANCE_DEFINITION *inst; ret = FALSE; beginRead( FALSE ); beginRead( TRUE ); initObj( &costlyData, &imageObject, N_IMAGE ); initObj( ®Data, &processObject, N_PROCESS ); if( imageObject == NULL || processObject == NULL ) goto GETIMAGEMEM_ERROR; inst = getFirstInstance( imageObject ); if( !getProcessIndex( procid, &index ) ) goto GETIMAGEMEM_ERROR; for( i=0; i < imageObject->NumInstances; i += 1 ) { if( inst == NULL ) goto GETIMAGEMEM_ERROR; if( inst->ParentObjectInstance == index ) { wsprintf( buf, "%ls", (char *)inst + inst->NameOffset ); if( !strcmp( buf, imagename ) ) { counter = findCounter( imageObject, N_NO_ACCESS ); if( counter == NULL ) goto GETIMAGEMEM_ERROR; imageinfo->noaccess = getCounterDWORD( inst, counter ); counter = findCounter( imageObject, N_READ_ONLY ); if( counter == NULL ) goto GETIMAGEMEM_ERROR; imageinfo->read = getCounterDWORD( inst, counter ); counter = findCounter( imageObject, N_READ_WRITE ); if( counter == NULL ) goto GETIMAGEMEM_ERROR; imageinfo->write = getCounterDWORD( inst, counter ); counter = findCounter( imageObject, N_WRITE_COPY ); if( counter == NULL ) goto GETIMAGEMEM_ERROR; imageinfo->copy = getCounterDWORD( inst, counter ); counter = findCounter( imageObject, N_EXEC ); if( counter == NULL ) goto GETIMAGEMEM_ERROR; imageinfo->exec = getCounterDWORD( inst, counter ); counter = findCounter( imageObject, N_EXEC_READ ); if( counter == NULL ) goto GETIMAGEMEM_ERROR; imageinfo->execread = getCounterDWORD( inst, counter ); counter = findCounter( imageObject, N_EXEC_WRITE ); if( counter == NULL ) goto GETIMAGEMEM_ERROR; imageinfo->execwrite = getCounterDWORD( inst, counter ); counter = findCounter( imageObject, N_EXEC_COPY ); if( counter == NULL ) goto GETIMAGEMEM_ERROR; imageinfo->execcopy = getCounterDWORD( inst, counter ); imageinfo->tot = imageinfo->noaccess + imageinfo->read + imageinfo->write + imageinfo->copy + imageinfo->exec + imageinfo->execread + imageinfo->execwrite + imageinfo->execcopy; ret = TRUE; break; } } inst = getNextInstance( inst ); } endRead( TRUE ); endRead( FALSE ); return( ret); GETIMAGEMEM_ERROR: endRead( TRUE ); endRead( FALSE ); return( FALSE ); }
bool PerfDriver::claimCounter(const Counter &counter) const { return findCounter(counter) != NULL; }