/* * 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 ); }
CIFCEngineInteract::~CIFCEngineInteract() { //Delete the linked list if( getFirstInstance() != NULL) { STRUCT_INSTANCES * instance = getFirstInstance(); STRUCT_INSTANCES * temp = NULL; while( instance ) { temp = instance; instance = instance->next; delete temp; } this->m_firstInstance = NULL; this->m_lastInstance = NULL; temp = NULL; } //free(g_pIndices); //free(g_pVertices); }
/* * 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 ); }
void CIFCEngineInteract::destroyManually() { //Delete the linked list if(getFirstInstance() != NULL) { STRUCT_INSTANCES * instance = getFirstInstance(); STRUCT_INSTANCES * temp = NULL; //Used to delete the parent STRUCT_INSTANCES *parentTemp = NULL; while( instance ) { temp = instance; if(instance->parent) instance->parent = NULL; instance = instance->next; delete temp; } ///I nullified the last instance because when i use this method the m_lastInstance ///will contain a value which will make the addObject method to give a memory which the program ///doesn't own m_lastInstance = NULL; } }
/* * 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 ); }
/* * 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 ); }
/* * 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 ); }