OpenASIP  2.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
ExecutionTrace Class Reference

#include <ExecutionTrace.hh>

Collaboration diagram for ExecutionTrace:
Collaboration graph

Public Types

enum  ProcedureEntryType { PT_ENTRY = 0, PT_EXIT = 1 }
 a type for storing procedure entry type (entry/exit) More...
 
typedef std::string AddressSpaceID
 a type for storing address space identifiers More...
 
typedef std::string BusID
 a type for storing bus identifiers More...
 
typedef std::string SocketID
 a type for storing socket identifiers More...
 
typedef std::string SegmentID
 a type for storing bus segment identifiers More...
 
typedef std::string FunctionUnitID
 a type for storing function unit identifiers More...
 
typedef std::string OperationID
 a type for storing operation identifiers More...
 
typedef std::string RegisterFileID
 a type for storing register file identifiers More...
 
typedef int RegisterID
 a type for storing register ids More...
 
typedef unsigned int MemoryAddress
 a type for storing memory addresses More...
 
typedef SimValue MAU
 a type for storing data of size of the minimum addressable unit More...
 
typedef std::size_t RegisterAccessCount
 a type for register access counts More...
 
typedef ClockCycleCount OperationTriggerCount
 a type for operation trigger counts More...
 
typedef boost::tuple< RegisterAccessCount, RegisterAccessCount, ClockCycleCountConcurrentRFAccessCount
 type to be used as a key for storing concurrent RF access info More...
 
typedef std::list< ConcurrentRFAccessCountConcurrentRFAccessCountList
 type to be used for a list of concurrent RF accesses More...
 
typedef boost::tuple< OperationID, OperationTriggerCountFUOperationTriggerCount
 type to be used as a key for storing function unit operation execution counts More...
 
typedef std::list< FUOperationTriggerCountFUOperationTriggerCountList
 type to be used for lists of function operation execution counts More...
 

Public Member Functions

void addInstructionExecution (ClockCycleCount cycle, InstructionAddress address)
 
void addInstructionExecutionCount (InstructionAddress address, ClockCycleCount count)
 
void addProcedureAddressRange (InstructionAddress firstAddress, InstructionAddress lastAddress, const std::string &procedureName)
 
void addLockedCycle (ClockCycleCount cycle)
 
void addBasicBlockStart (ClockCycleCount cycle, InstructionAddress address)
 
void addMemoryAccess (ClockCycleCount cycle, const AddressSpaceID &addressSpace, MemoryAddress address, bool write, std::size_t size, const std::vector< MAU > *data=NULL)
 
void addProcedureEntry (ClockCycleCount cycle, InstructionAddress address)
 
void addProcedureExit (ClockCycleCount cycle, InstructionAddress address)
 
void addBusActivity (ClockCycleCount cycle, const BusID &busId, const SegmentID &segmentId, bool squash, const SimValue &data=NullSimValue::instance())
 
void addConcurrentRegisterFileAccessCount (RegisterFileID registerFile, RegisterAccessCount reads, RegisterAccessCount writes, ClockCycleCount count)
 
void addRegisterAccessCount (RegisterFileID registerFile, RegisterID registerIndex, ClockCycleCount reads, ClockCycleCount writes)
 
ConcurrentRFAccessCountListregisterFileAccessCounts (RegisterFileID registerFile) const
 
void addFunctionUnitOperationTriggerCount (FunctionUnitID functionUnit, OperationID operation, OperationTriggerCount count)
 
void addProcedureTransfer (ClockCycleCount cycle, InstructionAddress address, InstructionAddress sourceAddress, ProcedureEntryType type)
 
FUOperationTriggerCountListfunctionUnitOperationTriggerCounts (FunctionUnitID functionUnit) const
 
void addSocketWriteCount (SocketID socket, ClockCycleCount)
 
ClockCycleCount socketWriteCount (SocketID socket) const
 
void addBusWriteCount (BusID socket, ClockCycleCount count)
 
ClockCycleCount busWriteCount (BusID bus) const
 
void setSimulatedCycleCount (ClockCycleCount count)
 
ClockCycleCount simulatedCycleCount () const
 
InstructionExecutioninstructionExecutions ()
 
virtual ~ExecutionTrace ()
 

Static Public Member Functions

static ExecutionTraceopen (const std::string &fileName)
 

Protected Member Functions

 ExecutionTrace (const std::string &fileName, bool readOnly)
 
void open ()
 

Private Member Functions

void initialize ()
 

Private Attributes

const std::string & fileName_
 Filename of the trace database (sqlite file). More...
 
std::fstream callTrace_
 The call trace file. More...
 
std::fstream instructionProfile_
 The instruction profile file. More...
 
bool readOnly_
 Is the database access mode read-only? More...
 
RelationalDBdb_
 Handle to the sqlite trace database. More...
 
RelationalDBConnectiondbConnection_
 Handle to the database connection;. More...
 
InstructionExecutioninstructionExecution_
 Handle object for the queries of instruction executions. More...
 

Detailed Description

The main class of the Execution Trace Database (TraceDB).

Access to the execution trace database happens through the interface of this class.

Definition at line 56 of file ExecutionTrace.hh.

Member Typedef Documentation

◆ AddressSpaceID

typedef std::string ExecutionTrace::AddressSpaceID

a type for storing address space identifiers

Definition at line 60 of file ExecutionTrace.hh.

◆ BusID

typedef std::string ExecutionTrace::BusID

a type for storing bus identifiers

Definition at line 63 of file ExecutionTrace.hh.

◆ ConcurrentRFAccessCount

type to be used as a key for storing concurrent RF access info

Definition at line 105 of file ExecutionTrace.hh.

