ParserDBUsage.py
Go to the documentation of this file.
1 ###########################
2 # Parsed metric
3 class DBUsage():
4  def __init__(self):
5  self.n_queries = 0
6  self.vmem_usage = []
7  self.mem_usage = []
8  self.queries = []
9  self.query_time = []
10  self.rows = []
11  self.parsing_time = []
14 
15  def peak(self,thing):
16  if len(thing): return max(thing)
17  else: return 0
18 
19  def refresh(self):
20  self.sum_query_time = self.sumQueryTime()
21  self.sum_parsing_time = self.sumParsingTime()
22 
23  def peakVMUsage(self): return self.peak(self.vmem_usage)
24  def peakMUsage(self): return self.peak(self.mem_usage)
25  def peakQueryTime(self): return self.peak(self.query_time)
26  def sumQueryTime(self): return sum(self.query_time)
27  def peakParsingTime(self): return self.peak(self.parsing_time)
28  def sumParsingTime(self): return sum(self.parsing_time)
29  def peakRows(self): return self.peak(self.rows)
30  def sumRows(self): return sum(self.rows)
31 
32  def peakQuery(self):
33  if self.queries == []: return "No queries found"
34  enumerated_queries = []
35  for i_q, q in enumerate(self.queries):
36  enumerated_queries.append((self.query_time[i_q],q))
37  enumerated_queries.sort(reverse=True)
38  return enumerated_queries[0][1]
39 
40  def __repr__(self):
41  _repr = ""
42  _repr += "dbuse: --- DBUsage metric\n"
43  _repr += "dbuse: queries: %s\n" %repr(self.n_queries)
44  #_repr += "dbuse: vmem_usage: %s\n" %repr(self.vmem_usage)
45  _repr += "dbuse: vmem peak: %s MB\n" %repr(self.peakVMUsage())
46  #_repr += "dbuse: mem_usage: %s\n" %repr(self.mem_usage)
47  _repr += "dbuse: mem peak: %s MB\n" %repr(self.peakMUsage())
48  _repr += "dbuse: n queries: %s\n" %repr(len(self.query_time))
49  #_repr += "dbuse: queries: %s\n" %repr(self.queries)
50  #_repr += "dbuse: query_time: %s\n" %repr(self.query_time)
51  _repr += "dbuse: query peak: %s ms\n" %repr(self.peakQueryTime())
52  _repr += "dbuse: from query: %s\n" %repr(self.peakQuery())
53  _repr += "dbuse: query sum: %s ms\n" %repr(self.sumQueryTime())
54  #_repr += "dbuse: parsing_time: %s\n" %repr(self.parsing_time)
55  _repr += "dbuse: n parsing: %s\n" %repr(len(self.parsing_time))
56  _repr += "dbuse: parsing peak: %s ms\n" %repr(self.peakParsingTime())
57  _repr += "dbuse: parsing sum: %s ms\n" %repr(self.sumParsingTime())
58  _repr += "dbuse: rows peak: %s\n" %repr(self.peakRows())
59  _repr += "dbuse: rows sum: %s" %repr(self.sumRows())
60  # strip trailing newline
61  #_repr = _repr[:-1]
62  return _repr
63 ###########################
64 # Parse line
65 def parseLine(line, usage):
66  if " of VirtualMemory" in line:
67  tokens = line.split()
68  assert (tokens[5] == "MB"), "Expecting tokens[5] to be MB, tokens:%s"%repr(tokens)
69  vmem = float(tokens[4])
70  usage.vmem_usage.append(vmem)
71  if " of PhysicalMemory" in line:
72  tokens = line.split()
73  assert (tokens[5] == "MB"), "Expecting tokens[5] to be MB, tokens:%s"%repr(tokens)
74  mem = float(tokens[4])
75  usage.mem_usage.append(mem)
76  if " query took " in line:
77  usage.n_queries+=1
78  tokens = line.split()
79  for i_t, t in enumerate(tokens):
80  if t == "query":
81  assert (tokens[i_t+1] == "took")
82  assert (tokens[i_t+3] == "ms")
83  start_token = i_t
84  time = float(tokens[i_t+2])
85  usage.queries.append(line.strip())
86  usage.query_time.append(time)
87  break
88  if " parsing took " in line:
89  usage.n_queries+=1
90  tokens = line.split()
91  for i_t, t in enumerate(tokens):
92  if t == "parsing":
93  assert (tokens[i_t+1] == "took")
94  assert (tokens[i_t+3] == "ms")
95  start_token = i_t
96  time = float(tokens[i_t+2])
97  usage.parsing_time.append(time)
98  break
99  if "rows from database" in line:
100  tokens = line.split()
101  if (len(tokens) == 5):
102  rows = int(tokens[1])
103  usage.rows.append(rows)
104  else:
105  print "dbuse: ERROR: Expecting line to be 5 words long: %s"%line
106  usage.rows.append(0)
107 ###########################
108 # Parse output file
109 def parseSTDOUT(file_name, verbose=True):
110  if verbose: print "prsDB: --- Parsed STDOUT from file: %s"%file_name
111 
112  lines = open(file_name, "r").readlines()
113  if verbose: print "prsDB: read %i lines"%len(lines)
114  usage = DBUsage()
115 
116  # loop over the lines
117  for line in lines:
118  parseLine(line, usage)
119 
120  #print usage
121  return usage
def parseSTDOUT(file_name, verbose=True)
Parse output file.
def parseLine(line, usage)
procfile open("FD_BRL_v0.txt")
Parsed metric.
Definition: ParserDBUsage.py:3
def peak(self, thing)
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:68