sptimecounter02: Convert to JSON data

This avoids a dependency on the non-standard libxml2 module.
This commit is contained in:
Sebastian Huber
2024-01-09 10:27:39 +01:00
parent 7cf8aa7f72
commit 8e26f7ef02
3 changed files with 116 additions and 1060 deletions

View File

@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (c) 2015 embedded brains GmbH & Co. KG
* Copyright (C) 2015, 2024 embedded brains GmbH & Co. KG
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -61,6 +61,8 @@ const char rtems_test_name[] = "SPTIMECOUNTER 2";
typedef struct {
rtems_test_parallel_context base;
const char *test_sep;
const char *counter_sep;
struct timecounter tc_null;
uint32_t binuptime_per_job[CPU_COUNT];
sbintime_t duration_per_job[CPU_COUNT];
@@ -90,6 +92,45 @@ static void install_tc_null(timecounter_context *ctx)
rtems_timecounter_install(tc_cpu);
}
static void test_print_results(
const char *driver,
timecounter_context *ctx,
size_t active_workers
)
{
const char *value_sep;
size_t i;
if (active_workers == 1) {
printf(
"%s{\n"
" \"timecounter\": \"%s\",\n"
" \"counter\": [",
ctx->test_sep,
driver
);
ctx->test_sep = ", ";
ctx->counter_sep = "\n ";
}
printf("%s[", ctx->counter_sep);
ctx->counter_sep = "],\n ";
value_sep = "";
for (i = 0; i < active_workers; ++i) {
printf(
"%s%" PRIu32,
value_sep,
ctx->binuptime_per_job[i]
);
value_sep = ", ";
}
if (active_workers == rtems_scheduler_get_processor_maximum()) {
printf("]\n ]\n }");
}
}
static rtems_interval test_bintime_init(
rtems_test_parallel_context *base,
void *arg,
@@ -133,25 +174,14 @@ static void test_bintime_fini(
timecounter_context *ctx = (timecounter_context *) base;
size_t i;
printf(" <BinuptimeTest activeWorker=\"%zu\">\n", active_workers);
for (i = 0; i < active_workers; ++i) {
sbintime_t error;
printf(
" <Counter worker=\"%zu\">%" PRIu32 "</Counter>\n"
" <Duration worker=\"%zu\" unit=\"sbintime\">%" PRId64 "</Duration>\n",
i + 1,
ctx->binuptime_per_job[i],
i + 1,
ctx->duration_per_job[i]
);
error = DURATION_IN_SECONDS * SBT_1S - ctx->duration_per_job[i];
rtems_test_assert(error * error < SBT_1MS * SBT_1MS);
}
printf(" </BinuptimeTest>\n");
test_print_results("Clock Driver", ctx, active_workers);
}
static rtems_interval test_bintime_null_init(
@@ -192,20 +222,7 @@ static void test_bintime_null_fini(
size_t active_workers
)
{
timecounter_context *ctx = (timecounter_context *) base;
size_t i;
printf(" <BinuptimeNullTest activeWorker=\"%zu\">\n", active_workers);
for (i = 0; i < active_workers; ++i) {
printf(
" <Counter worker=\"%zu\">%" PRIu32 "</Counter>\n",
i + 1,
ctx->binuptime_per_job[i]
);
}
printf(" </BinuptimeNullTest>\n");
test_print_results("Null", (timecounter_context *) base, active_workers);
}
static const rtems_test_parallel_job timecounter_jobs[] = {
@@ -231,8 +248,9 @@ static void Init(rtems_task_argument arg)
TEST_BEGIN();
printf("<SPTimecounter01>\n");
printf("*** BEGIN OF JSON DATA ***\n[\n ");
ctx->test_sep = "";
rtems_test_parallel(
&ctx->base,
NULL,
@@ -240,6 +258,8 @@ static void Init(rtems_task_argument arg)
RTEMS_ARRAY_SIZE(timecounter_jobs)
);
printf("\n]\n*** END OF JSON DATA ***\n");
/* Check for all functions available in the bsd.h user space */
rtems_bsd_bintime(&bt);
@@ -255,8 +275,6 @@ static void Init(rtems_task_argument arg)
rtems_bsd_getmicrouptime(&tv);
rtems_bsd_getnanouptime(&ts);
printf("</SPTimecounter01>\n");
TEST_END();
rtems_test_exit(0);
}

View File

@@ -1,9 +1,6 @@
#!/usr/bin/env python
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2016 embedded brains GmbH & Co. KG
# Copyright (C) 2016, 2024 embedded brains GmbH & Co. KG
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@@ -25,37 +22,38 @@
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
import json
import re
import libxml2
from libxml2 import xmlNode
import matplotlib.pyplot as plt
data = open('sptimecounter02.scn').read()
data = re.sub(r'\*\*\*.*\*\*\*', '', data)
doc = libxml2.parseDoc(data)
ctx = doc.xpathNewContext()
import matplotlib.pyplot as plt # type: ignore
from matplotlib import ticker # type: ignore
plt.title('Timestamp Performance')
plt.xlabel('Active Workers')
plt.ylabel('Operation Count')
def m(n):
return int(n.getContent())
def _plot(data: dict) -> None:
_, axes = plt.subplots()
axes.set_title("Timestamp Performance")
axes.set_xlabel("Active Workers")
axes.set_ylabel("Operation Count")
x = list(range(1, len(data[0]["counter"]) + 1))
axes.xaxis.set_major_locator(ticker.FixedLocator(x))
for samples in data:
y = [sum(values) for values in samples["counter"]]
axes.plot(x,
y,
label=samples["timecounter"],
marker="o")
axes.legend(loc="best")
plt.savefig("sptimecounter02.png")
plt.savefig("sptimecounter02.pdf")
plt.close()
def getCounterSums(variant):
w = 1
y = []
while True:
c = map(m, ctx.xpathEval('/SPTimecounter01/' + variant + '[@activeWorker="' + str(w) + '"]/Counter'))
if not c:
break
y.append(sum(c))
w = w + 1
return y
y = getCounterSums('BinuptimeTest')
x = range(1, len(y) + 1)
plt.xticks(x)
plt.plot(x, y, marker = 'o')
plt.show()
_JSON_DATA = re.compile(
r"\*\*\* BEGIN OF JSON DATA \*\*\*(.*)"
r"\*\*\* END OF JSON DATA \*\*\*", re.DOTALL)
with open("sptimecounter02.scn", "r", encoding="utf-8") as src:
match = _JSON_DATA.search(src.read())
data = json.loads(match.group(1))
_plot(data)

File diff suppressed because it is too large Load Diff