From 251e6d127043bf20907fcdac909d14b1d60c670e Mon Sep 17 00:00:00 2001 From: "Piotr F. Mieszkowski" Date: Thu, 2 Jun 2022 23:41:14 +0200 Subject: [PATCH] Record execution time and log it After each execution, log an entry with information about total seconds from the start to the end of execution and the value returned by time.process_time() function, which returns: sum of the kernel and user-space CPU time according to the documentation. This feature can be used to collect stats about Lacre performance. --- gpg-mailgate.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gpg-mailgate.py b/gpg-mailgate.py index 202f35a..6c057f2 100755 --- a/gpg-mailgate.py +++ b/gpg-mailgate.py @@ -33,6 +33,7 @@ import smtplib import sys import syslog import traceback +import time # imports for S/MIME @@ -413,7 +414,13 @@ def sort_recipients( raw_message, from_addr, to_addrs ): # Send out mail to recipients which are left send_msg(raw_message.as_string(), recipients_left) +def exec_time_info(start_timestamp): + elapsed_s = time.time() - start_timestamp + process_t = time.process_time() + return (elapsed_s, process_t) + +start = time.time() conf.load_config() lacre.init_logging(conf.get_item('logging', 'config')) @@ -432,3 +439,6 @@ to_addrs = sys.argv[1:] # Let's start sort_recipients(raw_message, from_addr, to_addrs) +(elapsed_s, process_t) = exec_time_info(start) + +LOG.info("Elapsed-time: {elapsed:.2f}s; Process-time: {process:.4f}s".format(elapsed=elapsed_s, process=process_t))