summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Willmann <d.willmann@samsung.com>2013-07-17 18:22:16 +0100
committerDaniel Willmann <d.willmann@samsung.com>2013-07-17 18:22:16 +0100
commit3417638b23b523f8d4838b92b11de95687811dc0 (patch)
tree8dbb609b02bfebf159019b86d204432e901b8a68
parent06b8b7b87977edf1f290150d218fee5146348b4f (diff)
graph-coverage: Create graphs of the whole coverage or parts
Signed-off-by: Daniel Willmann <daniel@totalueberwachung.de>
-rwxr-xr-xgraph-coverage.py79
1 files changed, 64 insertions, 15 deletions
diff --git a/graph-coverage.py b/graph-coverage.py
index 3f3aaf9..e61d6d5 100755
--- a/graph-coverage.py
+++ b/graph-coverage.py
@@ -1,14 +1,13 @@
1#!/usr/bin/python 1#!/usr/bin/python
2 2
3# Copyright (c) Daniel Willmann <daniel@totalueberwachung.de> 3# Copyright (c) Daniel Willmann <daniel@totalueberwachung.de>
4# Copyright (c) Samsung Electronics
4 5
5import os 6import os
6import argparse 7import argparse
7from datetime import datetime 8from datetime import datetime
8import sqlite3 9import sqlite3
9 10
10from pylab import *
11
12class MakeList(argparse.Action): 11class MakeList(argparse.Action):
13 def __call__(self, parser, namespace, values, option_string=None): 12 def __call__(self, parser, namespace, values, option_string=None):
14 setattr(namespace, self.dest, values.split(',')) 13 setattr(namespace, self.dest, values.split(','))
@@ -20,12 +19,16 @@ display = parser.add_argument_group('Record')
20display.add_argument("-r", "--record", dest="coverage_file", 19display.add_argument("-r", "--record", dest="coverage_file",
21 type=argparse.FileType('r'), 20 type=argparse.FileType('r'),
22 help="update database with coverage information") 21 help="update database with coverage information")
22display.add_argument("-i", "--id", dest="date",
23 help="id to use for build (default is current date)")
23 24
24graph = parser.add_argument_group('Graph options') 25graph = parser.add_argument_group('Graph options')
25graph.add_argument("-g", "--graph", dest="graph", 26graph.add_argument("-g", "--graph", dest="graph",
26 help="generate a graph.") 27 help="generate a graph.")
27graph.add_argument("-l", "--label", dest="label", 28graph.add_argument("-l", "--label", dest="label",
28 help="Label of the graph", default="") 29 help="Label of the graph", default="")
30graph.add_argument("-f", "--files", dest="files", action=MakeList,
31 help="Only use these files for calculation")
29 32
30parser.add_argument("-q", "--quiet", 33parser.add_argument("-q", "--quiet",
31 action="store_false", dest="verbose", default=True, 34 action="store_false", dest="verbose", default=True,
@@ -47,7 +50,10 @@ try:
47except: 50except:
48 pass 51 pass
49 52
50date = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") 53if options.date:
54 date = options.date
55else:
56 date = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
51print "Collecting coverage for build", date 57print "Collecting coverage for build", date
52 58
53testname = "" 59testname = ""
@@ -58,7 +64,8 @@ all_ln = 0
58cov_ln = 0 64cov_ln = 0
59 65
60state = "NONE" 66state = "NONE"
61for line in options.coverage_file: 67if options.coverage_file:
68 for line in options.coverage_file:
62 line = line.rstrip() 69 line = line.rstrip()
63 if line == "end_of_record": 70 if line == "end_of_record":
64 if state == "NONE": 71 if state == "NONE":
@@ -116,16 +123,58 @@ for line in options.coverage_file:
116conn.commit() 123conn.commit()
117 124
118if options.graph: 125if options.graph:
119 pass 126 import matplotlib
120 127
121dates = c.execute("SELECT DISTINCT date from coverage ORDER BY date").fetchall() 128 matplotlib.use("GtkAgg")
122 129# matplotlib.rc('text', usetex=True)
123for date in dates: 130 matplotlib.rc('font', family='serif')
124 query = c.execute("SELECT date, SUM(all_fn), SUM(covered_fn), SUM(all_ln), SUM(covered_ln) from coverage WHERE date = ?", (date)) 131 matplotlib.rc('axes', titlesize='small')
125 132 matplotlib.rc('legend', fontsize='small')
126 for result in query.fetchall(): 133 matplotlib.rc('figure.subplot', bottom=0.20, top=0.90, left=0.10, right=0.95)
127 print result[0] 134
128 print "Function coverage: % 3.2f%%" % (float(result[2])/result[1] * 100, ) 135 import numpy
129 print "Line coverage: % 3.2f%%" % (float(result[4])/result[3] * 100, ) 136 from numpy import array
137 from pylab import *
138
139 dates = c.execute("SELECT DISTINCT date from coverage ORDER BY date").fetchall()
140
141 fn_per = []
142 ln_per = []
143
144 files = []
145 querystr = "SELECT date, SUM(all_fn), SUM(covered_fn), SUM(all_ln), SUM(covered_ln) from coverage WHERE date = ?"
146 if options.files:
147 querystr = querystr + " and ( " + " or ".join(["filename like ?" for x in options.files]) + " )"
148 files = [x + "%" for x in options.files]
149
150 for date in dates:
151 params = [date[0]]
152 if files:
153 params.extend(files)
154 query = c.execute(querystr, params)
155
156 for result in query.fetchall():
157 print result[0]
158 print "Function coverage: % 3.2f%%" % (float(result[2])/result[1] * 100, )
159 print "Line coverage: % 3.2f%%" % (float(result[4])/result[3] * 100, )
160 fn_per.append(float(result[2])/result[1]*100)
161 ln_per.append(float(result[4])/result[3]*100)
162
163 fncov = plot(numpy.arange(len(dates)), fn_per, linewidth=1.0)
164 lncov = plot(numpy.arange(len(dates)), ln_per, linewidth=1.0)
165
166 legend((fncov[0], lncov[0]), ('Functions', 'Lines'))
167 ind = numpy.arange(len(dates))
168 lims = xlim()
169 xlim((lims[0]-0.5, lims[1]+0.5))
170 xticks(ind, [x[0].replace(' ', '\n') for x in dates], rotation=60)
171 lims = ylim()
172# ylim((int(lims[0]), int(lims[1])+1))
173 ylim((0,100))
174 ylabel('coverage in %')
175 title(options.label)
176
177 savefig(options.graph, transparent=False)
178 close()
130 179
131conn.close() 180conn.close()