12542e558SGeorge V. Neville-Neil#!/usr/bin/env python 22542e558SGeorge V. Neville-Neil# Copyright (c) 2012, Neville-Neil Consulting 32542e558SGeorge V. Neville-Neil# All rights reserved. 42542e558SGeorge V. Neville-Neil# 52542e558SGeorge V. Neville-Neil# Redistribution and use in source and binary forms, with or without 62542e558SGeorge V. Neville-Neil# modification, are permitted provided that the following conditions are 72542e558SGeorge V. Neville-Neil# met: 82542e558SGeorge V. Neville-Neil# 92542e558SGeorge V. Neville-Neil# Redistributions of source code must retain the above copyright notice, 102542e558SGeorge V. Neville-Neil# this list of conditions and the following disclaimer. 112542e558SGeorge V. Neville-Neil# 122542e558SGeorge V. Neville-Neil# Redistributions in binary form must reproduce the above copyright 132542e558SGeorge V. Neville-Neil# notice, this list of conditions and the following disclaimer in the 142542e558SGeorge V. Neville-Neil# documentation and/or other materials provided with the distribution. 152542e558SGeorge V. Neville-Neil# 162542e558SGeorge V. Neville-Neil# Neither the name of Neville-Neil Consulting nor the names of its 172542e558SGeorge V. Neville-Neil# contributors may be used to endorse or promote products derived from 182542e558SGeorge V. Neville-Neil# this software without specific prior written permission. 192542e558SGeorge V. Neville-Neil# 202542e558SGeorge V. Neville-Neil# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 212542e558SGeorge V. Neville-Neil# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 222542e558SGeorge V. Neville-Neil# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 232542e558SGeorge V. Neville-Neil# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 242542e558SGeorge V. Neville-Neil# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 252542e558SGeorge V. Neville-Neil# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 262542e558SGeorge V. Neville-Neil# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 272542e558SGeorge V. Neville-Neil# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 282542e558SGeorge V. Neville-Neil# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 292542e558SGeorge V. Neville-Neil# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 302542e558SGeorge V. Neville-Neil# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 312542e558SGeorge V. Neville-Neil# 322542e558SGeorge V. Neville-Neil# Author: George V. Neville-Neil 332542e558SGeorge V. Neville-Neil# 342542e558SGeorge V. Neville-Neil# $FreeBSD$ 352542e558SGeorge V. Neville-Neil 362542e558SGeorge V. Neville-Neil# Description: A program to run a simple program against every available 372542e558SGeorge V. Neville-Neil# pmc counter present in a system. 382542e558SGeorge V. Neville-Neil# 392542e558SGeorge V. Neville-Neil# To use: 402542e558SGeorge V. Neville-Neil# 41f9166e7cSGeorge V. Neville-Neil# pmctest.py -p ls > /dev/null 422542e558SGeorge V. Neville-Neil# 432542e558SGeorge V. Neville-Neil# This should result in ls being run with every available counter 442542e558SGeorge V. Neville-Neil# and the system should neither lock up nor panic. 45f9166e7cSGeorge V. Neville-Neil# 46f9166e7cSGeorge V. Neville-Neil# The default is to wait after each counter is tested. Since the 47f9166e7cSGeorge V. Neville-Neil# prompt would go to stdout you won't see it, just press return 48f9166e7cSGeorge V. Neville-Neil# to continue or Ctrl-D to stop. 492542e558SGeorge V. Neville-Neil 502542e558SGeorge V. Neville-Neilimport sys 512542e558SGeorge V. Neville-Neilimport subprocess 522542e558SGeorge V. Neville-Neilfrom subprocess import PIPE 532542e558SGeorge V. Neville-Neil 54*05864d89SHiren Panchasara# Use input() for Python version 3 55*05864d89SHiren Panchasaraif sys.version_info[0] == 3: 56*05864d89SHiren Panchasara raw_input = input 57*05864d89SHiren Panchasara 582542e558SGeorge V. Neville-Neil# A list of strings that are not really counters, just 592542e558SGeorge V. Neville-Neil# name tags that are output by pmccontrol -L 60345ddfcfSFabien Thomasnotcounter = ["IAF", "IAP", "TSC", "UNC", "UCF", "UCP", "SOFT" ] 612542e558SGeorge V. Neville-Neil 622542e558SGeorge V. Neville-Neildef main(): 632542e558SGeorge V. Neville-Neil 64f9166e7cSGeorge V. Neville-Neil from optparse import OptionParser 652542e558SGeorge V. Neville-Neil 66f9166e7cSGeorge V. Neville-Neil parser = OptionParser() 67f9166e7cSGeorge V. Neville-Neil parser.add_option("-p", "--program", dest="program", 68f9166e7cSGeorge V. Neville-Neil help="program to execute") 69f9166e7cSGeorge V. Neville-Neil parser.add_option("-w", "--wait", action="store_true", dest="wait", 70f9166e7cSGeorge V. Neville-Neil default=True, help="wait after each execution") 71f9166e7cSGeorge V. Neville-Neil 72f9166e7cSGeorge V. Neville-Neil (options, args) = parser.parse_args() 732542e558SGeorge V. Neville-Neil 74d2c10b2aSGeorge V. Neville-Neil if (options.program == None): 75168ff9abSEitan Adler print("specify program, such as ls, with -p/--program") 76d2c10b2aSGeorge V. Neville-Neil sys.exit() 77d2c10b2aSGeorge V. Neville-Neil 782542e558SGeorge V. Neville-Neil p = subprocess.Popen(["pmccontrol", "-L"], stdout=PIPE) 792542e558SGeorge V. Neville-Neil counters = p.communicate()[0] 802542e558SGeorge V. Neville-Neil 812542e558SGeorge V. Neville-Neil if len(counters) <= 0: 82168ff9abSEitan Adler print("no counters found") 832542e558SGeorge V. Neville-Neil sys.exit() 842542e558SGeorge V. Neville-Neil 852542e558SGeorge V. Neville-Neil for counter in counters.split(): 862542e558SGeorge V. Neville-Neil if counter in notcounter: 872542e558SGeorge V. Neville-Neil continue 88f9166e7cSGeorge V. Neville-Neil p = subprocess.Popen(["pmcstat", "-p", counter, options.program], 89f9166e7cSGeorge V. Neville-Neil stdout=PIPE) 902542e558SGeorge V. Neville-Neil result = p.communicate()[0] 91168ff9abSEitan Adler print(result) 92f9166e7cSGeorge V. Neville-Neil if (options.wait == True): 93f9166e7cSGeorge V. Neville-Neil try: 94*05864d89SHiren Panchasara value = raw_input("next?") 95f9166e7cSGeorge V. Neville-Neil except EOFError: 96f9166e7cSGeorge V. Neville-Neil sys.exit() 972542e558SGeorge V. Neville-Neil 982542e558SGeorge V. Neville-Neil# The canonical way to make a python module into a script. 992542e558SGeorge V. Neville-Neil# Remove if unnecessary. 1002542e558SGeorge V. Neville-Neil 1012542e558SGeorge V. Neville-Neilif __name__ == "__main__": 1022542e558SGeorge V. Neville-Neil main() 103