Motr  M0
fom_req.py
Go to the documentation of this file.
1 #
2 # Copyright (c) 2020 Seagate Technology LLC and/or its Affiliates
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 # For any questions about this software or licensing,
17 # please email opensource@seagate.com or cortx-questions@seagate.com.
18 #
19 
20 import sys
21 from addb2db import *
22 from typing import List, Dict
23 from req_utils import *
24 
25 
26 def get_timelines(fom_id: int, pid: int):
27  time_table = []
28 
29  fom_desc_d = query2dlist(fom_desc.select().where((fom_desc.fom_sm_id==fom_id)&
30  (fom_desc.pid==pid)))
31  assert(len(fom_desc_d) == 1)
32  fom_state_id = fom_desc_d[0]['fom_state_sm_id']
33 
34  fom_req_st_d = query2dlist(fom_req_state.select().where((fom_req_state.id==fom_state_id)&(fom_req_state.pid==pid)))
35  times_tag_append(fom_req_st_d, 'op', f"fom-state {fom_state_id}")
36  time_table.append(fom_req_st_d)
37 
38  fom_req_d = query2dlist(fom_req.select().where((fom_req.id==fom_id)&(fom_req.pid==pid)))
39  times_tag_append(fom_req_d, 'op', f"fom-phase {fom_id}")
40  time_table.append(fom_req_d)
41 
42  stob_ids = query2dlist(fom_to_stio.select().where((fom_to_stio.fom_id==fom_id)&(fom_to_stio.pid==pid)))
43 
44  for sid in stob_ids:
45  stio_d = query2dlist(stio_req.select().where((stio_req.id==sid['stio_id'])&(stio_req.pid==pid)))
46  times_tag_append(stio_d, 'op', f"stob_io {sid['stio_id']}")
47  time_table.append(stio_d)
48 
49  tx_ids = query2dlist(fom_to_tx.select().where((fom_to_tx.fom_id==fom_id)&(fom_to_tx.pid==pid)))
50 
51  for tx in tx_ids:
52  tx_d = query2dlist(be_tx.select().where((be_tx.id==tx['tx_id'])&(be_tx.pid==pid)))
53  times_tag_append(tx_d, 'op', f"tx {tx['tx_id']}")
54  time_table.append(tx_d)
55 
56  prepare_time_table(time_table)
57 
58  return time_table
59 
60 
61 def parse_args():
62  parser = argparse.ArgumentParser(prog=sys.argv[0], description="""
63  fom_req.py: Display FOM-related timelines.
64  """)
65  parser.add_argument("-f", "--fom-id", type=int, required=True,
66  help="FOM id")
67  parser.add_argument("-p", "--pid", type=int, required=True,
68  help="Server pid to get FOM phases")
69  parser.add_argument("-v", "--verbose", action='count', default=0)
70  parser.add_argument("-u", "--time-unit", choices=['ms','us'], default='us',
71  help="Default time unit")
72  parser.add_argument("-m", "--maximize", action='store_true',
73  help="Display in maximised window")
74  parser.add_argument("-d", "--db", type=str, default="m0play.db",
75  help="Performance database (m0play.db)")
76 
77  return parser.parse_args()
78 
79 if __name__ == '__main__':
80  args=parse_args()
81 
82  db_init(args.db)
83  db_connect()
84 
85  print("Getting timelines...")
86 
87  time_table = get_timelines(args.fom_id, args.pid)
88 
89  db_close()
90 
91  print("Plotting timelines...")
92 
93  draw_timelines(time_table, None, 0, 0, args.time_unit, False, args.maximize)
94 
95 # ================================================================================
def prepare_time_table(time_table)
Definition: req_utils.py:51
def query2dlist(model)
Definition: req_utils.py:68
def db_init(path)
Definition: addb2db.py:314
def db_connect()
Definition: addb2db.py:321
static M0_UNUSED void print(struct m0_be_list *list)
Definition: list.c:186
def times_tag_append
Definition: req_utils.py:74
def parse_args()
Definition: fom_req.py:61
def get_timelines
Definition: fom_req.py:26
def db_close()
Definition: addb2db.py:324
def draw_timelines
Definition: req_utils.py:105