◆ ConcurrentRFAccessCountList

type to be used for a list of concurrent RF accesses

Definition at line 108 of file ExecutionTrace.hh.

◆ FunctionUnitID

typedef std::string ExecutionTrace::FunctionUnitID

a type for storing function unit identifiers

Definition at line 72 of file ExecutionTrace.hh.

◆ FUOperationTriggerCount

type to be used as a key for storing function unit operation execution counts

Definition at line 113 of file ExecutionTrace.hh.

◆ FUOperationTriggerCountList

type to be used for lists of function operation execution counts

Definition at line 116 of file ExecutionTrace.hh.

◆ MAU

a type for storing data of size of the minimum addressable unit

Definition at line 87 of file ExecutionTrace.hh.

◆ MemoryAddress

typedef unsigned int ExecutionTrace::MemoryAddress

a type for storing memory addresses

Definition at line 84 of file ExecutionTrace.hh.

◆ OperationID

typedef std::string ExecutionTrace::OperationID

a type for storing operation identifiers

Definition at line 75 of file ExecutionTrace.hh.

◆ OperationTriggerCount

a type for operation trigger counts

Definition at line 93 of file ExecutionTrace.hh.

◆ RegisterAccessCount

a type for register access counts

Definition at line 90 of file ExecutionTrace.hh.

◆ RegisterFileID

typedef std::string ExecutionTrace::RegisterFileID

a type for storing register file identifiers

Definition at line 78 of file ExecutionTrace.hh.

◆ RegisterID

a type for storing register ids

Definition at line 81 of file ExecutionTrace.hh.

◆ SegmentID

typedef std::string ExecutionTrace::SegmentID

a type for storing bus segment identifiers

Definition at line 69 of file ExecutionTrace.hh.

◆ SocketID

typedef std::string ExecutionTrace::SocketID

a type for storing socket identifiers

Definition at line 66 of file ExecutionTrace.hh.

Member Enumeration Documentation

◆ ProcedureEntryType

a type for storing procedure entry type (entry/exit)

Enumerator
PT_ENTRY 

procedure entry

PT_EXIT 

procedure exit

Definition at line 96 of file ExecutionTrace.hh.

96  {
97  PT_ENTRY = 0, ///< procedure entry
98  PT_EXIT = 1 ///< procedure exit
99  };

Constructor & Destructor Documentation

◆ ~ExecutionTrace()

ExecutionTrace::~ExecutionTrace ( )
virtual

Destructor.

Closes the database and frees the resources connected to it. Commits the transaction so updates are written to disk.

Definition at line 202 of file ExecutionTrace.cc.

202  {
203 
204  try {
205  if (instructionExecution_ != NULL) {
206  delete instructionExecution_;
207  instructionExecution_ = NULL;
208  }
209 
210  if (dbConnection_ != NULL) {
212  try {
213  assert(db_ != NULL);
215  dbConnection_ = NULL;
216  } catch (const RelationalDBException& e) {
218  __FILE__, __LINE__, __func__, e.errorMessage());
219  }
220  }
221 
222  callTrace_.close();
223  instructionProfile_.close();
224 
225  if (db_ != NULL) {
226  delete db_;
227  db_ = NULL;
228  }
229 
230  } catch (const Exception& e) {
231  debugLog(
232  "Exception almost leaked from ~ExecutionTrace! Message: " +
233  e.errorMessage());
234  }
235 }

References __func__, assert, callTrace_, RelationalDB::close(), RelationalDBConnection::commit(), db_, dbConnection_, debugLog, Exception::errorMessage(), instructionExecution_, instructionProfile_, and Application::writeToErrorLog().

Here is the call graph for this function:

◆ ExecutionTrace()

ExecutionTrace::ExecutionTrace ( const std::string &  fileName,
bool  readOnly 
)
protected

Constructor.

Parameters
fileNameFilename used for accessing the database.
readOnlyIs the database read-only?

Definition at line 180 of file ExecutionTrace.cc.

180  :
181  fileName_(fileName), callTrace_(
182  (fileName + ".calls").c_str(),
183  (FileSystem::fileExists(fileName) || readOnly) ?
184  std::fstream::in :
185  std::fstream::out | std::fstream::trunc),
187  (fileName + ".profile").c_str(),
188  (FileSystem::fileExists(fileName) || readOnly) ?
189  std::fstream::in :
190  std::fstream::out | std::fstream::trunc),
191  readOnly_(readOnly), db_(new SQLite()),
192  dbConnection_(NULL), instructionExecution_(NULL) {
193 }

Referenced by open().

Member Function Documentation

◆ addBasicBlockStart()

void ExecutionTrace::addBasicBlockStart ( ClockCycleCount  cycle,
InstructionAddress  address 
)

◆ addBusActivity()

void ExecutionTrace::addBusActivity ( ClockCycleCount  cycle,
const BusID busId,
const SegmentID segmentId,
bool  squash,
const SimValue data = NullSimValue::instance() 
)

Adds a new bus activity record to the database.

Parameters
cycleThe clock cycle in which the bus activity happened.
busIdThe name of the bus.
segmentIdThe name of the segment in the bus.
squashWhether the transfer was squashed or not.
dataThe data transferred.
Exceptions
IOExceptionIn case an error in adding the data happened.

Definition at line 391 of file ExecutionTrace.cc.

