|
25 | 25 | from reframe.core.logging import getlogger, _format_time_rfc3339, time_function |
26 | 26 | from reframe.core.runtime import runtime |
27 | 27 | from reframe.core.warnings import suppress_deprecations |
28 | | -from reframe.utility import nodelist_abbrev |
| 28 | +from reframe.utility import nodelist_abbrev, OrderedSet |
29 | 29 | from .storage import StorageBackend |
30 | 30 | from .utility import Aggregator, parse_cmp_spec, parse_time_period, is_uuid |
31 | 31 |
|
@@ -269,6 +269,14 @@ def update_timestamps(self, ts_start, ts_end): |
269 | 269 | 'time_elapsed': ts_end - ts_start |
270 | 270 | }) |
271 | 271 |
|
| 272 | + def update_extras(self, extras): |
| 273 | + '''Attach user-specific metadata to the session''' |
| 274 | + |
| 275 | + # We prepend a special character to the user extras in order to avoid |
| 276 | + # possible conflicts with existing keys |
| 277 | + for k, v in extras.items(): |
| 278 | + self.__report['session_info'][f'${k}'] = v |
| 279 | + |
272 | 280 | def update_run_stats(self, stats): |
273 | 281 | session_uuid = self.__report['session_info']['uuid'] |
274 | 282 | for runidx, tasks in stats.runs(): |
@@ -645,17 +653,38 @@ def session_data(time_period): |
645 | 653 | '''Retrieve all sessions''' |
646 | 654 |
|
647 | 655 | data = [['UUID', 'Start time', 'End time', 'Num runs', 'Num cases']] |
| 656 | + extra_cols = OrderedSet() |
648 | 657 | for sess_data in StorageBackend.default().fetch_sessions_time_period( |
649 | 658 | *parse_time_period(time_period) if time_period else (None, None) |
650 | 659 | ): |
651 | 660 | session_info = sess_data['session_info'] |
652 | | - data.append( |
653 | | - [session_info['uuid'], |
654 | | - session_info['time_start'], |
655 | | - session_info['time_end'], |
656 | | - len(sess_data['runs']), |
657 | | - len(sess_data['runs'][0]['testcases'])] |
658 | | - ) |
| 661 | + record = [session_info['uuid'], |
| 662 | + session_info['time_start'], |
| 663 | + session_info['time_end'], |
| 664 | + len(sess_data['runs']), |
| 665 | + len(sess_data['runs'][0]['testcases'])] |
| 666 | + |
| 667 | + # Expand output with any user metadata |
| 668 | + for k in session_info: |
| 669 | + if k.startswith('$'): |
| 670 | + extra_cols.add(k[1:]) |
| 671 | + |
| 672 | + # Add any extras recorded so far |
| 673 | + for key in extra_cols: |
| 674 | + record.append(session_info.get(f'${key}', '')) |
| 675 | + |
| 676 | + data.append(record) |
| 677 | + |
| 678 | + # Do a final grooming pass of the data to expand short records |
| 679 | + if extra_cols: |
| 680 | + data[0] += extra_cols |
| 681 | + |
| 682 | + for rec in data: |
| 683 | + diff = len(extra_cols) - len(rec) |
| 684 | + if diff == 0: |
| 685 | + break |
| 686 | + |
| 687 | + rec += ['n/a' for _ in range(diff)] |
659 | 688 |
|
660 | 689 | return data |
661 | 690 |
|
|
0 commit comments