mirror of
https://github.com/epasveer/seer.git
synced 2026-08-29 16:40:42 +08:00
Got rid of shared_ptr.
This commit is contained in:
@@ -144,12 +144,12 @@ QString SeerParallelStacksThread::toString() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
static std::shared_ptr<SeerParallelStacksStackNode> buildImpl(const QVector<SeerParallelStacksThread>& threads, const QString& currentFunction, int depth) {
|
||||
static SeerParallelStacksNode buildImpl(const QVector<SeerParallelStacksThread>& threads, const QString& currentFunction, int depth) {
|
||||
|
||||
auto node = std::make_shared<SeerParallelStacksStackNode>();
|
||||
node->depth = depth;
|
||||
node->function = currentFunction;
|
||||
node->threads = threads;
|
||||
SeerParallelStacksNode node;
|
||||
node.depth = depth;
|
||||
node.function = currentFunction;
|
||||
node.threads = threads;
|
||||
|
||||
// Group threads by the function at position [-depth-1] (bottom-up).
|
||||
QMap<QString, QVector<SeerParallelStacksThread>> functionThreads;
|
||||
@@ -157,6 +157,7 @@ static std::shared_ptr<SeerParallelStacksStackNode> buildImpl(const QVector<Seer
|
||||
int level = -depth - 1;
|
||||
|
||||
for (const SeerParallelStacksThread& t : threads) {
|
||||
|
||||
int idx = t.frames().size() + level; // convert negative index
|
||||
|
||||
if (idx < 0 || idx >= t.frames().size()) {
|
||||
@@ -170,45 +171,45 @@ static std::shared_ptr<SeerParallelStacksStackNode> buildImpl(const QVector<Seer
|
||||
|
||||
for (auto it = functionThreads.begin(); it != functionThreads.end(); ++it) {
|
||||
auto child = buildImpl(it.value(), it.key(), depth + 1);
|
||||
node->children.append(child);
|
||||
node.children.append(child);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
std::shared_ptr<SeerParallelStacksStackNode> SeerParallelStacksBuildParallelStacks(const QVector<SeerParallelStacksThread>& threads) {
|
||||
SeerParallelStacksNode SeerParallelStacksBuildParallelStacks(const QVector<SeerParallelStacksThread>& threads) {
|
||||
|
||||
return buildImpl(threads, QString(), 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// fillStack — flatten SeerParallelStacksStackNode tree into Stack tree for graphing
|
||||
// fillStack — flatten SeerParallelStacksNode tree into Stack tree for graphing
|
||||
// ---------------------------------------------------------------
|
||||
std::shared_ptr<SeerParallelStacksStack> SeerParallelStacksFillStack(const std::shared_ptr<SeerParallelStacksStackNode>& node) {
|
||||
SeerParallelStacksStack SeerParallelStacksFillStack(const SeerParallelStacksNode& node) {
|
||||
|
||||
auto stack = std::make_shared<SeerParallelStacksStack>();
|
||||
stack->threadCount = static_cast<int>(node->threads.size());
|
||||
SeerParallelStacksStack stack;
|
||||
stack.threadCount = node.threads.size();
|
||||
|
||||
// Collect thread IDs for this node
|
||||
for (const SeerParallelStacksThread& t : node->threads) {
|
||||
stack->threadIds.append(t.id());
|
||||
for (const SeerParallelStacksThread& t : node.threads) {
|
||||
stack.threadIds.append(t.id());
|
||||
}
|
||||
|
||||
if (!node->function.isEmpty()) {
|
||||
stack->functions.append(node->function);
|
||||
if (!node.function.isEmpty()) {
|
||||
stack.functions.append(node.function);
|
||||
}
|
||||
|
||||
if (node->children.size() == 1) {
|
||||
if (node.children.size() == 1) {
|
||||
// Merge single child into this stack (chain of frames).
|
||||
// Keep the IDs from the leaf (most specific) node.
|
||||
auto child = SeerParallelStacksFillStack(node->children[0]);
|
||||
stack->functions += child->functions;
|
||||
stack->stacks = child->stacks;
|
||||
stack->threadCount = child->threadCount;
|
||||
stack->threadIds = child->threadIds;
|
||||
auto child = SeerParallelStacksFillStack(node.children[0]);
|
||||
stack.functions += child.functions;
|
||||
stack.stacks = child.stacks;
|
||||
stack.threadCount = child.threadCount;
|
||||
stack.threadIds = child.threadIds;
|
||||
} else {
|
||||
for (const auto& childNode : node->children) {
|
||||
stack->stacks.append(SeerParallelStacksFillStack(childNode));
|
||||
for (const auto& childNode : node.children) {
|
||||
stack.stacks.append(SeerParallelStacksFillStack(childNode));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,22 +72,22 @@ class SeerParallelStacksThread {
|
||||
|
||||
typedef QVector<SeerParallelStacksThread> SeerParallelStacksThreads;
|
||||
|
||||
struct SeerParallelStacksStackNode {
|
||||
QString function; // empty == root
|
||||
int depth = 0;
|
||||
QVector<SeerParallelStacksThread> threads;
|
||||
QVector<std::shared_ptr<SeerParallelStacksStackNode>> children;
|
||||
struct SeerParallelStacksNode {
|
||||
QString function; // empty == root
|
||||
int depth = 0;
|
||||
QVector<SeerParallelStacksThread> threads;
|
||||
QVector<SeerParallelStacksNode> children;
|
||||
};
|
||||
|
||||
// Flat "Stack" representation used when building the graph.
|
||||
struct SeerParallelStacksStack {
|
||||
QVector<int> threadIds; // IDs of every thread in this node
|
||||
QVector<QString> functions;
|
||||
QVector<int> threadIds; // IDs of every thread in this node
|
||||
QVector<QString> functions;
|
||||
|
||||
QVector<std::shared_ptr<SeerParallelStacksStack>> stacks;
|
||||
int threadCount = 0;
|
||||
QVector<SeerParallelStacksStack> stacks;
|
||||
int threadCount = 0;
|
||||
};
|
||||
|
||||
std::shared_ptr<SeerParallelStacksStackNode> SeerParallelStacksBuildParallelStacks (const QVector<SeerParallelStacksThread>& threads); // Build the parallel-stacks tree from a flat list of threads.
|
||||
std::shared_ptr<SeerParallelStacksStack> SeerParallelStacksFillStack (const std::shared_ptr<SeerParallelStacksStackNode>& node);
|
||||
SeerParallelStacksNode SeerParallelStacksBuildParallelStacks (const QVector<SeerParallelStacksThread>& threads); // Build the parallel-stacks tree from a flat list of threads.
|
||||
SeerParallelStacksStack SeerParallelStacksFillStack (const SeerParallelStacksNode& node);
|
||||
|
||||
|
||||
@@ -749,11 +749,11 @@ void SeerParallelStacksGraphicsView::mouseReleaseEvent(QMouseEvent* event) {
|
||||
}
|
||||
|
||||
|
||||
void SeerParallelStacksGraphicsView::setStack(const std::shared_ptr<SeerParallelStacksStack>& root) {
|
||||
void SeerParallelStacksGraphicsView::setStack(const SeerParallelStacksStack& root) {
|
||||
|
||||
_scene->clear();
|
||||
|
||||
if (!root) return;
|
||||
// XXX if (!root) return;
|
||||
|
||||
auto* rootPN = new PlacedNode;
|
||||
buildPlacedTree(rootPN, root, nullptr);
|
||||
@@ -826,17 +826,17 @@ void SeerParallelStacksGraphicsView::alignParentlessToBottom(PlacedNode* pn, qre
|
||||
}
|
||||
}
|
||||
|
||||
void SeerParallelStacksGraphicsView::buildPlacedTree(PlacedNode* pn, const std::shared_ptr<SeerParallelStacksStack>& stack, PlacedNode* parentPN) {
|
||||
void SeerParallelStacksGraphicsView::buildPlacedTree(PlacedNode* pn, const SeerParallelStacksStack& stack, PlacedNode* parentPN) {
|
||||
|
||||
pn->stack = stack;
|
||||
pn->parent = parentPN;
|
||||
|
||||
if (!stack->functions.isEmpty()) {
|
||||
pn->item = new SeerParallelStacksStackBoxItem(*stack);
|
||||
if (!stack.functions.isEmpty()) {
|
||||
pn->item = new SeerParallelStacksStackBoxItem(stack);
|
||||
_scene->addItem(pn->item);
|
||||
}
|
||||
|
||||
for (const auto& child : stack->stacks) {
|
||||
for (const auto& child : stack.stacks) {
|
||||
auto* childPN = new PlacedNode;
|
||||
buildPlacedTree(childPN, child, pn);
|
||||
pn->children.append(childPN);
|
||||
|
||||
@@ -177,7 +177,7 @@ class SeerParallelStacksGraphicsView : public QGraphicsView {
|
||||
public:
|
||||
explicit SeerParallelStacksGraphicsView(QWidget* parent = nullptr);
|
||||
|
||||
void setStack (const std::shared_ptr<SeerParallelStacksStack>& root);
|
||||
void setStack (const SeerParallelStacksStack& root);
|
||||
|
||||
protected:
|
||||
void wheelEvent (QWheelEvent* event) override;
|
||||
@@ -198,26 +198,26 @@ class SeerParallelStacksGraphicsView : public QGraphicsView {
|
||||
|
||||
private:
|
||||
struct PlacedNode {
|
||||
std::shared_ptr<SeerParallelStacksStack> stack;
|
||||
SeerParallelStacksStackBoxItem* item = nullptr;
|
||||
PlacedNode* parent = nullptr;
|
||||
QVector<PlacedNode*> children;
|
||||
qreal cx = 0;
|
||||
qreal cy = 0;
|
||||
SeerParallelStacksStack stack;
|
||||
SeerParallelStacksStackBoxItem* item = nullptr;
|
||||
PlacedNode* parent = nullptr;
|
||||
QVector<PlacedNode*> children;
|
||||
qreal cx = 0;
|
||||
qreal cy = 0;
|
||||
};
|
||||
|
||||
void buildPlacedTree (PlacedNode* pn, const std::shared_ptr<SeerParallelStacksStack>& stack, PlacedNode* parentPN);
|
||||
void layoutTree (PlacedNode* pn, qreal& xCursor, qreal yTop);
|
||||
void collectMaxBottom (PlacedNode* pn, qreal& maxBottom);
|
||||
void alignParentlessToBottom (PlacedNode* pn, qreal maxBottom);
|
||||
void addEdges (PlacedNode* pn);
|
||||
void deleteTree (PlacedNode* pn);
|
||||
void repositionMiniMap (); // keeps it pinned to bottom-right corner
|
||||
void buildPlacedTree (PlacedNode* pn, const SeerParallelStacksStack& stack, PlacedNode* parentPN);
|
||||
void layoutTree (PlacedNode* pn, qreal& xCursor, qreal yTop);
|
||||
void collectMaxBottom (PlacedNode* pn, qreal& maxBottom);
|
||||
void alignParentlessToBottom (PlacedNode* pn, qreal maxBottom);
|
||||
void addEdges (PlacedNode* pn);
|
||||
void deleteTree (PlacedNode* pn);
|
||||
void repositionMiniMap (); // keeps it pinned to bottom-right corner
|
||||
|
||||
QGraphicsScene* _scene;
|
||||
SeerParallelStacksMiniMapWidget* _miniMap;
|
||||
bool _panning = false;
|
||||
QPoint _panStartPos; // viewport coords at pan start
|
||||
QGraphicsScene* _scene;
|
||||
SeerParallelStacksMiniMapWidget* _miniMap;
|
||||
bool _panning = false;
|
||||
QPoint _panStartPos; // viewport coords at pan start
|
||||
|
||||
friend class SeerParallelStacksMiniMapWidget; // needs sceneRect()/mapToScene()/centerOn() access
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user