393  {
394  std::string query =
395  "INSERT INTO bus_activity(cycle, bus, segment, squash, "
396  "data_as_int, data_as_double) VALUES(" +
397  Conversion::toString(cycle) + ", '" + busId + "', '" + segmentId +
398  "', ";
399 
400  if (squash)
401  query += "'TRUE'";
402  else
403  query += "'FALSE'";
404 
405  std::string doubleString = Conversion::toString(data.doubleWordValue());
406  if (doubleString == "nan")
407  doubleString = "NULL";
408 
409  if (!squash && &data != &NullSimValue::instance())
410  query += ", " + Conversion::toString(data.uIntWordValue()) + ", " +
411  doubleString + ")";
412  else
413  query += ", 0, 0.0)";
414 
415 
416  assert(dbConnection_ != NULL);
417 
418  try {
419  dbConnection_->updateQuery(query);
420  } catch (const RelationalDBException& e) {
421  debugLog(std::string("query: ") + query);
422  throw IOException(__FILE__, __LINE__, __func__, e.errorMessage());
423  }
424 }

References __func__, assert, dbConnection_, debugLog, SimValue::doubleWordValue(), Exception::errorMessage(), NullSimValue::instance(), Conversion::toString(), SimValue::uIntWordValue(), and RelationalDBConnection::updateQuery().

Here is the call graph for this function:

◆ addBusWriteCount()

void ExecutionTrace::addBusWriteCount ( BusID  bus,
ClockCycleCount  count 
)

Adds a bus write count statistics to the database.

This stats tells in how many clock cycles was a bus used (transported data through).

Parameters
socketThe name of the bus.
countThe count of writes/uses.
Exceptions
IOExceptionIn case an error in adding the data happened.

Definition at line 688 of file ExecutionTrace.cc.

688  {
689  const std::string query =
690  std::string("") +
691  "INSERT INTO bus_write_counts(bus, writes) "
692  "VALUES('" + bus + "', " + Conversion::toString(count) + ")";
693 
694  assert(dbConnection_ != NULL);
695 
696  try {
697  dbConnection_->updateQuery(query);
698  } catch (const RelationalDBException& e) {
699  debugLog(query + " failed!");
700  throw IOException(__FILE__, __LINE__, __func__, e.errorMessage());
701  }
702 }

References __func__, assert, dbConnection_, debugLog, Exception::errorMessage(), Conversion::toString(), and RelationalDBConnection::updateQuery().

Referenced by SimulatorFrontend::finishSimulation().

Here is the call graph for this function:

◆ addConcurrentRegisterFileAccessCount()

void ExecutionTrace::addConcurrentRegisterFileAccessCount ( RegisterFileID  registerFile,
RegisterAccessCount  reads,
RegisterAccessCount  writes,
ClockCycleCount  count 
)

Adds a concurrent register file access statistics to the database.

Statistics tells how many times a type of read/write count combination access happened. That is, how many times the given register file was read and written the given times simultaneously.

Parameters
registerFileThe name of the register file.
readsCount of simultaneous reads.
writesCount of simultaneous writes.
countThe count of this type of accesses.
Exceptions
IOExceptionIn case an error in adding the data happened.

Definition at line 440 of file ExecutionTrace.cc.

442  {
443  const std::string query =
444  std::string("") +
445  "INSERT INTO concurrent_register_file_access("
446  " register_file, reads, writes, count) "
447  "VALUES('" + registerFile + "', " +
448  Conversion::toString(reads) + ", " +
449  Conversion::toString(writes) + ", " +
450  Conversion::toString(count) + ")";
451 
452  assert(dbConnection_ != NULL);
453 
454  try {
455  dbConnection_->updateQuery(query);
456  } catch (const RelationalDBException& e) {
457  debugLog(query + " failed!");
458  throw IOException(__FILE__, __LINE__, __func__, e.errorMessage());
459  }
460 }

References __func__, assert, dbConnection_, debugLog, Exception::errorMessage(), Conversion::toString(), and RelationalDBConnection::updateQuery().

Referenced by SimulatorFrontend::finishSimulation().

Here is the call graph for this function:

◆ addFunctionUnitOperationTriggerCount()

void ExecutionTrace::addFunctionUnitOperationTriggerCount ( FunctionUnitID  functionUnit,
OperationID  operation,
OperationTriggerCount  count 
)

Adds a function unit operation execution statistics to the database.

Statistics tells how many times an operation was executed in an function unit.

Parameters
functionUnitThe name of the function unit.
operationThe name of the operation.
countThe count of executions.
Exceptions
IOExceptionIn case an error in adding the data happened.

Definition at line 546 of file ExecutionTrace.cc.

548  {
549  const std::string query =
550  std::string("") +
551  "INSERT INTO fu_operation_triggers("
552  " function_unit, operation, count) "
553  "VALUES('" + functionUnit + "', '" + operation + "', " +
554  Conversion::toString(count) + ")";
555 
556  assert(dbConnection_ != NULL);
557 
558  try {
559  dbConnection_->updateQuery(query);
560  } catch (const RelationalDBException& e) {
561  debugLog(query + " failed!");
562  throw IOException(__FILE__, __LINE__, __func__, e.errorMessage());
563  }
564 }

References __func__, assert, dbConnection_, debugLog, Exception::errorMessage(), Conversion::toString(), and RelationalDBConnection::updateQuery().

Referenced by SimulatorFrontend::finishSimulation().

Here is the call graph for this function:

◆ addInstructionExecution()

void ExecutionTrace::addInstructionExecution ( ClockCycleCount  cycle,
InstructionAddress  address 
)

Adds a new instruction execution record to the database.

Parameters
cycleThe clock cycle on which the instruction execution happened.
addressThe address of the executed instruction.
Exceptions
IOExceptionIn case an error in adding the data happened.

Definition at line 279 of file ExecutionTrace.cc.

