aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Buesch <m@bues.ch>2018-08-02 12:13:10 +0200
committerMichael Buesch <m@bues.ch>2018-08-02 12:13:10 +0200
commit433cbd6ff2940f20f45d32fd0d1993a8c13b1d2f (patch)
tree310ed8a1607c70237cd70d409c37a0d897639aa4
parentd694c896a46bc8320c61524f361ab247f0241909 (diff)
downloadxytronic-lf-433cbd6ff2940f20f45d32fd0d1993a8c13b1d2f.zip
xytronic-lf-433cbd6ff2940f20f45d32fd0d1993a8c13b1d2f.tar.xz
simulator: Add main loop statisticsHEADmaster
Signed-off-by: Michael Buesch <m@bues.ch>
-rw-r--r--firmware/simulator/pyxytronic.cxx13
-rw-r--r--firmware/simulator/simulator.cxx43
-rw-r--r--firmware/simulator/simulator.h1
-rwxr-xr-xfirmware/simulator/xytronic_simulator.py4
4 files changed, 61 insertions, 0 deletions
diff --git a/firmware/simulator/pyxytronic.cxx b/firmware/simulator/pyxytronic.cxx
index 3f34305..0e3924c 100644
--- a/firmware/simulator/pyxytronic.cxx
+++ b/firmware/simulator/pyxytronic.cxx
@@ -116,6 +116,18 @@ static PyObject * xy_simulator_uart_get_tx(PyObject *self, PyObject *args)
return bytes;
}
+static PyObject * xy_simulator_stats_ena(PyObject *self, PyObject *args)
+{
+ int mainloop_stats_ena;
+
+ if (!PyArg_ParseTuple(args, "p", &mainloop_stats_ena))
+ return NULL;
+
+ simulator_stats_ena(mainloop_stats_ena);
+
+ Py_RETURN_NONE;
+}
+
static PyObject * xy_simulator_mainloop_once(PyObject *self, PyObject *args)
{
simulator_mainloop_once();
@@ -145,6 +157,7 @@ static PyMethodDef xy_methods[] = {
{ "simulator_adc_set", xy_simulator_adc_set, METH_VARARGS, "", },
{ "simulator_pwm_get", xy_simulator_pwm_get, METH_VARARGS, "", },
{ "simulator_uart_get_tx", xy_simulator_uart_get_tx, METH_NOARGS, "", },
+ { "simulator_stats_ena", xy_simulator_stats_ena, METH_VARARGS, "", },
{ "simulator_mainloop_once", xy_simulator_mainloop_once, METH_NOARGS, "", },
{ "simulator_exit", xy_simulator_exit, METH_NOARGS, "", },
{ "simulator_init", xy_simulator_init, METH_NOARGS, "", },
diff --git a/firmware/simulator/simulator.cxx b/firmware/simulator/simulator.cxx
index 7c12575..cc484e1 100644
--- a/firmware/simulator/simulator.cxx
+++ b/firmware/simulator/simulator.cxx
@@ -58,6 +58,10 @@ struct sim_context {
int initialized;
std::thread io_thread;
volatile int io_thread_stop;
+ bool mainloop_stats_ena;
+ int mainloop_count;
+ uint64_t mainloop_count_begin;
+ double mainloops_per_sec;
/* EEPROM */
std::recursive_mutex eeprom_mutex;
@@ -87,6 +91,10 @@ struct sim_context {
{
initialized = 0;
io_thread_stop = 0;
+ mainloop_stats_ena = true;
+ mainloop_count = 0;
+ mainloop_count_begin = 0;
+ mainloops_per_sec = -1.0;
memset(uart_tx_buf, 0, sizeof(uart_tx_buf));
uart_tx_buf_write = 0;
@@ -506,14 +514,48 @@ bool simulator_setting_access(const char *name, int *value, bool write)
return false;
}
+void simulator_stats_ena(bool mainloop_stats_ena)
+{
+ sim.mainloop_stats_ena = mainloop_stats_ena;
+ sim.mainloop_count = 0;
+ sim.mainloop_count_begin = systime_ms_get();
+ sim.mainloops_per_sec = -1.0;
+}
+
void main_loop_once(void);
void simulator_mainloop_once(void)
{
+ uint64_t begin = 0, end = 0, runtime = 0;
+
if (!sim.initialized)
return;
+ if (sim.mainloop_stats_ena)
+ begin = systime_ms_get();
+
main_loop_once();
+
+ if (sim.mainloop_stats_ena) {
+ end = systime_ms_get();
+ runtime = end - begin;
+
+ if (++sim.mainloop_count >= 100) {
+ double loops_per_sec;
+ uint64_t duration;
+
+ duration = end - sim.mainloop_count_begin;
+ loops_per_sec = (double)(sim.mainloop_count * 1000) / (double)duration;
+
+ sim.mainloops_per_sec = loops_per_sec;
+ sim.mainloop_count = 0;
+ sim.mainloop_count_begin = end;
+ }
+
+ printf("Mainloop core runtime %llu ms\n%.1lf loops per second wallclock\n",
+ (unsigned long long)runtime,
+ sim.mainloops_per_sec);
+ }
}
void simulator_exit(void)
@@ -535,6 +577,7 @@ bool simulator_init(void)
return false;
sim.reset();
+ simulator_stats_ena(true);
fakeio_reset_all();
/* Install I/O register hooks. */
diff --git a/firmware/simulator/simulator.h b/firmware/simulator/simulator.h
index 4530eac..40824a0 100644
--- a/firmware/simulator/simulator.h
+++ b/firmware/simulator/simulator.h
@@ -14,6 +14,7 @@ bool simulator_pwm_get(int pwm_index, uint16_t *value, uint16_t *max_value);
bool simulator_adc_set(int adc_index, uint16_t value);
bool simulator_setting_access(const char *name, int *value, bool write);
+void simulator_stats_ena(bool mainloop_stats_ena);
void simulator_mainloop_once(void);
void simulator_exit(void);
bool simulator_init(void);
diff --git a/firmware/simulator/xytronic_simulator.py b/firmware/simulator/xytronic_simulator.py
index 5da3cb4..d5c7670 100755
--- a/firmware/simulator/xytronic_simulator.py
+++ b/firmware/simulator/xytronic_simulator.py
@@ -59,6 +59,7 @@ class Simulator(object):
self.__uartbuf = bytearray()
self.__reset_debuginterface()
self.__runHook = []
+ self.stats_ena()
def addRunHook(self, hook):
self.__runHook.append(hook)
@@ -69,6 +70,9 @@ class Simulator(object):
for hook in self.__runHook:
hook();
+ def stats_ena(self, mainloop_stats_ena=True):
+ self.xy.simulator_stats_ena(mainloop_stats_ena)
+
def setting_get(self, name):
value = self.xy.simulator_setting_read(name)
if self.SETTINGS[name] == "fixpt_t":
bues.ch cgit interface