Skip to content

Commit c1faecb

Browse files
authored
Merge pull request #208 from Helene/cpu_time
Add measure of the function used cpu time to the internal performance analytics
2 parents a8ab4ca + c758ad2 commit c1faecb

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

source/messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
'ReceivAttrValues': 'Received {}:{}',
5757
'StartMethod': 'Starting method: {} with args: {}.',
5858
'RunMethod': 'Executed method: {} with args: {}.',
59-
'TimerInfo': 'Processing {} took {:.6f} seconds.',
59+
'TimerInfo': 'Processing {} took real time: {:.6f} seconds, cpu time: {:.6f} seconds.',
6060
'Query2port': 'For better bridge performance multithreaded port {} will be used',
6161
'CollectorConnInfo': 'Connection to the collector server established successfully',
6262
'BridgeVersionInfo': ' *** IBM Storage Scale bridge for Grafana - Version: {} ***',

source/utils.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ def wrapper(*args: Any, **kwargs: Any) -> T:
4040
args_str = ', '.join(map(str, args[1:])) if len(args) > 1 else ''
4141
kwargs_str = ', '.join(f'{k}={v}' for k, v in kwargs.items()) if len(kwargs) > 0 else ''
4242
self.logger.trace(MSG['StartMethod'].format(f.__name__, ', '.join(filter(None, [args_str, kwargs_str]))))
43-
t = time.time()
43+
t1 = time.perf_counter(), time.process_time()
4444
result = f(*args, **kwargs)
45-
duration = time.time() - t
45+
t2 = time.perf_counter(), time.process_time()
46+
duration = t2[0] - t1[0]
47+
cpu_time = t2[1] - t1[1]
4648
if not skip_attribute:
4749
wrapper._execution_duration = duration # type: ignore
4850
self.logger.debug(MSG['RunMethod'].format(f.__name__, ', '.join(filter(None, [args_str, kwargs_str]))))
49-
self.logger.debug(MSG['TimerInfo'].format(f.__name__, duration))
51+
self.logger.debug(MSG['TimerInfo'].format(f.__name__, duration, cpu_time))
5052
return result
5153
return wrapper
5254
return outer
@@ -68,13 +70,15 @@ def wrapper(*args: Any, **kwargs: Any) -> T:
6870
args_str = ', '.join(map(str, args[1:])) if len(args) > 1 else ''
6971
kwargs_str = ', '.join(f'{k}={v}' for k, v in kwargs.items()) if len(kwargs) > 0 else ''
7072
logger.trace(MSG['StartMethod'].format(f.__name__, ', '.join(filter(None, [args_str, kwargs_str]))))
71-
t = time.time()
73+
t1 = time.perf_counter(), time.process_time()
7274
result = f(*args, **kwargs)
73-
duration = time.time() - t
75+
t2 = time.perf_counter(), time.process_time()
76+
duration = t2[0] - t1[0]
77+
cpu_time = t2[1] - t1[1]
7478
if not skip_attribute:
7579
wrapper._execution_duration = duration # type: ignore
7680
logger.debug(MSG['RunMethod'].format(f.__name__, ', '.join(filter(None, [args_str, kwargs_str]))))
77-
logger.debug(MSG['TimerInfo'].format(f.__name__, duration))
81+
logger.debug(MSG['TimerInfo'].format(f.__name__, duration, cpu_time))
7882
return result
7983
return wrapper
8084

0 commit comments

Comments
 (0)