280  {
281  const std::string query =
282  (boost::format(
283  "INSERT INTO instruction_execution(cycle, address) VALUES("
284  "%.0f, %d);") % cycle % address).str();
285 
286  assert(dbConnection_ != NULL);
287 
288  try {
289  dbConnection_->updateQuery(query);
290  } catch (const RelationalDBException& e) {
291  throw IOException(__FILE__, __LINE__, __func__, e.errorMessage());
292  }
293 }

References __func__, assert, dbConnection_, Exception::errorMessage(), and RelationalDBConnection::updateQuery().

Referenced by ExecutionTracker::handleEvent().

Here is the call graph for this function:

◆ addInstructionExecutionCount()

void ExecutionTrace::addInstructionExecutionCount ( InstructionAddress  address,
ClockCycleCount  count 
)

Adds a new instruction execution count record to the database.

Parameters
addressThe address of the executed instruction.
countThe count of clock cycles during which execution of the instruction happened.
Exceptions
IOExceptionIn case an error in adding the data happened.

Definition at line 304 of file ExecutionTrace.cc.

305  {
306  instructionProfile_ << address << "\t" << count << std::endl;
307 #if 0
308  const std::string query =
309  "INSERT INTO instruction_execution_count(address, count) VALUES(" +
310  Conversion::toString(address) + ", " +
311  Conversion::toString(count) + ");";
312 
313  assert(dbConnection_ != NULL);
314 
315  try {
316  dbConnection_->updateQuery(query);
317  } catch (const RelationalDBException& e) {
318  throw IOException(__FILE__, __LINE__, __func__, e.errorMessage());
319  }
320 #endif
321 }

References __func__, assert, dbConnection_, Exception::errorMessage(), instructionProfile_, Conversion::toString(), and RelationalDBConnection::updateQuery().

Referenced by SimulatorFrontend::finishSimulation().

Here is the call graph for this function:

◆ addLockedCycle()

void ExecutionTrace::addLockedCycle ( ClockCycleCount  cycle)

◆ addMemoryAccess()

void ExecutionTrace::addMemoryAccess ( ClockCycleCount  cycle,
const AddressSpaceID addressSpace,
MemoryAddress  address,
bool  write,
std::size_t  size,
const std::vector< MAU > *  data = NULL 
)

◆ addProcedureAddressRange()

void ExecutionTrace::addProcedureAddressRange ( InstructionAddress  firstAddress,
InstructionAddress  lastAddress,
const std::string &  procedureName 
)

Adds a procedure address range entry to the database.

An entry in this table tells the range of instruction addresses belonging to a procedure.

Parameters
firstAddressThe starting address of the procedure.
lastAddressThe ending address of the procedure.
nameThe name of the procedure.
Exceptions
IOExceptionIn case an error in adding the data happened.

Definition at line 335 of file ExecutionTrace.cc.

337  {
338  const std::string query =
339  "INSERT INTO procedure_address_range(first_address, last_address, "
340  "procedure_name) VALUES(" +
341  Conversion::toString(firstAddress) + ", " +
342  Conversion::toString(lastAddress) + ", '" +
343  procedureName + "');";
344 
345  assert(dbConnection_ != NULL);
346 
347  try {
348  dbConnection_->updateQuery(query);
349  } catch (const RelationalDBException& e) {
350  throw IOException(__FILE__, __LINE__, __func__, e.errorMessage());
351  }
352 }

References __func__, assert, dbConnection_, Exception::errorMessage(), Conversion::toString(), and RelationalDBConnection::updateQuery().

Referenced by SimulatorFrontend::finishSimulation().

Here is the call graph for this function:

◆ addProcedureEntry()

void ExecutionTrace::addProcedureEntry ( ClockCycleCount  cycle,
InstructionAddress  address 
)

◆ addProcedureExit()

void ExecutionTrace::addProcedureExit ( ClockCycleCount  cycle,
InstructionAddress  address 
)

◆ addProcedureTransfer()

void ExecutionTrace::addProcedureTransfer ( ClockCycleCount  cycle,
InstructionAddress  address,
InstructionAddress  sourceAddress,
ProcedureEntryType  type 
)

Adds a procedure transfer tracking data entry.

Parameters
cycleThe clock cycle in which the transfer occured.
addressThe instruction address to which the execution changed.
callAddressThe address of the call.
typeType of the transfer.

Definition at line 575 of file ExecutionTrace.cc.

577  {
578  callTrace_
579  << cycle << "\t" << address << "\t" << sourceAddress << "\t"
580  << type << std::endl;
581 }

References callTrace_.

Referenced by ProcedureTransferTracker::addProcedureTransfer().

◆ addRegisterAccessCount()

void ExecutionTrace::addRegisterAccessCount ( RegisterFileID  registerFile,
RegisterID  registerIndex,
ClockCycleCount  reads,
ClockCycleCount  writes 
)

Adds a register access statistics to the database.

Statistics tells how many times a register was read and written during simulation.

Parameters
registerFileThe name of the register file.
registerIndexThe index of the register.
readsCount of reads.
writesCount of writes.
Exceptions
IOExceptionIn case an error in adding the data happened.

Definition at line 475 of file ExecutionTrace.cc.

477  {
478  const std::string query =
479  (boost::format(
480  "INSERT INTO register_access("
481  " register_file, register_index, reads, writes) "
482  "VALUES('%s', %d, %.0f, %.0f)")
483  % registerFile % registerIndex % reads % writes).str();
484 
485  assert(dbConnection_ != NULL);
486 
487  try {
488  dbConnection_->updateQuery(query);
489  } catch (const RelationalDBException& e) {
490  debugLog(query + " failed!");
491  throw IOException(__FILE__, __LINE__, __func__, e.errorMessage());
492  }
493 }

