Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add litsupport module to collect QEMU plugin metrics #124

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions litsupport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(LITSUPPORT_FILES
modules/microbenchmark.py
modules/perf.py
modules/profilegen.py
modules/qemulog.py
modules/remote.py
modules/run.py
modules/run_under.py
Expand Down
51 changes: 51 additions & 0 deletions litsupport/modules/qemulog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""test-suite/lit plugin to collect metrics from QEMU logs.

If you are running the test suite under QEMU and are generating logs
that contain metrics (typically from a plugin), you can use this
module to:

1. save the logs to a file
2. parse any colon (:) separated metrics and collect them in the
metrics

For example, the example plugin libinsn.so outputs dynamic instruction
counts in the following format:

cpu 0 insns: 42
total insns: 1024

If you enable the plugin and tell QEMU to log it:

-DTEST_SUITE_RUN_UNDER='qemu -plugin libinsn.so -d plugin'
-DTEST_SUITE_EXTRA_LIT_MODULES=qemulog

You can then compare those instruction counts later:

./compare.py results.json -m 'total insns'

"""

from litsupport import shellcommand
from litsupport import testplan
from litsupport.modules import run_under


def _mutateCommandLine(context, commandline):
context.qemulog = context.tmpBase + ".qemulog"
cmd = shellcommand.parse(commandline)
cmd.envvars.update({"QEMU_LOG_FILENAME": context.qemulog})
return cmd.toCommandline()


def _getOutput(context):
with open(context.qemulog, "r") as f:
result = dict()
for line in f.read().splitlines():
[name, count] = line.split(":")
result[name] = int(count)
return result


def mutatePlan(context, plan):
plan.runscript = testplan.mutateScript(context, plan.runscript, _mutateCommandLine)
plan.metric_collectors.append(_getOutput)