Пример #1
0
void RefleshThread::refleshSysTab()
{
    CpuStat cpuinfo[5][2];
    CpuRate rate;

    for (int i=0;i<5;i++)
    {
        cpuinfo[i][0] = CpuStat(getCpuInfo(i+1));
    }
    usleep(100000);
    for (int i=0;i<5;i++)
    {
        cpuinfo[i][1] = CpuStat(getCpuInfo(i+1));
        rate.cpu[i] = 100-100*(cpuinfo[i][1].idle-cpuinfo[i][0].idle)/(double)(cpuinfo[i][1].sum - cpuinfo[i][0].sum);
    }

    std::cout << rate.cpu[0] << "  " << rate.cpu[1] << "  " << rate.cpu[2] << "  " << rate.cpu[3] << "  " << rate.cpu[4] << endl;

    emit reflesh2(rate);


    int memfree;
    int swapfree;
    QString buf = getInfoByField("/proc/meminfo","MemFree");
    sscanf(buf.toStdString().c_str(),"%d",&memfree);
    buf = getInfoByField("/proc/meminfo","SwapFree");
    sscanf(buf.toStdString().c_str(),"%d",&swapfree);

    emit reflesh3(memfree,swapfree);
}
String SystemStats::getCpuVendor()
{
    auto v = getCpuInfo ("vendor_id");

    if (v.isEmpty())
        v = getCpuInfo ("model name");

    return v;
}
Пример #3
0
void LoadInfo::init()
{
    QVBoxLayout *vb = new QVBoxLayout( this );

    QString cpuInfo = getCpuInfo();
    if ( !cpuInfo.isNull() )
        vb->addWidget( new QLabel( cpuInfo, this ) );
    vb->addWidget( new Load( this ), 100 );

    QHBoxLayout *hb = new QHBoxLayout;
    vb->addLayout(hb);
    QLabel *l = new QLabel( this );
    l->setPixmap( makeLabel( Qt::red ) );
    hb->addWidget( l );
    l = new QLabel(tr("Application CPU (%)"), this );
    hb->addWidget( l );
    hb->addStretch(20);

    hb = new QHBoxLayout;
    vb->addLayout(hb);
    l = new QLabel( this );
    l->setPixmap( makeLabel( Qt::green ) );
    hb->addWidget( l, 1 );
    l = new QLabel(tr("System CPU (%)"), this );
    hb->addWidget( l );
    hb->addStretch(20);
    vb->addStretch(50);
}
//==============================================================================
void CPUInformation::initialise() noexcept
{
    auto flags = getCpuInfo ("flags");
    hasMMX   = flags.contains ("mmx");
    hasSSE   = flags.contains ("sse");
    hasSSE2  = flags.contains ("sse2");
    hasSSE3  = flags.contains ("sse3");
    has3DNow = flags.contains ("3dnow");
    hasSSSE3 = flags.contains ("ssse3");
    hasSSE41 = flags.contains ("sse4_1");
    hasSSE42 = flags.contains ("sse4_2");
    hasAVX   = flags.contains ("avx");
    hasAVX2  = flags.contains ("avx2");

    numLogicalCPUs  = getCpuInfo ("processor").getIntValue() + 1;

    // Assume CPUs in all sockets have the same number of cores
    numPhysicalCPUs = getCpuInfo ("cpu cores").getIntValue() * (getCpuInfo ("physical id").getIntValue() + 1);

    if (numPhysicalCPUs <= 0)
        numPhysicalCPUs = numLogicalCPUs;
}
cpuInfo::cpuInfo(QWidget *parent) : QWidget(parent)
{
    // assigning memory to Label for ahowing processors Information
    CPUInfo = new QLabel(tr("<b>Hardware</b>"));
    ramInfo = new QLabel();
    user    = new QLabel();
    operatingSys = new QLabel();
    release  = new QLabel();
    kernelInfo = new QLabel();

    // Calling program to calculate system information
    getCpuInfo();
    getRamInfo();
    getOsInfo();

    // defining the layout structure
    // structure is a horizontal box containing one vertical box with a stretch in front
    // so that the information is not sticked to left wall
    CpuInfoLayout = new QHBoxLayout();           // horizontal box layout
    innerSetting1 = new QVBoxLayout();              // vertical box 2 whixh contains the data
    innerSetting1->addSpacing(4);
    innerSetting1->addWidget(user);
    innerSetting1->addSpacing(4);
    innerSetting1->addWidget(operatingSys);
    innerSetting1->addWidget(release);
    innerSetting1->addWidget(kernelInfo);
    innerSetting1->addSpacing(20);
    innerSetting1->addWidget(CPUInfo);       // Adding label to the layout
    innerSetting1->addWidget(ramInfo);

    // adding QLabel to the layout depending on the number of processors present in system
    for(int i=0; i<processorInfo.size(); ++i)
    {
         innerSetting1->addWidget(processorInfo.at(i));
         innerSetting1->addSpacing(0);
     }
    innerSetting1->addStretch();

    // adding layouts to tha main layout
    CpuInfoLayout->addStretch();
    CpuInfoLayout->addLayout(innerSetting1);
    CpuInfoLayout->addStretch();

    // setting the layout of the parent widget
    setLayout(CpuInfoLayout);
}
Пример #6
0
LoadInfo::LoadInfo( QWidget *parent, const char *name, WFlags f )
    : QWidget( parent, name, f )
{
    QVBoxLayout *vb = new QVBoxLayout( this, 6 );

    QString cpuInfo = getCpuInfo();
    if ( !cpuInfo.isNull() )
	vb->addWidget( new QLabel( cpuInfo, this ) );
    vb->addWidget( new Load( this ), 100 );
    QLabel *l = new QLabel( this );
    l->setPixmap( makeLabel( red, tr("Application CPU usage (%)") ) );
    vb->addWidget( l, 1 );
    l = new QLabel( this );
    l->setPixmap( makeLabel( green, tr("System CPU usage (%)") ) );
    vb->addWidget( l, 1 );
    vb->addStretch(50);

    QWhatsThis::add( this, tr( "This page shows how much this device's processor is being used." ) );
}
Пример #7
0
std::string
getDate::getInfo(int types)
{
    std::string retInfo;
    switch(types)
    {
        case cpuInfo:
            retInfo = getCpuInfo();
            break;

        case memInfo:
            retInfo = getMemInfo();
            break;

        case netInfo:
            retInfo = getNetInfo();
            break;
        
        case diskInfo:
            retInfo = getDiskInfo();
            break;
    }
    return retInfo;
}
int SystemStats::getCpuSpeedInMegaherz()
{
    return roundToInt (getCpuInfo ("cpu MHz").getFloatValue());
}
String SystemStats::getCpuModel()
{
    return getCpuInfo ("model name");
}
String SystemStats::getDeviceDescription()
{
    return getCpuInfo ("Hardware");
}
int
CAPerfCfg::initialize()
{
  // construct the CAPerfEvent objects from 
  //    CAProfileConfig::m_ctrEventList
  //    CAProfileConfig::m_samplingEventList

  uint64_t sampleType = 0;
  bool     sampleIdAll = false;
  bool     firstEvent = true;

  // initialze the m_cpuVec;
  int ret = getCpuInfo(&m_cpuVec);
  CA_DBG_PRINTF(3, "Number of CPUs : %d\n.", m_cpuVec.size());

  // For per-process get the target pid's thread list;
  // TODO: Not sure whether we need to maintain per process CAThreadVec.
  // It may be a problem during PERF fd redirect ??
  size_t numPids;
  pid_t  *pids;
  if (! m_pmuTgt.isSWP()) {
    m_pmuTgt.getPids(&numPids, &pids);

    for (int i = 0; i < numPids; i++) {
      ret = getThreadList(pids[i], &m_threadVec);
    }
  }

  // TODO: check whether the cpu-list in the pmutarget is valid or not ?

  // iterate over the counting event list...
  if (m_ctrEventList.size() != 0) {
    CAEventList::iterator iter = m_ctrEventList.begin();
    for (; iter != m_ctrEventList.end(); iter++) {
      CAPerfEvent evt(*iter, this);

      m_ctrPerfEventList.push_back(evt);
    }
  }
  m_nbrCtrPerfEvents = m_ctrPerfEventList.size();

  if (m_samplingEventList.size() != 0) {
    CAEventList::iterator iter = m_samplingEventList.begin();
    for (; iter != m_samplingEventList.end(); iter++) {
      CAPerfEvent evt(*iter, this);

      if (! firstEvent) {
        evt.setPerfAttrMmap(false);
#ifdef LINUX_PERF_MMAP_DATA_SUPPORT
        evt.setPerfAttrMmapData(false);
#endif
        evt.setPerfAttrComm(false);
      }
      firstEvent = false;

      m_samplingPerfEventList.push_back(evt);

      sampleType = evt.getSampleType();
#ifdef LINUX_PERF_SAMPLE_ID_ALL_SUPPORT
      sampleIdAll = evt.getSampleIdAll();
#endif
    }
  }
  m_nbrSamplingPerfEvents = m_samplingPerfEventList.size();

  // FIXME;
  if (sampleType) {
    m_sampleRecSize = getSampleRecSize(sampleType, sampleIdAll);
  }

  // FIXME: just for testing
  ret = m_dataWriter.init((char *)(getOutputFile().c_str()),
			  isOverwrite());
  if (S_OK != ret) {
    CA_DBG_PRINTF(3, "initializing datafile failed... ret(%d)\n", ret);
    return E_FAIL;
  }
  CA_DBG_PRINTF(3, "initializing datafile succeedded...\n");

  return S_OK;
}