References __func__, assert, dbConnection_, debugLog, Exception::errorMessage(), and RelationalDBConnection::updateQuery().

Referenced by SimulatorFrontend::finishSimulation().

Here is the call graph for this function:

◆ addSocketWriteCount()

void ExecutionTrace::addSocketWriteCount ( SocketID  socket,
ClockCycleCount  count 
)

Adds a socket write count statistics to the database.

This stats tells in how many clock cycles was a socket used (transported data through).

Parameters
socketThe name of the socket.
countThe count of writes/uses.
Exceptions
IOExceptionIn case an error in adding the data happened.

Definition at line 631 of file ExecutionTrace.cc.

631  {
632  const std::string query =
633  std::string("") +
634  "INSERT INTO socket_write_counts(socket, writes) "
635  "VALUES('" + socket + "', " + Conversion::toString(count) + ")";
636 
637  assert(dbConnection_ != NULL);
638 
639  try {
640  dbConnection_->updateQuery(query);
641  } catch (const RelationalDBException& e) {
642  debugLog(query + " failed!");
643  throw IOException(__FILE__, __LINE__, __func__, e.errorMessage());
644  }
645 }

References __func__, assert, dbConnection_, debugLog, Exception::errorMessage(), Conversion::toString(), and RelationalDBConnection::updateQuery().

Referenced by SimulatorFrontend::finishSimulation().

Here is the call graph for this function:

◆ busWriteCount()

ClockCycleCount ExecutionTrace::busWriteCount ( BusID  bus) const

Returns the count of clock cycles in which a bus was written to.

In case no data was found for the given bus in DB, returns 0.

Parameters
busThe name of the bus.
Returns
The count of writes/accesses.

Definition at line 713 of file ExecutionTrace.cc.

713  {
714 
715  RelationalDBQueryResult* result = NULL;
716  ClockCycleCount count = 0;
717  try {
718  result = dbConnection_->query(
719  (boost::format(
720  "SELECT writes FROM bus_write_counts "
721  "WHERE bus LIKE('%s')") % bus).str());
722 
723  if (result->hasNext()) {
724  result->next();
725  count = (result->data("writes")).integerValue();
726  }
727  } catch (const Exception&) {
728  }
729  delete result;
730  result = NULL;
731  return count;
732 }

References RelationalDBQueryResult::data(), dbConnection_, RelationalDBQueryResult::hasNext(), RelationalDBQueryResult::next(), and RelationalDBConnection::query().

Referenced by DefaultICDecoderEstimator::estimateICEnergy().

Here is the call graph for this function:

◆ functionUnitOperationTriggerCounts()

ExecutionTrace::FUOperationTriggerCountList * ExecutionTrace::functionUnitOperationTriggerCounts ( FunctionUnitID  functionUnit) const

Returns the list of operation access counts for wanted function unit.

Parameters
functionUnitThe function unit for which the stats are needed.
Returns
A list of access counts. Must be deleted by the client after use.
Exceptions
IOExceptionIf an I/O error occurs.

Definition at line 591 of file ExecutionTrace.cc.

592  {
593  FUOperationTriggerCountList* accesses = NULL;
594  try {
595  assert(dbConnection_ != NULL);
596 
597  RelationalDBQueryResult* result =
599  std::string("") +
600  "SELECT * FROM fu_operation_triggers WHERE function_unit "
601  "LIKE('" + functionUnit + "')");
602  accesses = new FUOperationTriggerCountList();
603  while (result->hasNext()) {
604  result->next();
605  accesses->push_back(
606  boost::make_tuple(
607  (result->data("operation")).stringValue(),
608  (result->data("count")).integerValue()));
609  }
610  delete result;
611  result = NULL;
612  } catch (const Exception& e) {
613  delete accesses;
614  throw IOException(__FILE__, __LINE__, __func__, e.errorMessage());
615  }
616 
617  return accesses;
618 }

References __func__, assert, RelationalDBQueryResult::data(), dbConnection_, Exception::errorMessage(), RelationalDBQueryResult::hasNext(), RelationalDBQueryResult::next(), and RelationalDBConnection::query().

Referenced by StrictMatchFUEstimator::estimateEnergy(), and InterpolatingFUEstimator::estimateEnergy().

Here is the call graph for this function:

◆ initialize()

void ExecutionTrace::initialize ( )
private

Initializes a new trace database.

Exceptions
IOExceptionIf an I/O error occured.

Definition at line 243 of file ExecutionTrace.cc.

243  {
244  assert(dbConnection_ != NULL);
245 
246  try {
257 
259  (boost::format(
260  "INSERT INTO database_info(version) VALUES (%d);") %
261  DB_VERSION).str());
262 
263  } catch (const RelationalDBException& e) {
264  debugLog(
265  std::string("") + "Error while initializing TraceDB. " +
266  e.errorMessage());
267  throw IOException(__FILE__, __LINE__, __func__, e.errorMessage());
268  }
269 }

References __func__, assert, CQ_BUS_ACTIVITY, CQ_BUS_WRITE_COUNTS, CQ_CONCURRENT_REGISTER_FILE_ACCESS, CQ_DATABASE_INFO, CQ_FU_OPERATION_TRIGGERS, CQ_INSTRUCTION_EXECUTION, CQ_PROCEDURE_ADDRESS_RANGE, CQ_REGISTER_ACCESS, CQ_SOCKET_WRITE_COUNTS, CQ_TOTALS, DB_VERSION, dbConnection_, RelationalDBConnection::DDLQuery(), debugLog, Exception::errorMessage(), and RelationalDBConnection::updateQuery().

Referenced by open().

Here is the call graph for this function:

◆ instructionExecutions()

InstructionExecution & ExecutionTrace::instructionExecutions ( )

