Encode ovnievents output for HTML

This commit is contained in:
Rodrigo Arias 2024-01-29 18:53:11 +01:00
parent df0e7b2bd4
commit 68fc8b0eba
2 changed files with 69 additions and 12 deletions

View File

@ -8,7 +8,7 @@ Built on Jan 29 2024.
List of events for the model *nanos6* with identifier **`6`** at version `1.0.0`:
<dl>
<dt><a id="6Yc" href="#6Yc"><pre>6Yc+(u32 typeid, str label)</pre></a></dt>
<dd>creates task type %{typeid} with label "%{label}"</dd>
<dd>creates task type %{typeid} with label &quot;%{label}&quot;</dd>
<dt><a id="6Tc" href="#6Tc"><pre>6Tc(u32 taskid, u32 typeid)</pre></a></dt>
<dd>creates task %{taskid} with type %{typeid}</dd>
<dt><a id="6Tx" href="#6Tx"><pre>6Tx(u32 taskid)</pre></a></dt>
@ -400,7 +400,7 @@ List of events for the model *ovni* with identifier **`O`** at version `1.0.0`:
<dt><a id="OAr" href="#OAr"><pre>OAr(i32 cpu, i32 tid)</pre></a></dt>
<dd>changes the affinity of thread %{tid} to CPU %{cpu}</dd>
<dt><a id="OAs" href="#OAs"><pre>OAs(i32 cpu)</pre></a></dt>
<dd>switches it's own affinity to the CPU %{cpu}</dd>
<dd>switches it&apos;s own affinity to the CPU %{cpu}</dd>
<dt><a id="OB." href="#OB."><pre>OB.</pre></a></dt>
<dd>emits a burst event to measure latency</dd>
<dt><a id="OHC" href="#OHC"><pre>OHC(i32 cpu, u64 tag)</pre></a></dt>
@ -498,7 +498,7 @@ List of events for the model *nosv* with identifier **`V`** at version `1.0.0`:
<dt><a id="VTr" href="#VTr"><pre>VTr(u32 taskid)</pre></a></dt>
<dd>resumes the task %{taskid}</dd>
<dt><a id="VYc" href="#VYc"><pre>VYc+(u32 typeid, str label)</pre></a></dt>
<dd>creates task type %{typeid} with label "%{label}"</dd>
<dd>creates task type %{typeid} with label &quot;%{label}&quot;</dd>
<dt><a id="VSr" href="#VSr"><pre>VSr</pre></a></dt>
<dd>receives a task from another thread</dd>
<dt><a id="VSs" href="#VSs"><pre>VSs</pre></a></dt>

View File

@ -16,19 +16,66 @@
#include "stream.h"
#include "trace.h"
static void
static int
html_encode(char *dst, int ndst, const char *src)
{
int j = 0;
int nsrc = strlen(src);
for (int i = 0; i < nsrc; i++) {
/* Simple check */
if (j + 10 >= ndst) {
err("not enough room");
return -1;
}
int c = src[i];
switch (c) {
case '&': strcpy(&dst[j], "&amp;"); j += 5; break;
case '"': strcpy(&dst[j], "&quot;"); j += 6; break;
case '\'': strcpy(&dst[j], "&apos;"); j += 6; break;
case '<': strcpy(&dst[j], "&lt;"); j += 4; break;
case '>': strcpy(&dst[j], "&gt;"); j += 4; break;
default: dst[j++] = c; break;
}
}
dst[j] = '\0';
return 0;
}
static int
print_event(struct model_spec *spec, long i)
{
struct ev_decl *evdecl = &spec->evlist[i];
struct ev_spec *evspec = &spec->evspec->alloc[i];
const char *name = evspec->mcv;
char name[16];
if (html_encode(name, 16, evspec->mcv) != 0) {
err("html_encode failed for %s", evspec->mcv);
return -1;
}
printf("<dt><a id=\"%s\" href=\"#%s\"><pre>%s</pre></a></dt>\n", name, name, evdecl->signature);
printf("<dd>%s</dd>\n", evdecl->description);
char signature[1024];
if (html_encode(signature, 1024, evdecl->signature) != 0) {
err("html_encode failed for %s", evdecl->signature);
return -1;
}
char desc[1024];
if (html_encode(desc, 1024, evdecl->description) != 0) {
err("html_encode failed for %s", evdecl->description);
return -1;
}
printf("<dt><a id=\"%s\" href=\"#%s\"><pre>%s</pre></a></dt>\n", name, name, signature);
printf("<dd>%s</dd>\n", desc);
return 0;
}
static void
static int
print_model(struct model_spec *spec)
{
printf("\n");
@ -38,9 +85,16 @@ print_model(struct model_spec *spec)
spec->name, spec->model, spec->version);
printf("<dl>\n");
for (long j = 0; j < spec->evspec->nevents; j++)
print_event(spec, j);
for (long j = 0; j < spec->evspec->nevents; j++) {
if (print_event(spec, j) != 0) {
err("cannot print event %d", j);
return -1;
}
}
printf("</dl>\n");
return 0;
}
int
@ -54,7 +108,7 @@ main(void)
/* Register all the models */
if (models_register(&model) != 0) {
err("failed to register models");
return -1;
return 1;
}
printf("# Emulator events\n");
@ -66,7 +120,10 @@ main(void)
if (!model.registered[i])
continue;
print_model(model.spec[i]);
if (print_model(model.spec[i]) != 0) {
err("cannot print model %c events", i);
return 1;
}
}
return 0;