pmctest.py revision 231634
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 231634 2012-02-14 04:18:59Z 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# 41231634Sgnn# pmctest.py 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. 45231634Sgnn 46231634Sgnnimport sys 47231634Sgnnimport subprocess 48231634Sgnnfrom subprocess import PIPE 49231634Sgnn 50231634Sgnn# A list of strings that are not really counters, just 51231634Sgnn# name tags that are output by pmccontrol -L 52231634Sgnnnotcounter = ["IAF", "IAP", "TSC", "UNC", "UCF"] 53231634Sgnn 54231634Sgnndef main(): 55231634Sgnn 56231634Sgnn if (len(sys.argv) != 2): 57231634Sgnn print ("usage: pmctest.py program") 58231634Sgnn 59231634Sgnn program = sys.argv[1] 60231634Sgnn 61231634Sgnn p = subprocess.Popen(["pmccontrol", "-L"], stdout=PIPE) 62231634Sgnn counters = p.communicate()[0] 63231634Sgnn 64231634Sgnn if len(counters) <= 0: 65231634Sgnn print "no counters found" 66231634Sgnn sys.exit() 67231634Sgnn 68231634Sgnn for counter in counters.split(): 69231634Sgnn if counter in notcounter: 70231634Sgnn continue 71231634Sgnn p = subprocess.Popen(["pmcstat", "-p", counter, program], stdout=PIPE) 72231634Sgnn result = p.communicate()[0] 73231634Sgnn print result 74231634Sgnn 75231634Sgnn# The canonical way to make a python module into a script. 76231634Sgnn# Remove if unnecessary. 77231634Sgnn 78231634Sgnnif __name__ == "__main__": 79231634Sgnn main() 80