Queries database for instruction execution entries.

Returns
A handle object which can be used to traverse through the results. The handle points to the first instruction execution in the list of executions, sorted by the cycle.
Exceptions
IOExceptionIf an I/O error occurs.

Definition at line 363 of file ExecutionTrace.cc.

363  {
364  if (instructionExecution_ != NULL) {
365  delete instructionExecution_;
366  instructionExecution_ = NULL;
367  }
368 
369  try {
372  "SELECT * FROM instruction_execution ORDER BY cycle"));
373  } catch (const Exception& e) {
374  throw IOException(__FILE__, __LINE__, __func__, e.errorMessage());
375  }
376 
377  return *instructionExecution_;
378 }

References __func__, dbConnection_, Exception::errorMessage(), instructionExecution_, and RelationalDBConnection::query().

Referenced by open().

Here is the call graph for this function:

◆ open() [1/2]

void ExecutionTrace::open ( )
protected

Initializes the trace files.

For the traceDB sqlite file, starts a new transaction. Transaction is committed in destructor. This consumes lots of memory but should reduce I/O to the minimum.

Definition at line 169 of file ExecutionTrace.cc.

169  {
172 }

References RelationalDBConnection::beginTransaction(), RelationalDB::connect(), db_, dbConnection_, and fileName_.

Referenced by SimulatorFrontend::initializeTracing(), and loadInputs().

Here is the call graph for this function:

◆ open() [2/2]

ExecutionTrace * ExecutionTrace::open ( const std::string &  fileName)
static

Creates a new execution trace database.

If the database file cannot be found, creates a new database file and initializes it. Some of the bigger traces are written to separate ascii files to speed up trace generation.

The filenames are formed as follows:

fileName The main traceDB relational database file, always created (e.g. foobar.tpef.1.trace). fileName.calls The call trace, produced with 'procedure_transfer_tracking' setting of ttasim (e.g. foobar.tpef.1.trace.calls). fileName.profile The instruction execution counts, produced with 'profile_data_saving' setting of ttasim (e.g. foobar.tpef.1.trace.profile).

Parameters
fileNameFull path to the traceDB file to be opened.
Returns
A pointer to opened execution trace database instance. Instance is owned by the client and should be deleted after use.
Exceptions
IOExceptionIf there was a problem opening the database, for example, if the file cannot be found and a new file cannot be created.

Definition at line 138 of file ExecutionTrace.cc.

138  {
139  ExecutionTrace* traceDB =
140  new ExecutionTrace(
141  fileName, FileSystem::fileExists(fileName) &&
142  !FileSystem::fileIsWritable(fileName));
143  try {
144  bool newDatabase = !FileSystem::fileExists(fileName);
145  traceDB->open();
146  if (newDatabase) {
147  traceDB->initialize();
148  } else {
149  // tests that the file is really a trace DB by querying the
150  // instruction_execution table
151  traceDB->instructionExecutions();
152  }
153  } catch (const RelationalDBException& e) {
154  delete traceDB;
155  throw IOException(__FILE__, __LINE__, __func__, e.errorMessage());
156  }
157 
158  return traceDB;
159 }

References __func__, Exception::errorMessage(), ExecutionTrace(), FileSystem::fileExists(), FileSystem::fileIsWritable(), initialize(), instructionExecutions(), and open().

Referenced by open().

Here is the call graph for this function:

◆ registerFileAccessCounts()

ExecutionTrace::ConcurrentRFAccessCountList * ExecutionTrace::registerFileAccessCounts ( RegisterFileID  registerFile) const

Returns the list of different concurrent register file access combinations and counts how many times those were encountered while simulating the program.

Parameters
registerFileThe register file for which the stats are needed.
Returns
A list of accesses. Must be deleted by the client after use.
Exceptions
IOExceptionIf an I/O error occurs.

Definition at line 505 of file ExecutionTrace.cc.

505  {
506  ConcurrentRFAccessCountList* accesses = NULL;
507  try {
508  assert(dbConnection_ != NULL);
509 
510  RelationalDBQueryResult* result =
512  std::string("") +
513  "SELECT * FROM concurrent_register_file_access " +
514  "WHERE register_file LIKE('" + registerFile + "')");
515  accesses = new ConcurrentRFAccessCountList();
516  while (result->hasNext()) {
517  result->next();
518  accesses->push_back(
519  boost::make_tuple(
520  (result->data("reads")).integerValue(),
521  (result->data("writes")).integerValue(),
522  (result->data("count")).integerValue()));
523  }
524  delete result;
525  result = NULL;
526  } catch (const Exception& e) {
527  delete accesses;
528  throw IOException(__FILE__, __LINE__, __func__, e.errorMessage());
529  }
530 
531  return accesses;
532 }

References __func__, assert, RelationalDBQueryResult::data(), dbConnection_, Exception::errorMessage(), RelationalDBQueryResult::hasNext(), RelationalDBQueryResult::next(), and RelationalDBConnection::query().

Referenced by StrictMatchRFEstimator::estimateEnergy(), and InterpolatingRFEstimator::estimateEnergy().

Here is the call graph for this function:

◆ setSimulatedCycleCount()

void ExecutionTrace::setSimulatedCycleCount ( ClockCycleCount  count)

Sets the total count of simulated clock cycles.

Parameters
countThe count of cycles.
Exceptions
IOExceptionIn case an error in adding the data happened.

Definition at line 741 of file ExecutionTrace.cc.

