Skip to content

Added command execution time measurement #123

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

Merged
merged 1 commit into from
May 28, 2024

Conversation

MakSl
Copy link
Contributor

@MakSl MakSl commented May 22, 2024

This will be useful to keep track of possible performance degradation when code changes.

@MakSl MakSl requested a review from demonolock May 22, 2024 12:48
stderr=subprocess.STDOUT,
env=env
).decode('utf-8', errors='replace')
if execution_time:
Copy link
Contributor

Choose a reason for hiding this comment

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

Думаю ничего страшного, если будем замерять время команд всегда

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Хмм, получается будем замерять всегда, но будем использовать не всегда?
Может лучше оставим условие? Хоть замер и не занимает много времени. Но читаемость кода так лучше имхо.

Copy link
Contributor

Choose a reason for hiding this comment

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

Почему читаемость лучше?

 if self.execution_time:
                start_time = time.time()
                self.test_class.output = subprocess.check_output(
                    cmdline,
                    stderr=subprocess.STDOUT,
                    env=env
                ).decode('utf-8', errors='replace')
                end_time = time.time()
                self.execution_time = end_time - start_time
            else:
                self.test_class.output = subprocess.check_output(
                    cmdline,
                    stderr=subprocess.STDOUT,
                    env=env
                ).decode('utf-8', errors='replace')

против

                start_time = time.time()
                self.test_class.output = subprocess.check_output(
                    cmdline,
                    stderr=subprocess.STDOUT,
                    env=env
                ).decode('utf-8', errors='replace')
                end_time = time.time()
                self.execution_time = end_time - start_time      
Copy link
Contributor Author

Choose a reason for hiding this comment

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

В конечной реализации это доп условие и вправду лишнее.


def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
skip_log_directory=False, expect_error=False, use_backup_dir=True):
skip_log_directory=False, expect_error=False, use_backup_dir=True, execution_time=False):
Copy link
Contributor

Choose a reason for hiding this comment

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

прокидывать сюда не нужно было, execution_time и так доступен из self.execution_time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Поправил

@demonolock
Copy link
Contributor

Проблема со стилем кода

Можно проверять локально поставив flake8
Установка
pip install flake8

Проверка
flake8 /путь/до_кода

@MakSl MakSl force-pushed the measuring_the_speed_of_commands branch from 7049fa7 to 0dc237d Compare May 22, 2024 23:35
elapsed_time_4t = backup_id_4t.execution_time

# Full by basebackup
backup = node.backup(check_time=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

А тест проверял? Проходит?
Не вижу check_time в функции backup_node

Copy link
Contributor Author

@MakSl MakSl May 28, 2024

Choose a reason for hiding this comment

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

Данный тест был не работоспособен. Исправил его и проверил у себя. Получение времени осуществляется.

Отдельный тест на проверку работоспособности считаю излишней. Поэтому по итогу убрал тест.

@@ -56,6 +56,7 @@ def __init__(self, test_class: unittest.TestCase,
self.verbose = init_params.verbose
self.archive_compress = init_params.archive_compress
self.test_class.output = None
self.execution_time = execution_time
Copy link
Contributor

Choose a reason for hiding this comment

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

Так лучше не делать
execution_time и признак того что мы хотим замерить время и само время.
Python конечно позволяет, но это ведет к сложноотслеживаемым ошибкам. Лучше сделать его None если замера не было

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Согласен. Исправил этот момент.

  This will be useful to keep track of possible performance degradation when code changes.
@MakSl MakSl force-pushed the measuring_the_speed_of_commands branch from 0dc237d to b452e0d Compare May 28, 2024 14:36
@demonolock demonolock merged commit 63db275 into master May 28, 2024
2 checks passed
@demonolock demonolock deleted the measuring_the_speed_of_commands branch May 28, 2024 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants