git-svn-id: svn://db.shs.com.ru/libs@563 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2019-06-26 17:34:07 +00:00
parent f02757a8ac
commit a840b5d61a
5 changed files with 103 additions and 50 deletions

View File

@@ -1,9 +1,10 @@
project(piintrospector)
file(GLOB SRC "*.h" "*.cpp" "*.ui" "*.qrc" "lang/*.ts")
pip_code_model(CCMPII "../../pip/src_main/introspection/piintrospection_server_p.h" OPTIONS "-DPIP_EXPORT" "-Es")
set(PII_ROOT "../../pip/src_main/introspection")
pip_code_model(CCM "${PII_ROOT}/piintrospection_server_p.h" "${PII_ROOT}/piintrospection_threads_p.h" OPTIONS "-DPIP_EXPORT" "-Es")
find_qt(${QtVersions} Core Gui)
qt_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM)
qt_add_executable(${PROJECT_NAME} WIN32 out_CPP CCMPII)
qt_add_executable(${PROJECT_NAME} WIN32 out_CPP CCM)
qt_target_link_libraries(${PROJECT_NAME} pip qad_utils qad_widgets qad_application piqt_utils)
message(STATUS "Building ${PROJECT_NAME}")
if(LIB)

View File

@@ -1,5 +1,7 @@
#include "containers_view.h"
#include <QTreeView>
#include <QPainter>
#include <QStyle>
#include <QSortFilterProxyModel>
#include <cxxabi.h>
@@ -29,7 +31,7 @@ ContainersModel::ContainersModel() {
prev_all.resize(all.size(), 0L);
}
#ifdef PIP_INTROSPECTION
void ContainersModel::update(const PIMap<uint, PIIntrospectionContainers::Type> & td, const PIMap<uint, PIString> & tn) {
prev_typedata = typedata;
typedata = td;
@@ -49,14 +51,12 @@ void ContainersModel::update(const PIMap<uint, PIIntrospectionContainers::Type>
all[ccBytesAllocated] += i.value().bytes_allocated;
all[ccBytesUsed] += i.value().bytes_used;
}
dataChanged(index(1, 0), index(columnCount(), typeids.size_s() - 1));
emit headerDataChanged(Qt::Horizontal, 1, columnCount());
dataChanged(index(0, ccCount), index(typeids.size_s() - 1, columnCount()));
emit headerDataChanged(Qt::Horizontal, ccCount, columnCount());
}
#endif
void ContainersModel::clear() {
#ifdef PIP_INTROSPECTION
beginRemoveRows(QModelIndex(), 0, typeids.size_s() - 1);
typedata.clear();
prev_typedata.clear();
@@ -64,9 +64,9 @@ void ContainersModel::clear() {
typeids.clear();
all.fill(0L);
endRemoveRows();
#endif
}
int ContainersModel::rowCount(const QModelIndex & parent) const {
return typeids.size_s();
}
@@ -78,9 +78,7 @@ int ContainersModel::columnCount(const QModelIndex & parent) const {
QModelIndex ContainersModel::index(int row, int column, const QModelIndex & parent) const {
#ifdef PIP_INTROSPECTION
if (row >= typenames.size_s() || row >= typedata.size_s()) return QModelIndex();
#endif
return createIndex(row, column, typeids[row]);
}
@@ -110,40 +108,43 @@ QVariant ContainersModel::headerData(int section, Qt::Orientation orientation, i
QVariant ContainersModel::data(const QModelIndex & index, int role) const {
if (role != Qt::DisplayRole && role != Qt::UserRole) return QVariant();
#ifdef PIP_INTROSPECTION
if (role != Qt::DisplayRole && role != Qt::UserRole && role != (Qt::UserRole+1)) return QVariant();
uint id = uint(index.internalId());
llong v = 0L;
if (mode_changes) {
switch (index.column()) {
case ccType: return demangle(typenames.value(id).dataAscii());
case ccCount: return int(typedata.value(id).count) - int(prev_typedata.value(id).count);
case ccBytesAllocated:
v = typedata.value(id).bytes_allocated;
v -= prev_typedata.value(id).bytes_allocated;
if (role == Qt::UserRole) return piAbs(v);
return PI2QString(PIString::readableSize(v));
case ccBytesUsed:
v = typedata.value(id).bytes_used;
v -= prev_typedata.value(id).bytes_used;
if (role == Qt::UserRole) return piAbs(v);
return PI2QString(PIString::readableSize(v));
}
} else {
switch (index.column()) {
case ccType: return demangle(typenames.value(id).dataAscii());
case ccCount: return typedata.value(id).count;
case ccBytesAllocated:
v = typedata.value(id).bytes_allocated;
if (role == Qt::UserRole) return v;
return PI2QString(PIString::readableSize(v));
case ccBytesUsed:
v = typedata.value(id).bytes_used;
if (role == Qt::UserRole) return v;
return PI2QString(PIString::readableSize(v));
if (role == Qt::DisplayRole || role == Qt::UserRole) {
if (mode_changes) {
switch (index.column()) {
case ccType: return demangle(typenames.value(id).dataAscii());
case ccCount: return int(typedata.value(id).count) - int(prev_typedata.value(id).count);
case ccBytesAllocated:
v = typedata.value(id).bytes_allocated;
v -= prev_typedata.value(id).bytes_allocated;
if (role == Qt::UserRole) return piAbs(v);
return PI2QString(PIString::readableSize(v));
case ccBytesUsed:
v = typedata.value(id).bytes_used;
v -= prev_typedata.value(id).bytes_used;
if (role == Qt::UserRole) return piAbs(v);
return PI2QString(PIString::readableSize(v));
}
} else {
switch (index.column()) {
case ccType: return demangle(typenames.value(id).dataAscii());
case ccCount: return typedata.value(id).count;
case ccBytesAllocated:
v = typedata.value(id).bytes_allocated;
if (role == Qt::UserRole) return v;
return PI2QString(PIString::readableSize(v));
case ccBytesUsed:
v = typedata.value(id).bytes_used;
if (role == Qt::UserRole) return v;
return PI2QString(PIString::readableSize(v));
}
}
}
#endif
if (role == (Qt::UserRole+1) && (index.column() == ccCount)) {
return typedata.value(id).count;
}
return QVariant();
}
@@ -155,8 +156,27 @@ Qt::ItemFlags ContainersModel::flags(const QModelIndex & index) const {
void ContainersModel::setChangesMode(bool yes) {
mode_changes = yes;
dataChanged(index(1, 0), index(columnCount(), typeids.size_s() - 1));
emit headerDataChanged(Qt::Horizontal, 1, columnCount());
dataChanged(index(0, ccCount), index(typeids.size_s() - 1, columnCount()));
emit headerDataChanged(Qt::Horizontal, ccCount, columnCount());
}
void ContainersDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const {
QStyledItemDelegate::paint(painter, option, index);
if (model->index(index.row(), ccCount).data(Qt::UserRole+1).toInt() == 0) {
QColor col;
if (option.state == QStyle::State_Enabled ||
option.state == QStyle::State_HasFocus)
col = option.palette.color(QPalette::Active, QPalette::WindowText);
else
col = option.palette.color(QPalette::Disabled, QPalette::WindowText);
col.setAlphaF(0.5);
int y = option.rect.center().y() + (option.fontMetrics.height() / 2.5) - option.fontMetrics.strikeOutPos();
painter->setPen(QPen(col, lineThickness()));
painter->drawLine(QPoint(option.rect.left(), y), QPoint(option.rect.right(), y));
}
}
@@ -170,7 +190,8 @@ ContainersView::ContainersView(QWidget * parent): QWidget(parent) {
proxy->setSourceModel(model);
proxy->setSortRole(Qt::UserRole);
proxy->setDynamicSortFilter(false);
treeContainers->setModel(proxy);
treeContainers->setModel(model);
treeContainers->setItemDelegate(new ContainersDelegate(model));
}
@@ -189,11 +210,10 @@ void ContainersView::changeEvent(QEvent * e) {
}
}
#ifdef PIP_INTROSPECTION
void ContainersView::showContainers(const PIMap<uint, PIIntrospectionContainers::Type> & data, const PIMap<uint, PIString> & typenames) {
model->update(data, typenames);
}
#endif
void ContainersView::clear() {

View File

@@ -4,6 +4,8 @@
#include "ui_containers_view.h"
#include <QDebug>
#include <QWidget>
#include <QAbstractItemModel>
#include <QStyledItemDelegate>
#include "piqt.h"
#ifdef PIP_INTROSPECTION
# include "piintrospection_containers_p.h"
@@ -43,6 +45,14 @@ public slots:
};
class ContainersDelegate: public QStyledItemDelegate {
Q_OBJECT
public:
ContainersDelegate(QAbstractItemModel * m) {model = m;}
void paint(QPainter *painter, const QStyleOptionViewItem & option, const QModelIndex &index) const override;
QAbstractItemModel * model;
};
class ContainersView: public QWidget, private Ui::ContainersView
@@ -58,7 +68,6 @@ public:
protected:
void changeEvent(QEvent * e);
QStringList src_header;
ContainersModel * model;
private slots:

View File

@@ -125,25 +125,37 @@ void QPIIntrospector::peerReceived(const PIString & from, const PIByteArray & da
PIByteArray pba;
while (!cs.atEnd()) {
switch (cs.read()) {
case 1: {
case PIIntrospection::itInfo: {
cs.get(pba);
PIIntrospection::ProcessInfo info;
PIIntrospection::unpackInfo(pba, info);
showInfo(info);
} break;
case 2: {
case PIIntrospection::itProcStat: {
cs.get(pba);
PIIntrospection::ProcessStat stat;
PIIntrospection::unpackProcStat(pba, stat);
//showInfo(info);
} break;
case PIIntrospection::itContainers: {
cs.get(pba);
PIMap<uint, PIIntrospectionContainers::Type> data;
PIMap<uint, PIString> typenames;
PIIntrospection::unpackContainers(pba, data, typenames);
widgetContainers->showContainers(data, typenames);
} break;
case 4: {
case PIIntrospection::itObjects: {
cs.get(pba);
PIVector<PIIntrospection::ObjectInfo> objects;
PIIntrospection::unpackObjects(pba, objects);
widgetObjects->showObjects(objects);
} break;
case PIIntrospection::itThreads: {
cs.get(pba);
PIVector<PIIntrospectionThreads::ThreadInfo> threads;
PIIntrospection::unpackThreads(pba, threads);
widgetThreads->showThreads(threads);
} break;
default: break;
}
}

View File

@@ -124,7 +124,7 @@
<item>
<widget class="QTabWidget" name="tabWidgetMain">
<property name="currentIndex">
<number>1</number>
<number>3</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@@ -167,6 +167,11 @@
<attribute name="title">
<string>Threads</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="ThreadsView" name="widgetThreads" native="true"/>
</item>
</layout>
</widget>
</widget>
</item>
@@ -190,6 +195,12 @@
<header>containers_view.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ThreadsView</class>
<extends>QWidget</extends>
<header>threads_view.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>