741  {
742  const std::string query =
743  std::string("") +
744  "INSERT INTO totals(value_name, integer_value) "
745  "VALUES('cycle_count', " + Conversion::toString(count) + ")";
746 
747  assert(dbConnection_ != NULL);
748 
749  try {
750  dbConnection_->updateQuery(query);
751  } catch (const RelationalDBException& e) {
752  debugLog(query + " failed!");
753  throw IOException(__FILE__, __LINE__, __func__, e.errorMessage());
754  }
755 }

References __func__, assert, dbConnection_, debugLog, Exception::errorMessage(), Conversion::toString(), and RelationalDBConnection::updateQuery().

Referenced by SimulatorFrontend::finishSimulation().

Here is the call graph for this function:

◆ simulatedCycleCount()

ClockCycleCount ExecutionTrace::simulatedCycleCount ( ) const

Gets the total count of simulated clock cycles.

Returns
The count of cycles.
Exceptions
IOExceptionIn case an error in getting the data happened.

Definition at line 764 of file ExecutionTrace.cc.

764  {
765  RelationalDBQueryResult* result = NULL;
766  try {
767  result = dbConnection_->query(
768  "SELECT integer_value FROM totals "
769  "WHERE value_name LIKE('cycle_count')");
770  if (!result->hasNext()) {
771  delete result;
772  result = NULL;
773  throw IOException(
774  __FILE__, __LINE__, __func__,
775  "No 'cycle_count' entry in 'totals' table.");
776  }
777  result->next();
778  ClockCycleCount count = (result->data("integer_value")).integerValue();
779  delete result;
780  result = NULL;
781  return count;
782  } catch (const Exception& e) {
783  delete result;
784  result = NULL;
785  throw IOException(__FILE__, __LINE__, __func__, e.errorMessage());
786  }
787 }

References __func__, RelationalDBQueryResult::data(), dbConnection_, Exception::errorMessage(), RelationalDBQueryResult::hasNext(), RelationalDBQueryResult::next(), and RelationalDBConnection::query().

Referenced by StrictMatchFUEstimator::estimateEnergy(), StrictMatchRFEstimator::estimateEnergy(), InterpolatingFUEstimator::estimateEnergy(), InterpolatingRFEstimator::estimateEnergy(), and DefaultICDecoderEstimator::estimateICEnergy().

Here is the call graph for this function:

◆ socketWriteCount()

ClockCycleCount ExecutionTrace::socketWriteCount ( SocketID  socket) const

Returns the count of clock cycles in which a socket was written to.

In case no data was found for the given socket in DB, returns 0.

Parameters
socketThe name of the socket.
Returns
The count of writes/accesses.

Definition at line 656 of file ExecutionTrace.cc.

656  {
657 
658  RelationalDBQueryResult* result = NULL;
659  ClockCycleCount count = 0;
660  try {
661  result = dbConnection_->query(
662  (boost::format(
663  "SELECT writes FROM socket_write_counts "
664  "WHERE socket LIKE('%s')") % socket).str());
665 
666  if (result->hasNext()) {
667  result->next();
668  count = (result->data("writes")).integerValue();
669  }
670  } catch (const Exception&) {
671  }
672  delete result;
673  result = NULL;
674  return count;
675 }

References RelationalDBQueryResult::data(), dbConnection_, RelationalDBQueryResult::hasNext(), RelationalDBQueryResult::next(), and RelationalDBConnection::query().

Referenced by DefaultICDecoderEstimator::estimateICEnergy().

Here is the call graph for this function:

Member Data Documentation

◆ callTrace_

std::fstream ExecutionTrace::callTrace_
private

The call trace file.

Definition at line 199 of file ExecutionTrace.hh.

Referenced by addProcedureTransfer(), and ~ExecutionTrace().

◆ db_

RelationalDB* ExecutionTrace::db_
private

Handle to the sqlite trace database.

Definition at line 205 of file ExecutionTrace.hh.

Referenced by open(), and ~ExecutionTrace().

◆ dbConnection_

RelationalDBConnection* ExecutionTrace::dbConnection_
private

◆ fileName_

const std::string& ExecutionTrace::fileName_
private

Filename of the trace database (sqlite file).

Definition at line 197 of file ExecutionTrace.hh.

Referenced by open().

◆ instructionExecution_

InstructionExecution* ExecutionTrace::instructionExecution_
private

Handle object for the queries of instruction executions.

Definition at line 209 of file ExecutionTrace.hh.

Referenced by instructionExecutions(), and ~ExecutionTrace().

◆ instructionProfile_

std::fstream ExecutionTrace::instructionProfile_
private

The instruction profile file.

Definition at line 201 of file ExecutionTrace.hh.

Referenced by addInstructionExecutionCount(), and ~ExecutionTrace().

◆ readOnly_

bool ExecutionTrace::readOnly_
private

Is the database access mode read-only?

Definition at line 203 of file ExecutionTrace.hh.


