/* This function opens the trace file and converts the addresses to a
* 32 bit binary representation. This function is called every time
* a file is opened */
void MainWindow::on_actionOpen_triggered()
{
filename
= QFileDialog::getOpenFileName(this, tr
("Select Trace File"),
tr("Text Files (*.txt);;All Files (*)"));
if( filename.length() != 0 )
{
bool ok;
/* Zero out the LCD's, display the filename, and show the progress bar */
ui->writeLcd->display( 0 );
ui->readLcd->display( 0 );
ui->filenameText->setText( filename.mid( filename.lastIndexOf( "/") + 1 ) );
ui->progressBar->setVisible(true);
/* Open File */
QFile traceFile
( filename
);
/* This loop reads in each request from the file a line at a time.
* Convert memory request to binary and store into array. Each entry in array
* contains a 32-bit address, and a leading R or W signifying a Read/Write */
while( !inFileStream.atEnd() )
{
addr = inFileStream.readLine();
/* First extract read/write */
if( addr[0] == 'R' || addr[0] == 'r' )
{
/* Remove the R/W and any whitespace */
addr.remove(0, 1);
addr.trimmed();
/* Convert to binary and store in array */
addr = toBin( addr.toInt( &ok, 10 ) );
instruc.append( 'R' + addr );
ui->readLcd->display( ui->readLcd->value() + 1 );
}
else if( addr[0] == 'W' || addr[0] == 'w' )
{
/* Remove the R/W and any whitespace */
addr.remove(0, 1);
addr.trimmed();
/* Convert to binary and store in array */
addr = toBin( addr.toInt( &ok, 10 ) );
instruc.append( 'W' + addr );
ui->writeLcd->display( ui->writeLcd->value() + 1 );
}
}
traceFile.close();
/* Set for progress bar */
total = instruc.size() * 4;
/* Create four cache objects with different size N */
COACache a( 1, instruc );
/* The SIGNALS and SLOTS are to update the GUI */
connect( &a, SIGNAL(updateDone()), this, SLOT(updateProgBar()));
connect( &a, SIGNAL(updateMiss(int)), ui->n1MissLcd, SLOT(display(int)));
connect( &a, SIGNAL( updateHit(int) ), ui->n1HitLcd, SLOT( display(int) ));
connect( &a, SIGNAL(updateMRate(double)), ui->n1MRLcd, SLOT(display(double)));
connect( &a, SIGNAL(updateHRate(double)), ui->n1HRLcd, SLOT(display(double)));
connect( &a, SIGNAL(updateRep(int)), ui->n1RepLcd, SLOT(display(int)));
a.simulate();
COACache b( 2, instruc );
connect( &b, SIGNAL(updateDone()), this, SLOT(updateProgBar()));
connect( &b, SIGNAL(updateMiss(int)), ui->n2MissLcd, SLOT(display(int)));
connect( &b, SIGNAL( updateHit(int) ), ui->n2HitLcd, SLOT( display(int) ));
connect( &b, SIGNAL(updateMRate(double)), ui->n2MRLcd, SLOT(display(double)));
connect( &b, SIGNAL(updateHRate(double)), ui->n2HRLcd, SLOT(display(double)));
connect( &b, SIGNAL(updateRep(int)), ui->n2RepLcd, SLOT(display(int)));
b.simulate();
COACache c( 4, instruc );
connect( &c, SIGNAL(updateDone()), this, SLOT(updateProgBar()));
connect( &c, SIGNAL(updateMiss(int)), ui->n4MissLcd, SLOT(display(int)));
connect( &c, SIGNAL( updateHit(int) ), ui->n4HitLcd, SLOT( display(int) ));
connect( &c, SIGNAL(updateMRate(double)), ui->n4MRLcd, SLOT(display(double)));
connect( &c, SIGNAL(updateHRate(double)), ui->n4HRLcd, SLOT(display(double)));
connect( &c, SIGNAL(updateRep(int)), ui->n4RepLcd, SLOT(display(int)));
c.simulate();
COACache d( 8, instruc );
connect( &d, SIGNAL(updateDone()), this, SLOT(updateProgBar()));
connect( &d, SIGNAL(updateMiss(int)), ui->n8MissLcd, SLOT(display(int)));
connect( &d, SIGNAL( updateHit(int) ), ui->n8HitLcd, SLOT( display(int) ));
connect( &d, SIGNAL(updateMRate(double)), ui->n8MRLcd, SLOT(display(double)));
connect( &d, SIGNAL(updateHRate(double)), ui->n8HRLcd, SLOT(display(double)));
connect( &d, SIGNAL(updateRep(int)), ui->n8RepLcd, SLOT(display(int)));
d.simulate();
ui->progressBar->setVisible(false);
}
}
/* This function opens the trace file and converts the addresses to a
* 32 bit binary representation. This function is called every time
* a file is opened */
void MainWindow::on_actionOpen_triggered()
{
QString filename;
filename = QFileDialog::getOpenFileName(this, tr("Select Trace File"),
QDir::currentPath(),
tr("Text Files (*.txt);;All Files (*)"));
if( filename.length() != 0 )
{
QString addr;
bool ok;
QStringList instruc;
/* Zero out the LCD's, display the filename, and show the progress bar */
ui->writeLcd->display( 0 );
ui->readLcd->display( 0 );
ui->filenameText->setText( filename.mid( filename.lastIndexOf( "/") + 1 ) );
ui->progressBar->setVisible(true);
/* Open File */
QFile traceFile( filename );
traceFile.open( QIODevice::ReadOnly );
QTextStream inFileStream( &traceFile );
/* This loop reads in each request from the file a line at a time.
* Convert memory request to binary and store into array. Each entry in array
* contains a 32-bit address, and a leading R or W signifying a Read/Write */
while( !inFileStream.atEnd() )
{
addr = inFileStream.readLine();
/* First extract read/write */
if( addr[0] == 'R' || addr[0] == 'r' )
{
/* Remove the R/W and any whitespace */
addr.remove(0, 1);
addr.trimmed();
/* Convert to binary and store in array */
addr = toBin( addr.toInt( &ok, 10 ) );
instruc.append( 'R' + addr );
ui->readLcd->display( ui->readLcd->value() + 1 );
}
else if( addr[0] == 'W' || addr[0] == 'w' )
{
/* Remove the R/W and any whitespace */
addr.remove(0, 1);
addr.trimmed();
/* Convert to binary and store in array */
addr = toBin( addr.toInt( &ok, 10 ) );
instruc.append( 'W' + addr );
ui->writeLcd->display( ui->writeLcd->value() + 1 );
}
}
traceFile.close();
/* Set for progress bar */
total = instruc.size() * 4;
/* Create four cache objects with different size N */
COACache a( 1, instruc );
/* The SIGNALS and SLOTS are to update the GUI */
connect( &a, SIGNAL(updateDone()), this, SLOT(updateProgBar()));
connect( &a, SIGNAL(updateMiss(int)), ui->n1MissLcd, SLOT(display(int)));
connect( &a, SIGNAL( updateHit(int) ), ui->n1HitLcd, SLOT( display(int) ));
connect( &a, SIGNAL(updateMRate(double)), ui->n1MRLcd, SLOT(display(double)));
connect( &a, SIGNAL(updateHRate(double)), ui->n1HRLcd, SLOT(display(double)));
connect( &a, SIGNAL(updateRep(int)), ui->n1RepLcd, SLOT(display(int)));
a.simulate();
COACache b( 2, instruc );
connect( &b, SIGNAL(updateDone()), this, SLOT(updateProgBar()));
connect( &b, SIGNAL(updateMiss(int)), ui->n2MissLcd, SLOT(display(int)));
connect( &b, SIGNAL( updateHit(int) ), ui->n2HitLcd, SLOT( display(int) ));
connect( &b, SIGNAL(updateMRate(double)), ui->n2MRLcd, SLOT(display(double)));
connect( &b, SIGNAL(updateHRate(double)), ui->n2HRLcd, SLOT(display(double)));
connect( &b, SIGNAL(updateRep(int)), ui->n2RepLcd, SLOT(display(int)));
b.simulate();
COACache c( 4, instruc );
connect( &c, SIGNAL(updateDone()), this, SLOT(updateProgBar()));
connect( &c, SIGNAL(updateMiss(int)), ui->n4MissLcd, SLOT(display(int)));
connect( &c, SIGNAL( updateHit(int) ), ui->n4HitLcd, SLOT( display(int) ));
connect( &c, SIGNAL(updateMRate(double)), ui->n4MRLcd, SLOT(display(double)));
connect( &c, SIGNAL(updateHRate(double)), ui->n4HRLcd, SLOT(display(double)));
connect( &c, SIGNAL(updateRep(int)), ui->n4RepLcd, SLOT(display(int)));
c.simulate();
COACache d( 8, instruc );
connect( &d, SIGNAL(updateDone()), this, SLOT(updateProgBar()));
connect( &d, SIGNAL(updateMiss(int)), ui->n8MissLcd, SLOT(display(int)));
connect( &d, SIGNAL( updateHit(int) ), ui->n8HitLcd, SLOT( display(int) ));
connect( &d, SIGNAL(updateMRate(double)), ui->n8MRLcd, SLOT(display(double)));
connect( &d, SIGNAL(updateHRate(double)), ui->n8HRLcd, SLOT(display(double)));
connect( &d, SIGNAL(updateRep(int)), ui->n8RepLcd, SLOT(display(int)));
d.simulate();
ui->progressBar->setVisible(false);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks