1/* 2 * Copyright (c) 2012-2014, TU Delft 3 * Copyright (c) 2012-2014, TU Eindhoven 4 * Copyright (c) 2012-2014, TU Kaiserslautern 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are 9 * met: 10 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 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. 17 * 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. 21 * 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. 33 * 34 * Authors: Omar Naji 35 * 36 */ 37#include "TraceParser.h" 38 39#include "CommandAnalysis.h" 40#include "CmdScheduler.h" 41 42using namespace Data; 43using namespace std; 44 45TraceParser::TraceParser(const MemorySpecification& memSpec) : 46 counters(memSpec) 47{ 48} 49 50 51Data::MemCommand TraceParser::parseLine(std::string line) 52{ 53 MemCommand memcmd(MemCommand::UNINITIALIZED, 0, 0); 54 istringstream linestream(line); 55 string item; 56 int64_t item_val; 57 unsigned itemnum = 0; 58 59 while (getline(linestream, item, ',')) { 60 if (itemnum == 0) { 61 stringstream timestamp(item); 62 timestamp >> item_val; 63 memcmd.setTime(item_val); 64 } else if (itemnum == 1) { 65 item_val = MemCommand::getTypeFromName(item); 66 memcmd.setType(static_cast<MemCommand::cmds>(item_val)); 67 } else if (itemnum == 2) { 68 stringstream bank(item); 69 bank >> item_val; 70 memcmd.setBank(static_cast<unsigned>(item_val)); 71 } 72 itemnum++; 73 } 74 return memcmd; 75} // TraceParser::parseLine 76 77void TraceParser::parseFile(MemorySpecification memSpec, std::ifstream& trace, 78 int window, int grouping, int interleaving, int burst, 79 int powerdown, int trans) 80{ 81 ifstream pwr_trace; 82 83 counters = CommandAnalysis(memSpec); 84 int nCommands = 0; 85 bool lastupdate = false; 86 if (trans) { 87 cmdScheduler cmdsched; 88 cmdsched.transTranslation(memSpec, trace, grouping, interleaving, burst, powerdown); 89 pwr_trace.open("commands.trace", ifstream::in); 90 std::string line; 91 while (getline(pwr_trace, line)) { 92 MemCommand cmdline = parseLine(line); 93 cmd_list.push_back(cmdline); 94 nCommands++; 95 if (nCommands == window) { 96 counters.getCommands(cmd_list, lastupdate); 97 nCommands = 0; 98 cmd_list.clear(); 99 } 100 } 101 lastupdate = true; 102 counters.getCommands(cmd_list, lastupdate); 103 cmd_list.clear(); 104 pwr_trace.close(); 105 } else { 106 std::string line; 107 while (getline(trace, line)) { 108 MemCommand cmdline = parseLine(line); 109 cmd_list.push_back(cmdline); 110 nCommands++; 111 if (nCommands == window) { 112 counters.getCommands(cmd_list, lastupdate); 113 nCommands = 0; 114 cmd_list.clear(); 115 } 116 } 117 lastupdate = true; 118 counters.getCommands(cmd_list, lastupdate); 119 cmd_list.clear(); 120 } 121 counters.clear(); 122 trace.close(); 123} // TraceParser::parseFile 124