The documentation for this class was generated from the following files:
CQ_DATABASE_INFO
const std::string CQ_DATABASE_INFO
database table creation queries (CQ)
Definition: ExecutionTrace.cc:48
RelationalDBConnection::updateQuery
virtual int updateQuery(const std::string &queryString)=0
Definition: RelationalDBConnection.cc:54
SimValue::doubleWordValue
DoubleWord doubleWordValue() const
Definition: SimValue.cc:1052
CQ_REGISTER_ACCESS
const std::string CQ_REGISTER_ACCESS
Definition: ExecutionTrace.cc:80
RelationalDBException
Definition: Exception.hh:692
ExecutionTrace::PT_EXIT
@ PT_EXIT
procedure exit
Definition: ExecutionTrace.hh:98
RelationalDB::connect
virtual RelationalDBConnection & connect(const std::string &database, const std::string &login="", const std::string &password="", bool readOnly=false)=0
ExecutionTrace::fileName_
const std::string & fileName_
Filename of the trace database (sqlite file).
Definition: ExecutionTrace.hh:197
RelationalDBQueryResult::data
virtual const DataObject & data(std::size_t column) const =0
Definition: RelationalDBQueryResult.cc:96
Application::writeToErrorLog
static void writeToErrorLog(const std::string fileName, const int lineNumber, const std::string functionName, const std::string message, const int neededVerbosity=0)
Definition: Application.cc:224
ExecutionTrace::ExecutionTrace
ExecutionTrace(const std::string &fileName, bool readOnly)
Definition: ExecutionTrace.cc:180
NullSimValue::instance
static SimValue & instance()
Definition: SimValue.cc:1642
ExecutionTrace::FUOperationTriggerCountList
std::list< FUOperationTriggerCount > FUOperationTriggerCountList
type to be used for lists of function operation execution counts
Definition: ExecutionTrace.hh:116
RelationalDBConnection::commit
virtual void commit()=0
Definition: RelationalDBConnection.cc:110
CQ_CONCURRENT_REGISTER_FILE_ACCESS
const std::string CQ_CONCURRENT_REGISTER_FILE_ACCESS
Definition: ExecutionTrace.cc:73
ExecutionTrace::PT_ENTRY
@ PT_ENTRY
procedure entry
Definition: ExecutionTrace.hh:97
SimValue::uIntWordValue
UIntWord uIntWordValue() const
Definition: SimValue.cc:972
Conversion::toString
static std::string toString(const T &source)
RelationalDBQueryResult::hasNext
virtual bool hasNext()=0
Definition: RelationalDBQueryResult.cc:126
assert
#define assert(condition)
Definition: Application.hh:86
DB_VERSION
const int DB_VERSION
the version number of the database schema
Definition: ExecutionTrace.cc:109
ExecutionTrace::instructionProfile_
std::fstream instructionProfile_
The instruction profile file.
Definition: ExecutionTrace.hh:201
RelationalDB::close
virtual void close(const RelationalDBConnection &connection)=0
FileSystem::fileIsWritable
static bool fileIsWritable(const std::string fileName)
RelationalDBQueryResult::next
virtual bool next()=0
Definition: RelationalDBQueryResult.cc:138
CQ_INSTRUCTION_EXECUTION
const std::string CQ_INSTRUCTION_EXECUTION
Definition: ExecutionTrace.cc:53
CQ_TOTALS
const std::string CQ_TOTALS
Definition: ExecutionTrace.cc:103
InstructionExecution
Definition: InstructionExecution.hh:45
ExecutionTrace
Definition: ExecutionTrace.hh:56
CQ_BUS_WRITE_COUNTS
const std::string CQ_BUS_WRITE_COUNTS
Definition: ExecutionTrace.cc:93
CQ_BUS_ACTIVITY
const std::string CQ_BUS_ACTIVITY
Definition: ExecutionTrace.cc:64
RelationalDBQueryResult
Definition: RelationalDBQueryResult.hh:46
__func__
#define __func__
Definition: Application.hh:67
ExecutionTrace::db_
RelationalDB * db_
Handle to the sqlite trace database.
Definition: ExecutionTrace.hh:205
RelationalDBConnection::query
virtual RelationalDBQueryResult * query(const std::string &queryString, bool init=true)=0
Definition: RelationalDBConnection.cc:80
ExecutionTrace::instructionExecutions
InstructionExecution & instructionExecutions()
Definition: ExecutionTrace.cc:363
Exception
Definition: Exception.hh:54
CQ_SOCKET_WRITE_COUNTS
const std::string CQ_SOCKET_WRITE_COUNTS
Definition: ExecutionTrace.cc:98
ExecutionTrace::instructionExecution_
InstructionExecution * instructionExecution_
Handle object for the queries of instruction executions.
Definition: ExecutionTrace.hh:209
ExecutionTrace::readOnly_
bool readOnly_
Is the database access mode read-only?
Definition: ExecutionTrace.hh:203
RelationalDBConnection::beginTransaction
virtual void beginTransaction()=0
Definition: RelationalDBConnection.cc:92
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
ExecutionTrace::open
static ExecutionTrace * open(const std::string &fileName)
Definition: ExecutionTrace.cc:138
RelationalDBConnection::DDLQuery
virtual void DDLQuery(const std::string &queryString)=0
Definition: RelationalDBConnection.cc:69
CQ_PROCEDURE_ADDRESS_RANGE
const std::string CQ_PROCEDURE_ADDRESS_RANGE
Definition: ExecutionTrace.cc:58
FileSystem::fileExists
static bool fileExists(const std::string fileName)
ExecutionTrace::initialize
void initialize()
Definition: ExecutionTrace.cc:243
CQ_FU_OPERATION_TRIGGERS
const std::string CQ_FU_OPERATION_TRIGGERS
Definition: ExecutionTrace.cc:87
ExecutionTrace::callTrace_
std::fstream callTrace_
The call trace file.
Definition: ExecutionTrace.hh:199
ClockCycleCount
CycleCount ClockCycleCount
Alias for ClockCycleCount.
Definition: SimulatorConstants.hh:57
ExecutionTrace::ConcurrentRFAccessCountList
std::list< ConcurrentRFAccessCount > ConcurrentRFAccessCountList
type to be used for a list of concurrent RF accesses
Definition: ExecutionTrace.hh:108
IOException
Definition: Exception.hh:130
ExecutionTrace::dbConnection_
RelationalDBConnection * dbConnection_
Handle to the database connection;.
Definition: ExecutionTrace.hh:207
debugLog
#define debugLog(text)
Definition: Application.hh:95
SQLite
Definition: SQLite.hh:45