Profiling.

This commit is contained in:
Christian Speckner 2019-02-27 23:41:08 +01:00
parent 1ba1332501
commit ac398ac31b
3 changed files with 124 additions and 1 deletions

View File

@ -15,13 +15,42 @@
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#include <chrono>
#include "ProfilingRunner.hxx"
#include "FSNode.hxx"
#include "CartDetector.hxx"
#include "Cart.hxx"
#include "MD5.hxx"
#include "Control.hxx"
#include "M6502.hxx"
#include "M6532.hxx"
#include "TIA.hxx"
#include "ConsoleTiming.hxx"
#include "DummyFrameManager.hxx"
#include "System.hxx"
#include "Joystick.hxx"
#include "Random.hxx"
#include "DispatchResult.hxx"
using namespace std::chrono;
namespace {
static constexpr uInt32 RUNTIME_DEFAULT = 60;
static constexpr uInt32 cyclesPerSecond = 262 * 76 * 60;
void updateProgress(uInt32 from, uInt32 to) {
while (from < to) {
if (from % 10 == 0 && from > 0) cout << from << "%";
else cout << ".";
cout.flush();
from++;
}
}
}
static constexpr uInt32 RUNTIME_DEFAULT = 60;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ProfilingRunner::ProfilingRunner(int argc, char* argv[])
@ -83,5 +112,57 @@ bool ProfilingRunner::runOne(const ProfilingRun run)
return false;
}
IO consoleIO;
Random rng(0);
Event event;
DummyFrameManager frameManager;
M6502 cpu(mySettings);
M6532 riot(consoleIO, mySettings);
TIA tia(consoleIO, []() { return ConsoleTiming::ntsc; }, mySettings);
System system(rng, cpu, riot, tia, *cartridge);
consoleIO.myLeftControl = make_unique<Joystick>(Controller::Left, event, system);
consoleIO.myRightControl = make_unique<Joystick>(Controller::Right, event, system);
consoleIO.mySwitches = make_unique<Switches>(event, myProps, mySettings);
tia.setFrameManager(&frameManager);
tia.bindToControllers();
cartridge->setStartBankFromPropsFunc([]() { return -1; });
system.initialize();
system.reset();
uInt64 cycles = 0;
uInt64 cyclesTarget = run.runtime * cyclesPerSecond;
DispatchResult dispatchResult;
dispatchResult.setOk(0);
uInt32 percent = 0;
(cout << "0%").flush();
time_point<high_resolution_clock> tp = high_resolution_clock::now();
while (cycles < cyclesTarget && dispatchResult.getStatus() == DispatchResult::Status::ok) {
tia.update(dispatchResult);
cycles += dispatchResult.getCycles();
uInt32 percentNow = std::min((100 * cycles) / cyclesTarget, static_cast<uInt64>(100));
updateProgress(percent, percentNow);
percent = percentNow;
}
double realtimeUsed = duration_cast<duration<double>>(high_resolution_clock::now () - tp).count();
if (dispatchResult.getStatus() != DispatchResult::Status::ok) {
cout << endl << "ERROR: emulation failed after " << cycles << " cycles";
return false;
}
(cout << "100%" << endl).flush();
cout << "real time: " << realtimeUsed << " seconds" << endl;
return true;
}

View File

@ -18,8 +18,13 @@
#ifndef PROFILING_RUNNER
#define PROFILING_RUNNER
class Control;
class Switches;
#include "bspf.hxx"
#include "Settings.hxx"
#include "ConsoleIO.hxx"
#include "Props.hxx"
class ProfilingRunner {
public:
@ -35,6 +40,16 @@ class ProfilingRunner {
uInt32 runtime;
};
struct IO: public ConsoleIO {
Controller& leftController() const override { return *myLeftControl; }
Controller& rightController() const override { return *myRightControl; }
Switches& switches() const override { return *mySwitches; }
unique_ptr<Controller> myLeftControl;
unique_ptr<Controller> myRightControl;
unique_ptr<Switches> mySwitches;
};
private:
bool runOne(const ProfilingRun run);
@ -44,6 +59,8 @@ class ProfilingRunner {
vector<ProfilingRun> profilingRuns;
Settings mySettings;
Properties myProps;
};
#endif // PROFILING_RUNNER

View File

@ -0,0 +1,25 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony
// and the Stella Team
//
// See the file "License.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#ifndef TIA_DUMMY_FRAME_MANAGER
#define TIA_DUMMY_FRAME_MANAGER
#include "AbstractFrameManager.hxx"
class DummyFrameManager: public AbstractFrameManager {};
#endif // TIA_DUMMY_FRAME_MANAGER