Deleted Added
full compact
pmctest.py (231634) pmctest.py (231698)
1#!/usr/bin/env python
2# Copyright (c) 2012, Neville-Neil Consulting
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met:
8#

--- 17 unchanged lines hidden (view full) ---

26# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31#
32# Author: George V. Neville-Neil
33#
1#!/usr/bin/env python
2# Copyright (c) 2012, Neville-Neil Consulting
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met:
8#

--- 17 unchanged lines hidden (view full) ---

26# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31#
32# Author: George V. Neville-Neil
33#
34# $FreeBSD: head/tools/test/hwpmc/pmctest.py 231634 2012-02-14 04:18:59Z gnn $
34# $FreeBSD: head/tools/test/hwpmc/pmctest.py 231698 2012-02-14 18:51:21Z gnn $
35
36# Description: A program to run a simple program against every available
37# pmc counter present in a system.
38#
39# To use:
40#
35
36# Description: A program to run a simple program against every available
37# pmc counter present in a system.
38#
39# To use:
40#
41# pmctest.py ls > /dev/null
41# pmctest.py -p ls > /dev/null
42#
43# This should result in ls being run with every available counter
44# and the system should neither lock up nor panic.
42#
43# This should result in ls being run with every available counter
44# and the system should neither lock up nor panic.
45#
46# The default is to wait after each counter is tested. Since the
47# prompt would go to stdout you won't see it, just press return
48# to continue or Ctrl-D to stop.
45
46import sys
47import subprocess
48from subprocess import PIPE
49
50# A list of strings that are not really counters, just
51# name tags that are output by pmccontrol -L
52notcounter = ["IAF", "IAP", "TSC", "UNC", "UCF"]
53
54def main():
55
49
50import sys
51import subprocess
52from subprocess import PIPE
53
54# A list of strings that are not really counters, just
55# name tags that are output by pmccontrol -L
56notcounter = ["IAF", "IAP", "TSC", "UNC", "UCF"]
57
58def main():
59
56 if (len(sys.argv) != 2):
57 print ("usage: pmctest.py program")
60 from optparse import OptionParser
61
62 parser = OptionParser()
63 parser.add_option("-p", "--program", dest="program",
64 help="program to execute")
65 parser.add_option("-w", "--wait", action="store_true", dest="wait",
66 default=True, help="wait after each execution")
58
67
59 program = sys.argv[1]
68 (options, args) = parser.parse_args()
60
61 p = subprocess.Popen(["pmccontrol", "-L"], stdout=PIPE)
62 counters = p.communicate()[0]
63
64 if len(counters) <= 0:
65 print "no counters found"
66 sys.exit()
67
68 for counter in counters.split():
69 if counter in notcounter:
70 continue
69
70 p = subprocess.Popen(["pmccontrol", "-L"], stdout=PIPE)
71 counters = p.communicate()[0]
72
73 if len(counters) <= 0:
74 print "no counters found"
75 sys.exit()
76
77 for counter in counters.split():
78 if counter in notcounter:
79 continue
71 p = subprocess.Popen(["pmcstat", "-p", counter, program], stdout=PIPE)
80 p = subprocess.Popen(["pmcstat", "-p", counter, options.program],
81 stdout=PIPE)
72 result = p.communicate()[0]
73 print result
82 result = p.communicate()[0]
83 print result
84 if (options.wait == True):
85 try:
86 value = raw_input("next?")
87 except EOFError:
88 sys.exit()
74
75# The canonical way to make a python module into a script.
76# Remove if unnecessary.
77
78if __name__ == "__main__":
79 main()
89
90# The canonical way to make a python module into a script.
91# Remove if unnecessary.
92
93if __name__ == "__main__":
94 main()