|
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 |
# Self monitoring example. Copied from self.c
|
|
Packit |
577717 |
|
|
Packit |
577717 |
import os
|
|
Packit |
577717 |
from optparse import OptionParser
|
|
Packit |
577717 |
import random
|
|
Packit |
577717 |
import errno
|
|
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 |
(options, args) = parser.parse_args()
|
|
Packit |
577717 |
|
|
Packit |
577717 |
s = PerThreadSession(int(os.getpid()))
|
|
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 |
s.dispatch_events(events)
|
|
Packit |
577717 |
s.load()
|
|
Packit |
577717 |
s.start()
|
|
Packit |
577717 |
|
|
Packit |
577717 |
# code to be measured
|
|
Packit |
577717 |
#
|
|
Packit |
577717 |
# note that this is not identical to what examples/self.c does
|
|
Packit |
577717 |
# thus counts will be different in the end
|
|
Packit |
577717 |
for i in range(1, 10000000):
|
|
Packit |
577717 |
random.random()
|
|
Packit |
577717 |
|
|
Packit |
577717 |
s.stop()
|
|
Packit |
577717 |
|
|
Packit |
577717 |
# read the counts
|
|
Packit |
577717 |
for i in xrange(s.npmds):
|
|
Packit |
577717 |
print """PMD%d\t%lu""" % (s.pmds[0][i].reg_num, s.pmds[0][i].reg_value)
|