OpenASIP  2.0
DisasmTopCountAttrProvider.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file DisasmTopCountAttrProvider.cc
26  *
27  * Implementation of DisasmTopCountAttrProvider class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2006 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <wx/minifram.h>
34 #include <wx/grid.h>
37 #include "ExecutableInstruction.hh"
38 #include "Program.hh"
39 #include "NullInstruction.hh"
40 #include "Instruction.hh"
41 #include "ProximToolbox.hh"
43 #include "WxConversion.hh"
44 #include "Conversion.hh"
45 #include "ProximConstants.hh"
46 #include "ProximMainFrame.hh"
47 
48 BEGIN_EVENT_TABLE(DisasmExecCountFrame, wxMiniFrame)
51 
52 
53 /**
54  * The Constructor.
55  *
56  * @param parent Parent window of the miniframe.
57  * @param id Window identifier for the frame.
58  * @param topCountTable Table of top execution counts to display.
59  */
61  wxWindow* parent, wxWindowID id,
62  const DisasmTopCountAttrProvider::ExecutionCountTable& topCountTable) :
63  wxMiniFrame(parent, id, _T("Top Execution Counts")),
64  topCountTable_(topCountTable) {
65 
66  wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
67  list_ = new wxListCtrl(
68  this, -1, wxDefaultPosition, wxDefaultSize,
69  wxLC_REPORT | wxLC_SINGLE_SEL);
70 
71  list_->InsertColumn(0, _T("Exec Count"), wxLIST_FORMAT_LEFT, 100);
72  list_->InsertColumn(1, _T("Address range"), wxLIST_FORMAT_LEFT, 200);
73  sizer->Add(list_, 1, wxEXPAND|wxALL, 5);
74  SetSizer(sizer);
75 }
76 
77 /**
78  * The Destructor.
79  */
81 }
82 
83 /**
84  * Updates the execution count list.
85  */
86 void
88 
89  list_->DeleteAllItems();
90 
91  DisasmTopCountAttrProvider::ExecutionCountTable::const_iterator iter =
92  topCountTable_.begin();
93 
94  int pos = topCountTable_.size();
95  // Iterate through all entries in the topcount table.
96  for (; iter != topCountTable_.end(); iter++) {
97 
98  pos--;
99  unsigned count = (*iter).first;
100  const DisasmTopCountAttrProvider::AddressSet addressSet =
101  (*iter).second;
102 
103  DisasmTopCountAttrProvider::AddressSet::const_iterator citer =
104  addressSet.begin();
105 
106  // Iterate through all addresses with the same execution count and
107  // combine consecutive addresses to address ranges.
108  while (citer != addressSet.end()) {
109  unsigned rangeFirst = *citer;
110  unsigned rangeLast = *citer;
111  while (citer != addressSet.end() && (*citer == rangeLast)) {
112  citer++;
113  rangeLast++;
114  }
115  rangeLast--;
116 
117  // Add list entry for the address range.
118  wxString range = WxConversion::toWxString(rangeFirst);
119  if (rangeFirst != rangeLast) {
120  range.Append(_T(" - "));
121  range.Append(WxConversion::toWxString(rangeLast));
122  }
123 
124  list_->InsertItem(0, WxConversion::toWxString(count));
125  list_->SetItem(0, 1, range);
126  list_->SetItemData(0, rangeFirst);
127 
128  // Set background color for the list item.
129  // TODO: more elegant solution :)
130  if (pos < 5) {
131  list_->SetItemBackgroundColour(
132  0, wxColour(255 , pos * 50, 0));
133  } else {
134  list_->SetItemBackgroundColour(
135  0, wxColour(255 - (2 * (pos * 25 - 128)), 255, 0));
136  }
137 
138 
139  if (citer != addressSet.end()) {
140  citer++;
141  }
142  }
143  }
144 }
145 
146 
147 /**
148  * Event handler for the execution count list selection events.
149  *
150  * Selects and shows the start address of the selected range in the disassembly
151  * winow.
152  *
153  * @param event Selection event to handle.
154  */
155 void
157  unsigned addr = list_->GetItemData(event.GetIndex());
159  disasmwin.showAddress(addr);
160 }
161 
162 
163 /**
164  * The Constructor.
165  *
166  * @param simulator Simulator frontend for accessing instructions and execution
167  * counts.
168  * @param topCounts Number of top execution counts to list and highlight.
169  */
171  TracedSimulatorFrontend& simulator, size_t topCounts):
173  simulator_(simulator), topCounts_(topCounts) {
174 
177 
178  listWin_->Show();
179 }
180 
181 
182 /**
183  * The Destructor.
184  */
186  if (listWin_ != NULL) {
187  listWin_->Destroy();
188  }
189 }
190 
191 /**
192  * Updates the list of top execution counts when simulation stops.
193  */
194 void
197  listWin_->update();
198 }
199 
200 
201 /**
202  * Returns grid cell attributes for cell with given move.
203  *
204  * @param address Address of the cell's instruction.
205  */
206 wxGridCellAttr*
208  InstructionAddress address, int /* move */) {
209 
210  wxGridCellAttr* attr = new wxGridCellAttr();
211 
212  ClockCycleCount execCount =
214 
215  if (execCount == 0) {
216  attr->SetBackgroundColour(wxColour(220, 220, 220));
217  } else {
218  attr->SetBackgroundColour(bgColour(execCount));
219  }
220 
221  return attr;
222 }
223 
224 /**
225  * Updates the list of top execution counts.
226  */
227 void
229 
230  topCountTable_.clear();
232  const TTAProgram::Instruction* instruction = &program.firstInstruction();
233 
234  while (instruction != &TTAProgram::NullInstruction::instance()) {
235  InstructionAddress address = instruction->address().location();
236  ClockCycleCount execCount =
238 
239  if (execCount > 0) {
240  addToTopCountTable(address, execCount);
241  }
242 
243  instruction = &program.nextInstruction(*instruction);
244  }
245 
246 }
247 
248 /**
249  * Adds an instruction to the execution top count list if the count is high
250  * enough for the list.
251  *
252  * @param address Address of the instruction.
253  * @param execCount Execution count of the instruction.
254  */
255 void
257  InstructionAddress address, ClockCycleCount execCount) {
258 
259  ExecutionCountTable::iterator iter = topCountTable_.find(execCount);
260  if (iter != topCountTable_.end()) {
261  (*iter).second.insert(address);
262  } else if (topCountTable_.empty() ||
263  execCount > ((*topCountTable_.begin())).first) {
264 
265  AddressSet addressSet;
266  addressSet.insert(address);
267  topCountTable_.insert(
268  std::pair<ClockCycleCount, AddressSet>(execCount, addressSet));
269  }
270 
271  if (topCountTable_.size() > topCounts_) {
272  topCountTable_.erase(topCountTable_.begin());
273  }
274 
275 }
276 
277 /**
278  * Returns background highlight colour for an instruction with the given
279  * exec count.
280  *
281  * @param execCount Execution count of the instruciton.
282  * @return Background highlight colour for the instruction.
283  */
284 wxColour
286 
287  ExecutionCountTable::reverse_iterator iter = topCountTable_.rbegin();
288  size_t pos = 0;
289  while (iter != topCountTable_.rend()) {
290  if ((*iter).first == execCount) {
291  break;
292  }
293  pos++;
294  iter++;
295  }
296 
297  if (pos < topCounts_) {
298  int value = pos * (255 / topCounts_);
299  if (pos < (topCounts_ / 2)) {
300  return wxColour(255 , 2 * value, 0);
301  } else {
302  return wxColour(255 - (2 * (value-128)), 255, 0);
303  }
304  } else {
305  return wxColour(255, 255, 255);
306  }
307 
308 }
309 
TracedSimulatorFrontend
Definition: TracedSimulatorFrontend.hh:49
DisasmTopCountAttrProvider
Definition: DisasmTopCountAttrProvider.hh:53
TTAProgram::Program
Definition: Program.hh:63
InstructionAddress
UInt32 InstructionAddress
Definition: BaseType.hh:175
WxConversion::toWxString
static wxString toWxString(const std::string &source)
SimulatorFrontend::program
const TTAProgram::Program & program() const
Definition: SimulatorFrontend.cc:276
DisasmTopCountAttrProvider::AddressSet
std::set< InstructionAddress > AddressSet
Definition: DisasmTopCountAttrProvider.hh:62
DisasmExecCountFrame::~DisasmExecCountFrame
virtual ~DisasmExecCountFrame()
Definition: DisasmTopCountAttrProvider.cc:80
ExecutableInstruction::executionCount
ClockCycleCount executionCount() const
Definition: ExecutableInstruction.cc:85
TTAProgram::Instruction
Definition: Instruction.hh:57
DisasmTopCountAttrProvider::bgColour
wxColour bgColour(ClockCycleCount execCount)
Definition: DisasmTopCountAttrProvider.cc:285
DisasmTopCountAttrProvider::update
virtual void update()
Definition: DisasmTopCountAttrProvider.cc:195
ProximDisassemblyWindow.hh
DisasmTopCountAttrProvider::updateTopCountTable
void updateTopCountTable()
Definition: DisasmTopCountAttrProvider.cc:228
DisasmTopCountAttrProvider::listWin_
DisasmExecCountFrame * listWin_
Definition: DisasmTopCountAttrProvider.hh:78
ProximToolbox.hh
DisasmTopCountAttrProvider::DisasmTopCountAttrProvider
DisasmTopCountAttrProvider(TracedSimulatorFrontend &simulator, size_t topCounts)
Definition: DisasmTopCountAttrProvider.cc:170
ProximDisasmAttrProvider
Definition: ProximDisasmAttrProvider.hh:44
DisasmExecCountFrame::list_
wxListCtrl * list_
Definition: DisasmTopCountAttrProvider.hh:100
Instruction.hh
Conversion.hh
SimulatorFrontend::executableInstructionAt
const ExecutableInstruction & executableInstructionAt(InstructionAddress address) const
Definition: SimulatorFrontend.cc:2208
NullInstruction.hh
DisasmTopCountAttrProvider::moveCellAttr
virtual wxGridCellAttr * moveCellAttr(InstructionAddress address, int move)
Definition: DisasmTopCountAttrProvider.cc:207
DisasmTopCountAttrProvider::simulator_
TracedSimulatorFrontend & simulator_
Simulator frontend used for accessing the instructions and exec counts.
Definition: DisasmTopCountAttrProvider.hh:75
DisasmExecCountFrame::onSelection
void onSelection(wxListEvent &event)
Definition: DisasmTopCountAttrProvider.cc:156
DisasmTopCountAttrProvider.hh
TTAProgram::Address::location
InstructionAddress location() const
DisasmExecCountFrame::topCountTable_
const DisasmTopCountAttrProvider::ExecutionCountTable & topCountTable_
Definition: DisasmTopCountAttrProvider.hh:101
TTAProgram::NullInstruction::instance
static NullInstruction & instance()
Definition: NullInstruction.cc:66
EVT_LIST_ITEM_SELECTED
FUImplementationDialog::onAddExternalPort FUImplementationDialog::onDeleteExternalPort FUImplementationDialog::onArchPortSelection FUImplementationDialog::onArchPortActivation EVT_LIST_ITEM_SELECTED(ID_EXTERNAL_PORT_LIST, FUImplementationDialog::onExternalPortSelection) EVT_LIST_ITEM_ACTIVATED(ID_EXTERNAL_PORT_LIST
DisasmTopCountAttrProvider::addToTopCountTable
void addToTopCountTable(InstructionAddress address, ClockCycleCount execCount)
Definition: DisasmTopCountAttrProvider.cc:256
DisasmTopCountAttrProvider::topCounts_
size_t topCounts_
Number of top execution counts in the top execution count list.
Definition: DisasmTopCountAttrProvider.hh:77
TracedSimulatorFrontend.hh
ProximConstants.hh
Program.hh
DisasmTopCountAttrProvider::~DisasmTopCountAttrProvider
virtual ~DisasmTopCountAttrProvider()
Definition: DisasmTopCountAttrProvider.cc:185
ProximMainFrame.hh
ExecutableInstruction.hh
DisasmTopCountAttrProvider::topCountTable_
ExecutionCountTable topCountTable_
Top execution counts and set of instruction addresses with each count.
Definition: DisasmTopCountAttrProvider.hh:73
ClockCycleCount
CycleCount ClockCycleCount
Alias for ClockCycleCount.
Definition: SimulatorConstants.hh:57
WxConversion.hh
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
ProximToolbox::disassemblyWindow
static ProximDisassemblyWindow * disassemblyWindow()
Definition: ProximToolbox.cc:150
DisasmExecCountFrame
Definition: DisasmTopCountAttrProvider.hh:85
ProximDisassemblyWindow::showAddress
void showAddress(unsigned address)
Definition: ProximDisassemblyWindow.cc:359
ProximDisassemblyWindow
Definition: ProximDisassemblyWindow.hh:58
DisasmExecCountFrame::update
void update()
Definition: DisasmTopCountAttrProvider.cc:87
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
TTAProgram::Instruction::address
Address address() const
Definition: Instruction.cc:327