1 //===--------------------- RetireControlUnitStatistics.cpp ------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 ///
11 /// This file implements the RetireControlUnitStatistics interface.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #include "Views/RetireControlUnitStatistics.h"
16 #include "llvm/Support/Format.h"
17 
18 namespace llvm {
19 namespace mca {
20 
21 void RetireControlUnitStatistics::onEvent(const HWInstructionEvent &Event) {
22   if (Event.Type == HWInstructionEvent::Retired)
23     ++NumRetired;
24 }
25 
26 void RetireControlUnitStatistics::printView(raw_ostream &OS) const {
27   std::string Buffer;
28   raw_string_ostream TempStream(Buffer);
29   TempStream << "\n\nRetire Control Unit - "
30              << "number of cycles where we saw N instructions retired:\n";
31   TempStream << "[# retired], [# cycles]\n";
32 
33   for (const std::pair<unsigned, unsigned> &Entry : RetiredPerCycle) {
34     TempStream << " " << Entry.first;
35     if (Entry.first < 10)
36       TempStream << ",           ";
37     else
38       TempStream << ",          ";
39     TempStream << Entry.second << "  ("
40                << format("%.1f", ((double)Entry.second / NumCycles) * 100.0)
41                << "%)\n";
42   }
43 
44   TempStream.flush();
45   OS << Buffer;
46 }
47 
48 } // namespace mca
49 } // namespace llvm
50