File indexing completed on 2024-05-05 05:44:23
0001 /* 0002 This file is part of KCachegrind. 0003 0004 SPDX-FileCopyrightText: 2003-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> 0005 0006 SPDX-License-Identifier: GPL-2.0-only 0007 */ 0008 0009 #ifndef STACKBROWSER_H 0010 #define STACKBROWSER_H 0011 0012 #include "tracedata.h" 0013 0014 // A history of selected functions within stacks 0015 0016 class Stack 0017 { 0018 public: 0019 explicit Stack(TraceFunction*); 0020 0021 // extend the stack at top/bottom if possible 0022 bool contains(TraceFunction*); 0023 0024 void extendBottom(); 0025 void extendTop(); 0026 0027 // search for a function on stack calling specified function. 0028 // if found, return upper part with new function call 0029 Stack* split(TraceFunction*); 0030 0031 // increment reference count 0032 void ref() { _refCount++; } 0033 // decrement reference count 0034 bool deref() { return --_refCount; } 0035 int refCount() const { return _refCount; } 0036 0037 TraceFunction* top() { return _top; } 0038 TraceCallList calls() { return _calls; } 0039 TraceFunction* caller(TraceFunction*, bool extend); 0040 TraceFunction* called(TraceFunction*, bool extend); 0041 0042 QString toString(); 0043 0044 private: 0045 Stack(TraceFunction* top, TraceCallList list); 0046 0047 // at the top of the stack we have a function... 0048 TraceFunction* _top; 0049 // list ordered from top to bottom 0050 TraceCallList _calls; 0051 int _refCount; 0052 }; 0053 0054 class HistoryItem 0055 { 0056 public: 0057 HistoryItem(Stack*, TraceFunction*); 0058 ~HistoryItem(); 0059 0060 Stack* stack() { return _stack; } 0061 TraceFunction* function() { return _function; } 0062 HistoryItem* last() { return _last; } 0063 HistoryItem* next() { return _next; } 0064 void setLast(HistoryItem* h) { _last = h; } 0065 void setNext(HistoryItem* h) { _next = h; } 0066 0067 private: 0068 0069 HistoryItem *_last, *_next; 0070 Stack* _stack; 0071 TraceFunction* _function; 0072 }; 0073 0074 0075 class StackBrowser 0076 { 0077 public: 0078 StackBrowser(); 0079 ~StackBrowser(); 0080 0081 // A function was selected. This creates a new history entry 0082 HistoryItem* select(TraceFunction*); 0083 0084 HistoryItem* current() { return _current; } 0085 bool canGoBack(); 0086 bool canGoForward(); 0087 bool canGoUp(); 0088 bool canGoDown(); 0089 HistoryItem* goBack(); 0090 HistoryItem* goForward(); 0091 HistoryItem* goUp(); 0092 HistoryItem* goDown(); 0093 0094 private: 0095 HistoryItem* _current; 0096 }; 0097 0098 0099 #endif