2 * Copyright (c) 2012-2014, TU Delft
3 * Copyright (c) 2012-2014, TU Eindhoven
4 * Copyright (c) 2012-2014, TU Kaiserslautern
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the copyright holder nor the names of its
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
23 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
28 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include "TraceParser.h"
39 #include "CommandAnalysis.h"
40 #include "CmdScheduler.h"
45 Data::MemCommand
TraceParser::parseLine(std::string line
)
48 istringstream
linestream(line
);
52 MemCommand::cmds type
= MemCommand::NOP
; // Initialized to prevent warning
54 while (getline(linestream
, item
, ',')) {
56 stringstream
timestamp(item
);
57 timestamp
>> item_val
;
58 memcmd
.setTime(item_val
);
59 } else if (itemnum
== 1) {
60 item_val
= MemCommand::getTypeFromName(item
);
61 memcmd
.setType(static_cast<MemCommand::cmds
>(item_val
));
62 } else if (itemnum
== 2) {
63 stringstream
bank(item
);
66 memcmd
.setBank(static_cast<unsigned>(item_val
));
68 type
= memcmd
.getType();
72 } // TraceParser::parseLine
74 void TraceParser::parseFile(MemorySpecification memSpec
, std::ifstream
& trace
,
75 int window
, int grouping
, int interleaving
, int burst
,
76 int powerdown
, int trans
)
80 counters
= CommandAnalysis(memSpec
.memArchSpec
.nbrOfBanks
);
82 bool lastupdate
= false;
84 cmdScheduler cmdsched
;
85 cmdsched
.transTranslation(memSpec
, trace
, grouping
, interleaving
, burst
, powerdown
);
86 pwr_trace
.open("commands.trace", ifstream::in
);
88 while (getline(pwr_trace
, line
)) {
89 MemCommand cmdline
= parseLine(line
);
90 cmd_list
.push_back(cmdline
);
92 if (nCommands
== window
) {
93 counters
.getCommands(memSpec
, memSpec
.memArchSpec
.nbrOfBanks
, cmd_list
, lastupdate
);
99 counters
.getCommands(memSpec
, memSpec
.memArchSpec
.nbrOfBanks
, cmd_list
, lastupdate
);
104 while (getline(trace
, line
)) {
105 MemCommand cmdline
= parseLine(line
);
106 cmd_list
.push_back(cmdline
);
108 if (nCommands
== window
) {
109 counters
.getCommands(memSpec
, memSpec
.memArchSpec
.nbrOfBanks
, cmd_list
, lastupdate
);
115 counters
.getCommands(memSpec
, memSpec
.memArchSpec
.nbrOfBanks
, cmd_list
, lastupdate
);
120 } // TraceParser::parseFile