pmctest.py revision 231699
1231634Sgnn#!/usr/bin/env python 2231634Sgnn# Copyright (c) 2012, Neville-Neil Consulting 3231634Sgnn# All rights reserved. 4231634Sgnn# 5231634Sgnn# Redistribution and use in source and binary forms, with or without 6231634Sgnn# modification, are permitted provided that the following conditions are 7231634Sgnn# met: 8231634Sgnn# 9231634Sgnn# Redistributions of source code must retain the above copyright notice, 10231634Sgnn# this list of conditions and the following disclaimer. 11231634Sgnn# 12231634Sgnn# Redistributions in binary form must reproduce the above copyright 13231634Sgnn# notice, this list of conditions and the following disclaimer in the 14231634Sgnn# documentation and/or other materials provided with the distribution. 15231634Sgnn# 16231634Sgnn# Neither the name of Neville-Neil Consulting nor the names of its 17231634Sgnn# contributors may be used to endorse or promote products derived from 18231634Sgnn# this software without specific prior written permission. 19231634Sgnn# 20231634Sgnn# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21231634Sgnn# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22231634Sgnn# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23231634Sgnn# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24231634Sgnn# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25231634Sgnn# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26231634Sgnn# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27231634Sgnn# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28231634Sgnn# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29231634Sgnn# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30231634Sgnn# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31231634Sgnn# 32231634Sgnn# Author: George V. Neville-Neil 33231634Sgnn# 34231634Sgnn# $FreeBSD: head/tools/test/hwpmc/pmctest.py 231699 2012-02-14 18:57:10Z gnn $ 35231634Sgnn 36231634Sgnn# Description: A program to run a simple program against every available 37231634Sgnn# pmc counter present in a system. 38231634Sgnn# 39231634Sgnn# To use: 40231634Sgnn# 41231698Sgnn# pmctest.py -p ls > /dev/null 42231634Sgnn# 43231634Sgnn# This should result in ls being run with every available counter 44231634Sgnn# and the system should neither lock up nor panic. 45231698Sgnn# 46231698Sgnn# The default is to wait after each counter is tested. Since the 47231698Sgnn# prompt would go to stdout you won't see it, just press return 48231698Sgnn# to continue or Ctrl-D to stop. 49231634Sgnn 50231634Sgnnimport sys 51231634Sgnnimport subprocess 52231634Sgnnfrom subprocess import PIPE 53231634Sgnn 54231634Sgnn# A list of strings that are not really counters, just 55231634Sgnn# name tags that are output by pmccontrol -L 56231699Sgnnnotcounter = ["IAF", "IAP", "TSC", "UNC", "UCF", "UCP"] 57231634Sgnn 58231634Sgnndef main(): 59231634Sgnn 60231698Sgnn from optparse import OptionParser 61231698Sgnn 62231698Sgnn parser = OptionParser() 63231698Sgnn parser.add_option("-p", "--program", dest="program", 64231698Sgnn help="program to execute") 65231698Sgnn parser.add_option("-w", "--wait", action="store_true", dest="wait", 66231698Sgnn default=True, help="wait after each execution") 67231634Sgnn 68231698Sgnn (options, args) = parser.parse_args() 69231634Sgnn 70231634Sgnn p = subprocess.Popen(["pmccontrol", "-L"], stdout=PIPE) 71231634Sgnn counters = p.communicate()[0] 72231634Sgnn 73231634Sgnn if len(counters) <= 0: 74231634Sgnn print "no counters found" 75231634Sgnn sys.exit() 76231634Sgnn 77231634Sgnn for counter in counters.split(): 78231634Sgnn if counter in notcounter: 79231634Sgnn continue 80231698Sgnn p = subprocess.Popen(["pmcstat", "-p", counter, options.program], 81231698Sgnn stdout=PIPE) 82231634Sgnn result = p.communicate()[0] 83231634Sgnn print result 84231698Sgnn if (options.wait == True): 85231698Sgnn try: 86231698Sgnn value = raw_input("next?") 87231698Sgnn except EOFError: 88231698Sgnn sys.exit() 89231634Sgnn 90231634Sgnn# The canonical way to make a python module into a script. 91231634Sgnn# Remove if unnecessary. 92231634Sgnn 93231634Sgnnif __name__ == "__main__": 94231634Sgnn main() 95