Exemplo n.º 1
0
void DebugMetricsMonitor::updateMemoryUsage() {
#if defined(Q_OS_ANDROID)
    mMemoryUsage = AndroidActivity::getMemoryUsed();
#elif defined(Q_OS_MACX)
    struct task_basic_info taskInfo;
    mach_msg_type_number_t taskInfoCount = TASK_BASIC_INFO_COUNT;
    if (task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t) &taskInfo, &taskInfoCount)
            != KERN_SUCCESS)
    {
        qDebug() << "Kernel error when retrieving basic task info.";
        mMemoryUsage = -1;
    } else {
        // NOTE: On Mac OSX, the resident_size and virtual_size is in bytes, not pages,
        // which differs from the GNU Mach kernel.
        mMemoryUsage = taskInfo.resident_size;
    }
#elif defined(Q_OS_LINUX)  || defined(Q_OS_UNIX)
    QFile procInfoFile("/proc/self/statm");
    procInfoFile.open(QIODevice::ReadOnly | QIODevice::Text);
    QString procInfo = procInfoFile.readAll();
    procInfoFile.close();
    // Memory info prints number of resident 4KB memory pages in the second column
    // See: http://man7.org/linux/man-pages/man5/proc.5.html
    // NOTE: This number is not accurate past the nearest 4KB.
    mMemoryUsage = procInfo.split(QRegExp("\\s"))[1].toLong() * 4 * 1000;
#else
    // Guaranteed not to be Android,Linux,UNIX or Mac.

