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