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

Done automation for scheduler workflow. #2723

Open
wants to merge 1 commit into
base: master
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
173 changes: 173 additions & 0 deletions cpu/log_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#!/usr/bin/env python

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: 2023 IBM
# Author: Samir A Mulani <samir@linux.vnet.ibm.com>


import os
from avocado import Test
from avocado.utils import process
from avocado.utils import git
from avocado.utils.software_manager.manager import SoftwareManager
from avocado.utils import linux_modules


class log_generator(Test):
def setUp(self):
"""
Here in this test case we are running any cpu intensive workload
and capturing the disfferent logs,
Ex: perf_stat, strace and sched_scoreboard etc.
"""
pkgs = []
directory_name = "sched-scoreboard"
self.sched_scoreboard_dir = os.path.expanduser(f"~/{directory_name}")
self.uname = linux_modules.platform.uname()[2]
self.kernel_ver = "kernel-devel-%s" % self.uname
smm = SoftwareManager()
pkgs.extend(["strace", "perf", "trace-cmd", "git", "bpftrace"])
for pkg in pkgs:
if not smm.check_installed(pkg) and not smm.install(pkg):
self.cancel("Not able to install %s" % pkg)

self.user_command = self.params.get('user_command', default="sleep 10")
self.repeat = int(self.params.get('repeat', default="10"))

cmd = "command -v bpftrace &>/dev/null"
info = process.system_output(cmd, ignore_status=True)
if not info:
self.cancel(
"bpftrace is not installed. Please install it \
for sched-scoreboard to work.")

if os.path.exists(self.sched_scoreboard_dir) and os.path.isdir(
self.sched_scoreboard_dir):
os.chdir(self.sched_scoreboard_dir)
cmd = "git pull"
process.run(cmd, ignore_status=True, sudo=True, shell=True)
else:
os.mkdir(self.sched_scoreboard_dir)
os.chdir(self.sched_scoreboard_dir)
git.get_repo('https://github.com/AMDESE/sched-scoreboard.git',
branch='main',
destination_dir=self.sched_scoreboard_dir)

# Create symbolic link to bpftrace
cmd = 'ln -s "$(which bpftrace)" "%s/bpftrace"' % \
(self.sched_scoreboard_dir)
process.run(cmd, ignore_status=True, sudo=True, shell=True)

def test_sched_scoreboard_setup(self):
Copy link

@vishalc-ibm vishalc-ibm Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename this method to test_run_with_time_repeat

"""_summary_

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment can be removed

Here in this test case we are cloning the sched_scoreboard
repo and prepareing the sched_scoreboard to run.
"""
scoreboard_setup_log_file = self.logdir + "/sched_scoreboard_setup"
Copy link

@vishalc-ibm vishalc-ibm Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part will change to...

time_log_file = self.logdir + "/time"
os.mkdir(time_log_file)
log_file = "%s/time_command_output_%s.log" % (
                    time_log_file, self.kernel_ver)

os.mkdir(scoreboard_setup_log_file)

log_file = "%s/sched_scoreboard_command_output_%s.log" % (
scoreboard_setup_log_file, self.kernel_ver)
cmd = 'echo "Using command: %s >> %s" 2>&1' % (
self.user_command, log_file)
process.run(cmd, ignore_status=True, sudo=True, shell=True)

cmd = 'lscpu >> "%s" 2>&1' % (log_file)
Copy link

@vishalc-ibm vishalc-ibm Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test need not run lscpu
This should get captured by sysinfo utility
(preferably per-job)

Copy link

@vishalc-ibm vishalc-ibm Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, If we can collect other system level data such as lscpu, mpstat -P ALL 1 1, numactl -H, uptime etc. apart from all other static data that sysinfo utility already collects

Also as part of sysinfo utility's pre, create a backup /sys/kernel/debug/sched of this directory.

process.run(cmd, ignore_status=True, sudo=True, shell=True)
cmd = 'echo >> "%s" 2>&1' % (log_file)
process.run(cmd, ignore_status=True, sudo=True, shell=True)

# Execute the command and append the output to the log file
for i in range(self.repeat):
cmd = 'eval "$user_command" >> "%s" 2>&1' % (log_file)
process.run(cmd, ignore_status=True, sudo=True, shell=True)

cmd = 'echo >> "%s" 2>&1' % (log_file)
process.run(cmd, ignore_status=True, sudo=True, shell=True)

for i in range(self.repeat):
Copy link

@vishalc-ibm vishalc-ibm Nov 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method sets up sched-scoreboard repo and later runs the user supplied command through time utility. Please refactor into two seperate methods.

Copy link

@vishalc-ibm vishalc-ibm Nov 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setup of sched-scoreboard repo can be done inside setUp() method

# Execute the command and append the output to the log file
cmd = '/usr/bin/time -v $(echo %s) >> "%s" 2>&1' % (
self.user_command, log_file)
process.run(cmd, ignore_status=True, sudo=True, shell=True)
Copy link

