1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | # |
---|
4 | # Copyright (c) 2016 embedded brains GmbH. All rights reserved. |
---|
5 | # |
---|
6 | # The license and distribution terms for this file may be |
---|
7 | # found in the file LICENSE in this distribution or at |
---|
8 | # http://www.rtems.org/license/LICENSE. |
---|
9 | # |
---|
10 | |
---|
11 | import re |
---|
12 | import libxml2 |
---|
13 | import math |
---|
14 | import statistics |
---|
15 | from libxml2 import xmlNode |
---|
16 | import matplotlib.pyplot as plt |
---|
17 | data = open('smplock01.scn').read() |
---|
18 | data = re.sub(r'\*\*\*.*\*\*\*', '', data) |
---|
19 | doc = libxml2.parseDoc(data) |
---|
20 | ctx = doc.xpathNewContext() |
---|
21 | |
---|
22 | plt.title('SMP Lock Fairness') |
---|
23 | plt.xlabel('Active Workers') |
---|
24 | plt.ylabel('Normed Coefficient of Variation') |
---|
25 | |
---|
26 | i = 1 |
---|
27 | ticket = [] |
---|
28 | mcs = [] |
---|
29 | tas = [] |
---|
30 | ttas = [] |
---|
31 | |
---|
32 | def m(n): |
---|
33 | return int(xmlNode.getContent(n)) |
---|
34 | |
---|
35 | def normedCoefficientOfVariation(name, i): |
---|
36 | y = map(m, ctx.xpathEval('/SMPLock01/' + name + '[@activeWorker=' + str(i) + ']/LocalCounter')) |
---|
37 | if len(y) == 0: |
---|
38 | raise |
---|
39 | return (statistics.stdev(y) / statistics.mean(y)) / math.sqrt(len(y) - 1) |
---|
40 | |
---|
41 | try: |
---|
42 | while True: |
---|
43 | i = i + 1 |
---|
44 | ticket.append(normedCoefficientOfVariation('GlobalTicketLockWithLocalCounter', i)) |
---|
45 | mcs.append(normedCoefficientOfVariation('GlobalMCSLockWithLocalCounter', i)) |
---|
46 | tas.append(normedCoefficientOfVariation('GlobalTASLockWithLocalCounter', i)) |
---|
47 | ttas.append(normedCoefficientOfVariation('GlobalTTASLockWithLocalCounter', i)) |
---|
48 | except: |
---|
49 | pass |
---|
50 | |
---|
51 | x = range(1, len(ticket) + 1) |
---|
52 | plt.yscale('log') |
---|
53 | plt.plot(x, ticket, label = 'Ticket Lock', marker = 'o') |
---|
54 | plt.plot(x, mcs, label = 'MCS Lock', marker = 'o') |
---|
55 | plt.plot(x, tas, label = 'TAS Lock', marker = 'o') |
---|
56 | plt.plot(x, ttas, label = 'TTAS Lock', marker = 'o') |
---|
57 | plt.legend(loc = 'best') |
---|
58 | plt.show() |
---|