Skip to content

Commit

Permalink
Adding a post_run_hook to TraceCmd (open-s4c#96)
Browse files Browse the repository at this point in the history
This post_run_hook can be used to do processing of the data generated by
trace-cmd.

Signed-off-by: Mats Van Molle <[email protected]>
  • Loading branch information
matsvanmolle authored Aug 24, 2024
1 parent 1ea9916 commit 18db12a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
40 changes: 32 additions & 8 deletions benchkit/commandattachments/tracecmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: MIT

from typing import List
from benchkit.benchmark import RecordResult, WriteRecordFileFunction
from benchkit.shell.shellasync import AsyncProcess
from benchkit.utils.types import PathType
from benchkit.platforms import get_current_platform, Platform
Expand All @@ -11,10 +12,12 @@
class TraceCmd:

def __init__(self, events: List[str] = (), platform: Platform = None,) -> None:
self.events = [str(e) for e in events]
self.platform = platform if platform is not None else get_current_platform()
self._events = [str(e) for e in events]
self._platform = platform if platform is not None else get_current_platform()
self._pid = None
self._process = None

def attachement(
def attachment(
self,
process: AsyncProcess,
record_data_dir: PathType,
Expand All @@ -23,20 +26,41 @@ def attachement(
rdd = pathlib.Path(record_data_dir)
out_file = rdd / "trace.dat"

pid = process.pid
self._pid = process.pid
command = ["sudo", "trace-cmd", "record"]

# Add "-e" and each event to the command list
for event in self.events:
for event in self._events:
command.extend(["-e", event])

# Add the PID and output file arguments
command.extend(["-P", f"{pid}", "-o", f"{out_file}"])
command.extend(["-P", f"{self._pid}", "-o", f"{out_file}"])

AsyncProcess(
platform=self.platform,
self._process = AsyncProcess(
platform=self._platform,
arguments=command,
stdout_path=rdd / "trace-cmd.out",
stderr_path=rdd / "trace-cmd.err",
current_dir=rdd,
)

def post_run_hook(
self,
experiment_results_lines: List[RecordResult],
record_data_dir: PathType,
write_record_file_fun: WriteRecordFileFunction,
) -> None:
rdd = pathlib.Path(record_data_dir)
print(rdd)

self._process.wait()

command = ["trace-cmd", "report", "trace.dat"]

AsyncProcess(
platform=self._platform,
arguments=command,
stdout_path=rdd / "generate-graph.out",
stderr_path=rdd / "generate-graph.err",
current_dir=rdd,
)
6 changes: 3 additions & 3 deletions tests/campaigns/campaign_tracecmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

from benchmarks.cprogram import CProgramBench
from benchkit.campaign import CampaignIterateVariables
from benchkit.shell.shellasync import AsyncProcess
from benchkit.utils.types import PathType
from benchkit.platforms import get_current_platform
from benchkit.commandattachments.tracecmd import TraceCmd


def main() -> None:
platform = get_current_platform()

traceCmd = TraceCmd(["sched"], platform)
CampaignIterateVariables(
name="attach",
benchmark=CProgramBench(
command_attachments=[TraceCmd(["sched"], platform).attachement],
command_attachments=[traceCmd.attachment],
post_run_hooks=[traceCmd.post_run_hook]
),
nb_runs=1,
variables=[{}],
Expand Down

0 comments on commit 18db12a

Please sign in to comment.