Skip to content

Commit

Permalink
Merge branch 'jpellegrini-vm-doc'
Browse files Browse the repository at this point in the history
  • Loading branch information
egallesio committed Jul 22, 2024
2 parents d74c987 + 9596660 commit 5bdb4d7
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions doc/vm/vm.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,20 @@ Restoring is easier:
And, when the C stack is restored, the VM is back to its original state, except
for the global variables.

== Verifying the VM configuration

The primitive `%vm-config` returns an association list describing the
compile-time configuration of the VM. For example,

```
stklos> (%vm-config )
(#:computed-goto #t #:debug-vm #f #:stat-vm #t)
```

* `#:computed-goto`: was `vm.c` compiled using computed `goto`?
* `#:debug-vm`: does this STklos binary have debugging enabled?
* `#:stat-vm`: was the VM compiled with code for statistics-collecting?

== Collecting statistics

The code in `vm.c` can optionally be compiled to collect statistics.
Expand All @@ -1691,15 +1705,16 @@ conditionally on `STAT_VM`):

[source,c]
----
void tick(STk_instr b) {
couple_instr[previous_op][b]++;
static void tick(STk_instr b, STk_instr *previous_op, clock_t *previous_time) {
static clock_t current_time;
current_time = clock();
couple_instr[*previous_op][b]++;
cpt_inst[b]++;
previous_op = b;
*previous_op = b;
current_time = clock();
if (previous_time > 0)
time_inst[b] += ((double)(current_time - previous_time)) / CLOCKS_PER_SEC;
previous_time = current_time;
if (*previous_time > 0)
time_inst[b] += ((double)(current_time - *previous_time)) / CLOCKS_PER_SEC;
*previous_time = clock();
}
----

Expand All @@ -1713,8 +1728,10 @@ Three Scheme primitives are then available:
below).
* `(%vm-reset-stats)` will reset all counters.
* `(%vm-collect-stats . val)` is a parameter object. When called without
value, it returns if statistics are collected or not. With a value `val`,
one can determine if statistics must be collected.
value, it returns if statistics are collected or not. If the value `val`
is determined, then statistics
- will start being collected, if `val` is `#t`;
- will not be collected anymore if `val` is `#f`.

Collecting statistics is off by default, especially because compiling STklos
is very slow with statistics gathering. It should be turned on before profiling.
Expand Down Expand Up @@ -1749,16 +1766,8 @@ The C code for printing the instructions is in the functions
`dump_couple_instr_csv` and `dump_couple_instr_scm`.

Note that the `%vm-config` can be used to determine if the system has been
compiled with the profiling code. This primitive returns a property list and
the key `#:stat-vm` can be used here:

[source,scheme]
----
stklos> (%vm-config)
(#:computed-goto #t #:debug-vm #f #:stat-vm #t)
stklos> (key-get (%vm-config) :stat-vm))
#t
----
compiled with the profiling code. As said before, this primitive returns a
property list and `#:stat-vm` can be used here.

To profile some specific code there is the `%with-profile-data` macro:

Expand Down

0 comments on commit 5bdb4d7

Please sign in to comment.