@vishalc-ibm vishalc-ibm Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        process.run(cmd, ignore_status=True, sudo=True, shell=True)
        cmd = 'echo >> "%s" 2>&1' % (log_file)
        process.run(cmd, ignore_status=True, sudo=True, shell=True)
        # Execute the command and append the output to the log file
        for i in range(self.repeat):
            cmd = 'eval "$user_command" >> "%s" 2>&1' % (log_file)
            process.run(cmd, ignore_status=True, sudo=True, shell=True)
        cmd = 'echo >> "%s" 2>&1' % (log_file)
        process.run(cmd, ignore_status=True, sudo=True, shell=True)
        for i in range(self.repeat):
            # Execute the command and append the output to the log file
            cmd = '/usr/bin/time -v $(echo %s) >> "%s" 2>&1' % (
                self.user_command, log_file)
            process.run(cmd, ignore_status=True, sudo=True, shell=True)

Please refactor this part to separate test_* methods as following:

  • test_run_command: This method would run user_command one time
  • test_run_command_with_profilers: This method would run user_command one time but with profilers enabled. (using sysinfo utility to run profilers per-test but for test_run_command_with_profilers only)
  • test_run_command_repeat: This method would run user_command repeat times

Copy link

@vishalc-ibm vishalc-ibm Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • test_run_with_time_repeat: Will just be another test method to run the user_command through time command repeated repeat times


def test_strace_cmd(self):
Copy link

@vishalc-ibm vishalc-ibm Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/test_strace_cmd/test_run_with_strace_repeat/

"""
Run the strace command
"""
strace_log_file = self.logdir + "/strace"
os.mkdir(strace_log_file)

log_file = "%s/strace_command_output_%s.log" % (
strace_log_file, self.kernel_ver)
cmd = 'strace -c $(echo %s) >> "%s" 2>&1' % (self.user_command,
log_file)
for i in range(2):
process.run(cmd, ignore_status=True, sudo=True, shell=True)

def test_perf_stat_cmd(self):
Copy link

@vishalc-ibm vishalc-ibm Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/test_perf_stat_cmd/test_run_with_perf_stat_repeat/

"""_summary_
Run the workload command with perf stat.
"""
perf_log_file = self.logdir + "/perf_stat"
os.mkdir(perf_log_file)

log_file = "%s/perf_stat_command_output_%s.log" % (
perf_log_file, self.kernel_ver)
cmd = 'perf stat -r %d -d -d -d -- $(echo %s) >> "%s" 2>&1' % (
self.repeat, self.user_command, log_file)
process.run(cmd, ignore_status=True, sudo=True, shell=True)

cmd = 'echo >> "%s" 2>&1' % (log_file)
process.run(cmd, ignore_status=True, sudo=True, shell=True)

cmd = 'perf stat -r %d -d -d -d --all-kernel -- $(echo %s) \
>> "%s" 2>&1' % (
self.repeat, self.user_command, log_file)
process.run(cmd, ignore_status=True, sudo=True, shell=True)

cmd = 'echo >> "%s" 2>&1' % (log_file)
process.run(cmd, ignore_status=True, sudo=True, shell=True)

cmd = 'perf stat -r %d -d -d -d --all-user -- $(echo %s) \
>> "%s" 2>&1' % (
self.repeat, self.user_command, log_file)
process.run(cmd, ignore_status=True, sudo=True, shell=True)

def test_sched_scoreboard_cmd(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/test_sched_scoreboard_cmd/test_run_with_sched_scoreboard/

"""_summary_
Here we are running the sched_scoreboard to capture and report
all the data related to the Linux Kernel Scheduler.
"""
sched_log_file = self.logdir + "/sched_scoreboard"
os.mkdir(sched_log_file)
log_file = "%s/sched_scoreboard_command_output_%s.log" % (
sched_log_file, self.kernel_ver)
cmd = 'bash %s/sched-scoreboard.sh --logdir "%s" -e -d --workload \
"%s" >> "%s" 2>&1' % (self.sched_scoreboard_dir,
sched_log_file, self.user_command,
log_file)
process.run(cmd, ignore_status=True, sudo=True, shell=True)

def test_trace_cmd(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/test_trace_cmd/test_run_with_trace_cmd/

"""_summary_
Here we are running the workload command with trace command.
"""
trace_log_file = self.logdir + "/trace"
os.mkdir(trace_log_file)

log_file = "%s/trace_command_output_%s.dat" % (
trace_log_file, self.kernel_ver)
cmd = 'trace-cmd record -e sched -o "%s" -- $(echo %s) >> "%s" \
2>&1' % (trace_log_file, self.user_command, log_file)
process.run(cmd, ignore_status=True, sudo=True, shell=True)
2 changes: 2 additions & 0 deletions cpu/log_generator.py.data/log_generator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
user_command:
repeat:
Loading