summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mixutils/mixvm_command.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/mixutils/mixvm_command.c b/mixutils/mixvm_command.c
index 2c07be7..631b66d 100644
--- a/mixutils/mixvm_command.c
+++ b/mixutils/mixvm_command.c
@@ -199,6 +199,9 @@ static mix_dump_context_t *dc_ = NULL;
static mix_eval_t *eval_ = NULL;
/* trace status */
static gboolean is_tracing_ = FALSE;
+/* uptime */
+static mix_time_t uptime_ = 0;
+static mix_time_t prog_time_ = 0;
static int
@@ -267,12 +270,14 @@ cmd_load_ (char *arg)
fprintf (stderr, _("Program loaded. Start address: %d\n"),
mix_vm_get_prog_count (vm_));
+ prog_time_ = 0;
+
return TRUE;
}
/* trace current instruction */
static void
-trace_ ()
+trace_ (void)
{
enum {BUFFER_LEN = 128};
static gchar STRINS[BUFFER_LEN];
@@ -295,7 +300,7 @@ trace_ ()
}
static int
-run_and_trace_ ()
+run_and_trace_ (void)
{
int k = MIX_VM_OK;
if (!is_tracing_)
@@ -308,6 +313,16 @@ run_and_trace_ ()
return k;
}
+static void
+print_time_ (void)
+{
+ mix_time_t lapse = mix_vm_get_uptime(vm_) - uptime_;
+ uptime_ += lapse;
+ prog_time_ += lapse;
+ printf(_("Elapsed time: %ld /Total program time: %ld (Total uptime: %ld)\n"),
+ lapse, prog_time_, uptime_);
+}
+
static int
cmd_run_ (char *arg)
{
@@ -315,7 +330,11 @@ cmd_run_ (char *arg)
return TRUE;
puts (_("Running ..."));
- if (mix_vm_is_halted (vm_)) mix_vm_reset_program (vm_);
+ if (mix_vm_is_halted (vm_))
+ {
+ mix_vm_reset_program (vm_);
+ prog_time_ = 0;
+ }
switch (run_and_trace_ ())
{
@@ -340,6 +359,7 @@ cmd_run_ (char *arg)
g_assert_not_reached ();
break;
}
+ print_time_ ();
return TRUE;
}
@@ -362,6 +382,12 @@ cmd_next_ (char *arg)
ins_no = atoi (arg);
}
+ if (mix_vm_is_halted (vm_))
+ {
+ mix_vm_reset_program (vm_);
+ prog_time_ = 0;
+ }
+
while ( ins_no-- > 0 )
{
if (is_tracing_) trace_ ();
@@ -379,7 +405,7 @@ cmd_next_ (char *arg)
break;
}
}
-
+ print_time_ ();
return TRUE;
}