#endif

    if (mLoggingMetrics) {
        qDebug() << "Memory Usage:" << (mMemoryUsage / 1000000.0) << "MB";
    }
    emit memoryUsageChanged();
}
Exemplo n.º 2
0
void Shell::setMemoryUsage(int memoryUsage)
{
	if (m_memoryUsage == memoryUsage)
		return;

	m_memoryUsage = memoryUsage;
	emit memoryUsageChanged(memoryUsage);
}
/**
  \brief UserManager Main Ui interface.
  \internal
  \ingroup widget_usertoolkit usertoolkit usermanager
*/
tkUserManagerPrivate::tkUserManagerPrivate( QMainWindow * parent )
    : QObject( parent ),
    m_PermanentMemoryUsage(0),
    m_PermanentUserName(0),
    m_PermanentWidget(0),
    groupBoxMemoryUsage(0)
{
    m_Parent = parent;
    m_SearchBy = User::UserName;
    setupUi( parent );

    toolBar->addActions( menuUser_manager->actions() );
    // insert central widget
    QWidget * central = new QWidget( parent );
    QVBoxLayout * vb = new QVBoxLayout( central );
    //    vb->setMargin( 5 );
    QSplitter * split = new QSplitter( central );

    // Prepare left widget
    QWidget * left = new QWidget( central );
    QVBoxLayout * vbleft = new QVBoxLayout( left );
    vbleft->setSpacing( 10 );
    vbleft->setMargin( 0 );
    m_UserTableView = new QTableView( left );
    m_UserTableView->setEditTriggers( QAbstractItemView::NoEditTriggers );
    tkUserModel * model = tkUserModel::instance();
    m_UserTableView->setModel( model );
    m_UserTableView->horizontalHeader()->hide();
    m_UserTableView->verticalHeader()->hide();
    m_UserTableView->hideColumn( USER_ID );
    m_UserTableView->hideColumn( USER_UUID );
    m_UserTableView->hideColumn( USER_LOGIN );
    m_UserTableView->hideColumn( USER_PASSWORD );
    m_UserTableView->hideColumn( USER_LANGUAGE );
    m_UserTableView->hideColumn( USER_MAIL );
    m_UserTableView->hideColumn( USER_VALIDITY );
    m_UserTableView->hideColumn( USER_SECONDNAME );
    m_UserTableView->hideColumn( USER_LASTLOG );
    m_UserTableView->hideColumn( USER_LOCKER );
    m_UserTableView->resizeColumnsToContents();
    m_UserTableView->setSelectionMode( QAbstractItemView::SingleSelection );
    m_UserTableView->setSelectionBehavior( QAbstractItemView::SelectRows );
    // prepare Search Line Edit
    m_SearchEdit = new QButtonLineEdit( left );
    m_SearchToolBut = new QToolButton( m_SearchEdit );
    m_SearchEdit->setLeftButton( m_SearchToolBut );
    searchByNameAct = new QAction( m_SearchToolBut );
    searchBySurnameAct = new QAction( m_SearchToolBut );
    searchByNameAndSurnameAct = new QAction( m_SearchToolBut );
    searchByCityAct = new QAction( m_SearchToolBut );
    m_SearchToolBut->addAction( searchByNameAct );
    m_SearchToolBut->addAction( searchBySurnameAct );
    //    m_SearchToolBut->addAction( searchByNameAndSurnameAct );
    //    m_SearchToolBut->addAction( searchByCityAct );
    m_SearchToolBut->setPopupMode( QToolButton::InstantPopup );
    // group memory usage
    groupBoxMemoryUsage = new QGroupBox(left);
    QVBoxLayout *groupLayout = new QVBoxLayout(groupBoxMemoryUsage);
    m_PermanentMemoryUsage = new QLabel( m_PermanentWidget );
    groupLayout->addWidget( m_PermanentMemoryUsage );
    retranslate();

    // populate left widget layout
    vbleft->addWidget( m_SearchEdit );
    vbleft->addWidget( m_UserTableView );
    vbleft->addWidget( groupBoxMemoryUsage );
    selectUserTableView( tkUserModel::instance()->currentUserIndex().row() );

    // create center user viewer
    m_UserViewer = new tkUserViewer( central );
    split->addWidget( left );
    split->addWidget( m_UserViewer );
    split->setStretchFactor( 0, 1 );
    split->setStretchFactor( 1, 3 );
    vb->addWidget( split );

    analyseCurrentUserRights();

    //    userTableView->hide();
    parent->setCentralWidget( central );
    saveAct->setShortcut( QKeySequence::Save );
    createNewUserAct->setShortcut( QKeySequence::New );

    // connect slots
    connect( saveAct, SIGNAL(triggered()), this, SLOT(on_saveAct_triggered()) );
    connect( createNewUserAct, SIGNAL(triggered()), this, SLOT(on_createNewUserAct_triggered()) );
    connect( clearModificationsAct, SIGNAL(triggered()), this, SLOT(on_clearModificationsAct_triggered()) );
    connect( deleteUserAct,  SIGNAL(triggered()), this, SLOT(on_deleteUserAct_triggered()) );
    connect( quitUserManagerAct,  SIGNAL(triggered()), m_Parent, SLOT(close()) );
    connect( m_UserTableView, SIGNAL( activated( const QModelIndex & ) ),
             this, SLOT( on_userTableView_activated( const QModelIndex & ) ) );
    // connections for search line edit
    connect( m_SearchEdit, SIGNAL(textChanged(const QString &)), this, SLOT( on_m_SearchEdit_textchanged() ) );
    connect( m_SearchToolBut, SIGNAL(triggered(QAction*)), this, SLOT(on_m_SearchToolButton_triggered(QAction*)) );

    updateStatusBar();
    connect( tkUserModel::instance(), SIGNAL(memoryUsageChanged()), this, SLOT(updateStatusBar()) );

    // manage theme / icons
    parent->setWindowIcon( tkTheme::icon( ICONUSERMANAGER ) );
    saveAct->setIcon( tkTheme::icon( ICONSAVE, tkTheme::MediumIcon ) );
    createNewUserAct->setIcon( tkTheme::icon( ICONNEWUSER, tkTheme::MediumIcon ) );
    modifyUserAct->setIcon( tkTheme::icon( ICONEDITUSER, tkTheme::MediumIcon ) );
    clearModificationsAct->setIcon( tkTheme::icon( ICONCLEARUSER, tkTheme::MediumIcon ) );
    deleteUserAct->setIcon( tkTheme::icon( ICONDELETEUSER, tkTheme::MediumIcon ) );
    quitUserManagerAct->setIcon( tkTheme::icon( ICONEXIT, tkTheme::MediumIcon ) );
    m_SearchToolBut->setIcon( tkTheme::icon( ICONSEARCH ) );
    searchByNameAct->setIcon( tkTheme::icon( ICONSEARCH ) );
    searchBySurnameAct->setIcon( tkTheme::icon( ICONSEARCH ) );
    searchByNameAndSurnameAct->setIcon( tkTheme::icon( ICONSEARCH ) );
    searchByCityAct->setIcon( tkTheme::icon( ICONSEARCH ) );

    // TODO active userTableView on currentUser
}