|
Packit |
577717 |
#!/usr/bin/env python
|
|
Packit |
577717 |
#
|
|
Packit |
577717 |
# Copyright (c) 2008 Google, Inc.
|
|
Packit |
577717 |
# Contributed by Arun Sharma <arun.sharma@google.com>
|
|
Packit |
577717 |
#
|
|
Packit |
577717 |
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
Packit |
577717 |
# copy of this software and associated documentation files (the "Software"),
|
|
Packit |
577717 |
# to deal in the Software without restriction, including without limitation
|
|
Packit |
577717 |
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
Packit |
577717 |
# and/or sell copies of the Software, and to permit persons to whom the
|
|
Packit |
577717 |
# Software is furnished to do so, subject to the following conditions:
|
|
Packit |
577717 |
#
|
|
Packit |
577717 |
# The above copyright notice and this permission notice shall be included
|
|
Packit |
577717 |
# in all copies or substantial portions of the Software.
|
|
Packit |
577717 |
#
|
|
Packit |
577717 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
Packit |
577717 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
Packit |
577717 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
Packit |
577717 |
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
Packit |
577717 |
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
Packit |
577717 |
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
Packit |
577717 |
# OTHER DEALINGS IN THE SOFTWARE.
|
|
Packit |
577717 |
#
|
|
Packit |
577717 |
# System wide monitoring example. Copied from syst.c
|
|
Packit |
577717 |
#
|
|
Packit |
577717 |
# Run as: ./sys.py -c cpulist -e eventlist
|
|
Packit |
577717 |
|
|
Packit |
577717 |
import sys
|
|
Packit |
577717 |
import os
|
|
Packit |
577717 |
from optparse import OptionParser
|
|
Packit |
577717 |
import time
|
|
Packit |
577717 |
from perfmon import *
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if __name__ == '__main__':
|
|
Packit |
577717 |
parser = OptionParser()
|
|
Packit |
577717 |
parser.add_option("-e", "--events", help="Events to use",
|
|
Packit |
577717 |
action="store", dest="events")
|
|
Packit |
577717 |
parser.add_option("-c", "--cpulist", help="CPUs to monitor",
|
|
Packit |
577717 |
action="store", dest="cpulist")
|
|
Packit |
577717 |
parser.set_defaults(cpu=0)
|
|
Packit |
577717 |
(options, args) = parser.parse_args()
|
|
Packit |
577717 |
|
|
Packit |
577717 |
cpus = options.cpulist.split(',')
|
|
Packit |
577717 |
cpus = [ int(c) for c in cpus ]
|
|
Packit |
577717 |
try:
|
|
Packit |
577717 |
s = SystemWideSession(cpus)
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if options.events:
|
|
Packit |
577717 |
events = options.events.split(",")
|
|
Packit |
577717 |
else:
|
|
Packit |
577717 |
raise "You need to specify events to monitor"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
s.dispatch_events(events)
|
|
Packit |
577717 |
s.load()
|
|
Packit |
577717 |
|
|
Packit |
577717 |
# Measuring loop
|
|
Packit |
577717 |
for i in range(1, 10):
|
|
Packit |
577717 |
s.start()
|
|
Packit |
577717 |
time.sleep(1)
|
|
Packit |
577717 |
s.stop()
|
|
Packit |
577717 |
# Print the counts
|
|
Packit |
577717 |
for cpu in xrange(len(cpus)):
|
|
Packit |
577717 |
for i in xrange(s.npmds):
|
|
Packit |
577717 |
print "CPU%d.PMD%d\t%lu""" % (cpu, s.pmds[cpu][i].reg_num,
|
|
Packit |
577717 |
s.pmds[cpu][i].reg_value)
|
|
Packit |
577717 |
finally:
|
|
Packit |
577717 |
s.cleanup()
|