DataViews/PyProfileDialog.py

changeset 945
8cd4d08fa9f6
parent 791
9ec2ac20e54e
child 982
a1abe3018d04
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
17 17
18 from .Ui_PyProfileDialog import Ui_PyProfileDialog 18 from .Ui_PyProfileDialog import Ui_PyProfileDialog
19 import Utilities 19 import Utilities
20 20
21 from eric5config import getConfig 21 from eric5config import getConfig
22
22 23
23 class ProfileTreeWidgetItem(QTreeWidgetItem): 24 class ProfileTreeWidgetItem(QTreeWidgetItem):
24 """ 25 """
25 Class implementing a custom QTreeWidgetItem to allow sorting on numeric values. 26 Class implementing a custom QTreeWidgetItem to allow sorting on numeric values.
26 """ 27 """
45 return self.__getNC(self) < self.__getNC(other) 46 return self.__getNC(self) < self.__getNC(other)
46 if column == 6: 47 if column == 6:
47 return int(self.text(column)) < int(other.text(column)) 48 return int(self.text(column)) < int(other.text(column))
48 return self.text(column) < other.text(column) 49 return self.text(column) < other.text(column)
49 50
51
50 class PyProfileDialog(QDialog, Ui_PyProfileDialog): 52 class PyProfileDialog(QDialog, Ui_PyProfileDialog):
51 """ 53 """
52 Class implementing a dialog to display the results of a syntax check run. 54 Class implementing a dialog to display the results of a syntax check run.
53 """ 55 """
54 def __init__(self, parent = None): 56 def __init__(self, parent=None):
55 """ 57 """
56 Constructor 58 Constructor
57 59
58 @param parent parent widget (QWidget) 60 @param parent parent widget (QWidget)
59 """ 61 """
71 self.summaryList.headerItem().setText(self.summaryList.columnCount(), "") 73 self.summaryList.headerItem().setText(self.summaryList.columnCount(), "")
72 self.resultList.headerItem().setText(self.resultList.columnCount(), "") 74 self.resultList.headerItem().setText(self.resultList.columnCount(), "")
73 self.resultList.header().setSortIndicator(0, Qt.DescendingOrder) 75 self.resultList.header().setSortIndicator(0, Qt.DescendingOrder)
74 76
75 self.__menu = QMenu(self) 77 self.__menu = QMenu(self)
76 self.filterItm = self.__menu.addAction(self.trUtf8('Exclude Python Library'), 78 self.filterItm = self.__menu.addAction(self.trUtf8('Exclude Python Library'),
77 self.__filter) 79 self.__filter)
78 self.__menu.addSeparator() 80 self.__menu.addSeparator()
79 self.__menu.addAction(self.trUtf8('Erase Profiling Info'), 81 self.__menu.addAction(self.trUtf8('Erase Profiling Info'),
80 self.__eraseProfile) 82 self.__eraseProfile)
81 self.__menu.addAction(self.trUtf8('Erase Timing Info'), self.__eraseTiming) 83 self.__menu.addAction(self.trUtf8('Erase Timing Info'), self.__eraseTiming)
82 self.__menu.addSeparator() 84 self.__menu.addSeparator()
83 self.__menu.addAction(self.trUtf8('Erase All Infos'), self.__eraseAll) 85 self.__menu.addAction(self.trUtf8('Erase All Infos'), self.__eraseAll)
84 self.resultList.setContextMenuPolicy(Qt.CustomContextMenu) 86 self.resultList.setContextMenuPolicy(Qt.CustomContextMenu)
85 self.resultList.customContextMenuRequested.connect(self.__showContextMenu) 87 self.resultList.customContextMenuRequested.connect(self.__showContextMenu)
86 self.summaryList.setContextMenuPolicy(Qt.CustomContextMenu) 88 self.summaryList.setContextMenuPolicy(Qt.CustomContextMenu)
87 self.summaryList.customContextMenuRequested.connect(self.__showContextMenu) 89 self.summaryList.customContextMenuRequested.connect(self.__showContextMenu)
88 90
89 def __createResultItem(self, calls, totalTime, totalTimePerCall, cumulativeTime, 91 def __createResultItem(self, calls, totalTime, totalTimePerCall, cumulativeTime,
90 cumulativeTimePerCall, file, line, functionName): 92 cumulativeTimePerCall, file, line, functionName):
91 """ 93 """
92 Private method to create an entry in the result list. 94 Private method to create an entry in the result list.
93 95
94 @param calls number of calls (integer) 96 @param calls number of calls (integer)
99 @param file filename of file (string) 101 @param file filename of file (string)
100 @param line linenumber (integer) 102 @param line linenumber (integer)
101 @param functionName function name (string) 103 @param functionName function name (string)
102 """ 104 """
103 itm = ProfileTreeWidgetItem(self.resultList, [ 105 itm = ProfileTreeWidgetItem(self.resultList, [
104 calls, 106 calls,
105 "{0: 8.3f}".format(totalTime), 107 "{0: 8.3f}".format(totalTime),
106 totalTimePerCall, 108 totalTimePerCall,
107 "{0: 8.3f}".format(cumulativeTime), 109 "{0: 8.3f}".format(cumulativeTime),
108 cumulativeTimePerCall, 110 cumulativeTimePerCall,
109 file, 111 file,
110 str(line), 112 str(line),
111 functionName 113 functionName
112 ]) 114 ])
113 for col in [0, 1, 2, 3, 4, 6]: 115 for col in [0, 1, 2, 3, 4, 6]:
114 itm.setTextAlignment(col, Qt.AlignRight) 116 itm.setTextAlignment(col, Qt.AlignRight)
115 117
125 127
126 def __resortResultList(self): 128 def __resortResultList(self):
127 """ 129 """
128 Private method to resort the tree. 130 Private method to resort the tree.
129 """ 131 """
130 self.resultList.sortItems(self.resultList.sortColumn(), 132 self.resultList.sortItems(self.resultList.sortColumn(),
131 self.resultList.header().sortIndicatorOrder()) 133 self.resultList.header().sortIndicatorOrder())
132 134
133 def __populateLists(self, exclude = False): 135 def __populateLists(self, exclude=False):
134 """ 136 """
135 Private method used to populate the listviews. 137 Private method used to populate the listviews.
136 138
137 @param exclude flag indicating whether files residing in the 139 @param exclude flag indicating whether files residing in the
138 Python library should be excluded 140 Python library should be excluded
143 self.checkProgress.setMaximum(len(self.stats)) 145 self.checkProgress.setMaximum(len(self.stats))
144 QApplication.processEvents() 146 QApplication.processEvents()
145 147
146 progress = 0 148 progress = 0
147 total_calls = 0 149 total_calls = 0
148 prim_calls = 0 150 prim_calls = 0
149 total_tt = 0 151 total_tt = 0
150 152
151 try: 153 try:
152 # disable updates of the list for speed 154 # disable updates of the list for speed
153 self.resultList.setUpdatesEnabled(False) 155 self.resultList.setUpdatesEnabled(False)
154 self.resultList.setSortingEnabled(False) 156 self.resultList.setSortingEnabled(False)
162 not (exclude and func[0].startswith(self.pyLibPath)): 164 not (exclude and func[0].startswith(self.pyLibPath)):
163 if self.file is None or func[0].startswith(self.file) or \ 165 if self.file is None or func[0].startswith(self.file) or \
164 func[0].startswith(self.pyLibPath): 166 func[0].startswith(self.pyLibPath):
165 # calculate the totals 167 # calculate the totals
166 total_calls += nc 168 total_calls += nc
167 prim_calls += cc 169 prim_calls += cc
168 total_tt += tt 170 total_tt += tt
169 171
170 if nc != cc: 172 if nc != cc:
171 c = "{0:d}/{1:d}".format(nc, cc) 173 c = "{0:d}/{1:d}".format(nc, cc)
172 else: 174 else:
173 c = str(nc) 175 c = str(nc)
174 if nc == 0: 176 if nc == 0:
175 tpc = "{0: 8.3f}".format(0.0) 177 tpc = "{0: 8.3f}".format(0.0)
176 else: 178 else:
177 tpc = "{0: 8.3f}".format(tt/nc) 179 tpc = "{0: 8.3f}".format(tt / nc)
178 if cc == 0: 180 if cc == 0:
179 cpc = "{0: 8.3f}".format(0.0) 181 cpc = "{0: 8.3f}".format(0.0)
180 else: 182 else:
181 cpc = "{0: 8.3f}".format(ct/cc) 183 cpc = "{0: 8.3f}".format(ct / cc)
182 self.__createResultItem(c, tt, tpc, ct, cpc, func[0], 184 self.__createResultItem(c, tt, tpc, ct, cpc, func[0],
183 func[1], func[2]) 185 func[1], func[2])
184 186
185 progress += 1 187 progress += 1
186 self.checkProgress.setValue(progress) 188 self.checkProgress.setValue(progress)
187 QApplication.processEvents() 189 QApplication.processEvents()

eric ide

mercurial