Exemplo n.º 1
0
static int HostStatsFetchData(void)
{
  DWORD o;
  PPERF_OBJECT_TYPE objPtr = NULL;
  DWORD res;
  DWORD oldBufferSize = BufferSize;
  const char * qstr;
  qstr = LEVEL1_QUERY_STRING;

  while ((res = RegQueryValueEx(HKEY_PERFORMANCE_DATA, qstr,
				NULL, NULL,
				(LPBYTE)PerfData,
				&BufferSize)) == ERROR_MORE_DATA) {
    oldBufferSize += 4096;
    BufferSize = oldBufferSize;
    PerfData = (PPERF_DATA_BLOCK)realloc(PerfData, BufferSize);
    }
  if (res != ERROR_SUCCESS) {
    fprintf(stderr,
        "Can't get Windows performance data. RegQueryValueEx returned %ld, errorno \"%d\"\n",
        GetLastError(),
	res);
    return -1;
    }
#ifdef NTDBG
  fprintf(stderr, "buffersize is %ld\n", BufferSize);
  fflush(stderr);
#endif

  ProcessObj = NULL;
  ProcessorObj = NULL;
  MemoryObj = NULL;
  SystemObj = NULL;
  ObjectsObj = NULL;

  objPtr = FirstObject(PerfData);
  for (o=0; o < PerfData->NumObjectTypes; o++) {
#ifdef NTDBG
    fprintf(stderr, "Object %ld\n", objPtr->ObjectNameTitleIndex);
    fflush(stderr);
#endif
    switch (objPtr->ObjectNameTitleIndex) {
      case PROCESS_OBJ_ID: ProcessObj = objPtr; break;
      case PROCESSOR_OBJ_ID: ProcessorObj = objPtr; break;
      case MEMORY_OBJ_ID: MemoryObj = objPtr; break;
      case SYSTEM_OBJ_ID: SystemObj = objPtr; break;
      case OBJECTS_OBJ_ID: ObjectsObj = objPtr; break;
      case NETWORK_OBJ_ID: NetworkObj = objPtr; break;
      case UDP_OBJ_ID: UdpObj = objPtr; break;
      }
    objPtr = NextObject(objPtr);
    }
  if ( ProcessObj == NULL ||
       ProcessorObj == NULL ||
       MemoryObj == NULL ||
       SystemObj == NULL ||
       ObjectsObj == NULL ||
       NetworkObj == NULL ||
       UdpObj == NULL )
  {
    return -1;
  }
  loadProcessData();
  loadProcessorData();
  loadSystemData();
  loadMemoryData();
  loadObjectData();
  loadUdpData();
  loadCpuData();
  loadNetworkData();
  return 0;
}
Exemplo n.º 2
0
/*!
  Passes service directed to plugins on to the correct plugin.
*/
void InfoLogger::performLogService(TasCommandModel& model, TasResponse& response)
{
    TasTarget* target = model.findTarget(APPLICATION_TARGET);
    if(!mTimer.isActive() && model.interval() > 100){
        mTimer.setInterval(model.interval());
    }
    if(target){
        TasCommand* command = target->findCommand(CPU);
        if(command){
            if(command->parameter(ACTION) == "start"){
                QString fileName;
                if(!makeFileName(command, CPU, fileName)){
                    response.setErrorMessage("File path must be defined for cpu logging!");
                }
                else{
                    mLastCpuTime = mDeviceUtils->currentProcessCpuTime();
                    mInterval.start();
                    mState |= CpuLogging;     
                    if(mCpu){
                        delete mCpu;
                        mCpu = 0;
                    }
                    mCpu = openFile(fileName, command);
                }
            }
            else if(command->parameter(ACTION) == "stop" || command->parameter(ACTION) == "load"){
                loadCpuData(response, command);
            }
        }
        command = target->findCommand(MEM);
        if(command){
            if(command->parameter(ACTION) == "start"){
                QString fileName;
                if(!makeFileName(command, MEM, fileName)){
                    response.setErrorMessage("File path must be defined for mem logging!");
                }
                else{
                    mState |= MemLogging;
                    if(mMem){
                        delete mMem;
                        mMem = 0;
                    }
                    mMem = openFile(fileName, command);
                }
            }
            else if(command->parameter(ACTION) == "stop" || command->parameter(ACTION) == "load"){
                loadMemData(response, command);
            }

        }
        command = target->findCommand(GPU);
        if(command){
            if(command->parameter(ACTION) == "start"){
                QString fileName;
                if(!makeFileName(command, GPU, fileName)){
                    response.setErrorMessage("File path must be defined for mem logging!");
                }
                else{
                    mState |= GpuLogging;
                    if(mGpu){
                        delete mGpu;
                        mGpu = 0;
                    }
                    mGpu = openFile(fileName, command);
                }

            }
            else if(command->parameter(ACTION) == "stop" || command->parameter(ACTION) == "load"){
                loadGpuData(response, command);
            }

        }
        command = target->findCommand(PWR);
        if(command){
            if(command->parameter(ACTION) == "start"){
                QString fileName;
                if(!makeFileName(command, PWR, fileName)){
                    response.setErrorMessage("File path must be defined for pwr logging!");
                }
                else{
                    mState |= PwrLogging;
                    if(mPwr){
                        delete mPwr;
                        mPwr = 0;
                    }
                    mPwr = openFile(fileName, command);
                }
                //to launch measuring if not running
                mDeviceUtils->pwrDetails();
            }
            else if(command->parameter(ACTION) == "stop" || command->parameter(ACTION) == "load"){
                loadPwrData(response, command);
                if(command->parameter(ACTION) == "stop" ){
                    mDeviceUtils->stopPwrData();
                }
            }

        }
        //determines that does the interval need to be started or stopped
        checkLoggerState();
    }
}