piintrospector fixes and optimization

This commit is contained in:
2022-04-14 17:45:37 +03:00
parent e92556e744
commit 8b23709991
3 changed files with 29 additions and 19 deletions

View File

@@ -34,8 +34,8 @@ void ContainersModel::update(const PIVector<PIIntrospectionContainers::TypeInfo>
}
piForeachC (PIIntrospectionContainers::TypeInfo & i, t) {
all[ccCount] += i.count;
all[ccBytesAllocated] += i.allocated * i.item_size;
all[ccBytesUsed] += i.used * i.item_size;
all[ccBytesAllocated] += i.allocated_bytes;
all[ccBytesUsed] += i.used_bytes;
}
int pts = cur_data.size_s();
cur_data = t;
@@ -112,22 +112,20 @@ QVariant ContainersModel::data(const QModelIndex & index, int role) const {
case ccType: return PI2QString(t.name);
case ccItemSize:
if (role == Qt::UserRole) return t.item_size;
return PI2QString(PIString::readableSize(t.item_size));
return PI2QString(t.item_size_str);
default: break;
}
if (mode_changes) {
switch (index.column()) {
case ccCount: return int(t.count) - int(prev_data.value(id).count);
case ccBytesAllocated:
v = t.allocated;
v -= prev_data.value(id).allocated;
v *= t.item_size;
v = t.allocated_bytes;
v -= prev_data.value(id).allocated_bytes;
if (role == Qt::UserRole) return piAbs(v);
return PI2QString(PIString::readableSize(v));
case ccBytesUsed:
v = t.used;
v -= prev_data.value(id).used;
v *= t.item_size;
v = t.used_bytes;
v -= prev_data.value(id).used_bytes;
if (role == Qt::UserRole) return piAbs(v);
return PI2QString(PIString::readableSize(v));
}
@@ -135,13 +133,11 @@ QVariant ContainersModel::data(const QModelIndex & index, int role) const {
switch (index.column()) {
case ccCount: return t.count;
case ccBytesAllocated:
v = t.allocated * t.item_size;
if (role == Qt::UserRole) return v;
return PI2QString(PIString::readableSize(v));
if (role == Qt::UserRole) return t.allocated_bytes;
return PI2QString(t.allocated_str);
case ccBytesUsed:
v = t.used * t.item_size;
if (role == Qt::UserRole) return v;
return PI2QString(PIString::readableSize(v));
if (role == Qt::UserRole) return t.used_bytes;
return PI2QString(t.used_str);
}
}
}
@@ -191,8 +187,8 @@ int cmp_func_name_d(const PIIntrospectionContainers::TypeInfo * t0, const PIIntr
#endif
CMP_FUNC(item_size)
CMP_FUNC(count)
CMP_FUNC(allocated)
CMP_FUNC(used)
CMP_FUNC(allocated_bytes)
CMP_FUNC(used_bytes)
#undef CMP_FUNC
void ContainersModel::sort(int column, Qt::SortOrder order) {
ls_column = column;
@@ -204,11 +200,12 @@ void ContainersModel::sort(int column, Qt::SortOrder order) {
case ccType : cf = order == Qt::AscendingOrder ? cmp_func_name_a : cmp_func_name_d ; pf = print_func_name; break;
case ccItemSize : cf = order == Qt::AscendingOrder ? cmp_func_item_size_a : cmp_func_item_size_d; pf = print_func_item_size; break;
case ccCount : cf = order == Qt::AscendingOrder ? cmp_func_count_a : cmp_func_count_d ; pf = print_func_count; break;
case ccBytesAllocated: cf = order == Qt::AscendingOrder ? cmp_func_allocated_a : cmp_func_allocated_d; pf = print_func_allocated; break;
case ccBytesUsed : cf = order == Qt::AscendingOrder ? cmp_func_used_a : cmp_func_used_d ; pf = print_func_used; break;
case ccBytesAllocated: cf = order == Qt::AscendingOrder ? cmp_func_allocated_bytes_a : cmp_func_allocated_bytes_d; pf = print_func_allocated_bytes; break;
case ccBytesUsed : cf = order == Qt::AscendingOrder ? cmp_func_used_bytes_a : cmp_func_used_bytes_d ; pf = print_func_used_bytes; break;
default : break;
}
if (cf) {
qDebug() << "\nsrc" << column << order;
cur_data.forEach(pf);
cur_data.sort(cf);
qDebug() << "sort" << column << order;

View File

@@ -157,6 +157,17 @@ QString QPIIntrospector::durationStr(PISystemTime t) {
}
void QPIIntrospector::prepareContainers(PIVector<PIIntrospectionContainers::TypeInfo> & data) {
for (PIIntrospectionContainers::TypeInfo & i: data) {
i.allocated_bytes = i.allocated * i.item_size;
i.used_bytes = i.used * i.item_size;
i.item_size_str.setReadableSize(i.item_size);
i.allocated_str.setReadableSize(i.allocated_bytes);
i.used_str.setReadableSize(i.used_bytes);
}
}
void QPIIntrospector::on_listApp_currentRowChanged(int r) {
PIString cs;
if (r < 0) cs.clear();
@@ -192,6 +203,7 @@ void QPIIntrospector::peerReceived(const PIString & from, const PIByteArray & da
pba.clear(); cs.get(pba);
PIVector<PIIntrospectionContainers::TypeInfo> data;
PIIntrospection::unpackContainers(pba, data);
prepareContainers(data);
widgetContainers->showContainers(data);
} break;
case PIIntrospection::itObjects: {

View File

@@ -27,6 +27,7 @@ protected:
void buildDumpSection(QTreeWidgetItem * pi, PIString & str);
void showInfo();
QString durationStr(PISystemTime t);
void prepareContainers(PIVector<PIIntrospectionContainers::TypeInfo> & data);
EVENT_HANDLER2(void, peerReceived, const PIString &, from, const PIByteArray &, data);
EVENT_HANDLER1(void, peersChanged, const PIString &, name);