|
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 |
|
|
Packit |
577717 |
import os
|
|
Packit |
577717 |
from perfmon import *
|
|
Packit |
577717 |
|
|
Packit |
577717 |
def public_members(self):
|
|
Packit |
577717 |
s = "{ "
|
|
Packit |
577717 |
for k, v in self.__dict__.iteritems():
|
|
Packit |
577717 |
if not k[0] == '_':
|
|
Packit |
577717 |
s += "%s : %s, " % (k, v)
|
|
Packit |
577717 |
s += " }"
|
|
Packit |
577717 |
return s
|
|
Packit |
577717 |
|
|
Packit |
577717 |
class System:
|
|
Packit |
577717 |
def __init__(self):
|
|
Packit |
577717 |
self.ncpus = os.sysconf('SC_NPROCESSORS_ONLN')
|
|
Packit |
577717 |
self.pmu = PMU()
|
|
Packit |
577717 |
|
|
Packit |
577717 |
def __repr__(self):
|
|
Packit |
577717 |
return public_members(self)
|
|
Packit |
577717 |
|
|
Packit |
577717 |
class Event:
|
|
Packit |
577717 |
def __init__(self):
|
|
Packit |
577717 |
pass
|
|
Packit |
577717 |
|
|
Packit |
577717 |
def __repr__(self):
|
|
Packit |
577717 |
return '\n' + public_members(self)
|
|
Packit |
577717 |
|
|
Packit |
577717 |
class EventMask:
|
|
Packit |
577717 |
def __init__(self):
|
|
Packit |
577717 |
pass
|
|
Packit |
577717 |
|
|
Packit |
577717 |
def __repr__(self):
|
|
Packit |
577717 |
return '\n\t' + public_members(self)
|
|
Packit |
577717 |
|
|
Packit |
577717 |
class PMU:
|
|
Packit |
577717 |
def __init__(self):
|
|
Packit |
577717 |
pfm_initialize()
|
|
Packit |
577717 |
|
|
Packit |
577717 |
self.type = pfm_py_get_pmu_type()
|
|
Packit |
577717 |
self.name = pfm_get_pmu_name(PFMON_MAX_EVTNAME_LEN)[1]
|
|
Packit |
577717 |
self.width = pfm_py_get_hw_counter_width()
|
|
Packit |
577717 |
|
|
Packit |
577717 |
# What does the PMU support?
|
|
Packit |
577717 |
self.__implemented_pmcs = pfmlib_regmask_t()
|
|
Packit |
577717 |
self.__implemented_pmds = pfmlib_regmask_t()
|
|
Packit |
577717 |
self.__implemented_counters = pfmlib_regmask_t()
|
|
Packit |
577717 |
pfm_get_impl_pmcs(self.__implemented_pmcs)
|
|
Packit |
577717 |
pfm_get_impl_pmds(self.__implemented_pmds)
|
|
Packit |
577717 |
pfm_get_impl_counters(self.__implemented_counters)
|
|
Packit |
577717 |
self.implemented_pmcs = self.__implemented_pmcs.weight()
|
|
Packit |
577717 |
self.implemented_pmds = self.__implemented_pmds.weight()
|
|
Packit |
577717 |
self.implemented_counters = self.__implemented_counters.weight()
|
|
Packit |
577717 |
|
|
Packit |
577717 |
self.__events = None
|
|
Packit |
577717 |
|
|
Packit |
577717 |
def __parse_events(self):
|
|
Packit |
577717 |
nevents = pfm_py_get_num_events()
|
|
Packit |
577717 |
self.__events = []
|
|
Packit |
577717 |
for idx in range(0, nevents):
|
|
Packit |
577717 |
e = Event()
|
|
Packit |
577717 |
e.name = pfm_py_get_event_name(idx)
|
|
Packit |
577717 |
e.code = pfm_py_get_event_code(idx)
|
|
Packit |
577717 |
e.__counters = pfmlib_regmask_t()
|
|
Packit |
577717 |
pfm_get_event_counters(idx, e.__counters)
|
|
Packit |
577717 |
# Now the event masks
|
|
Packit |
577717 |
e.masks = []
|
|
Packit |
577717 |
nmasks = pfm_py_get_num_event_masks(idx)
|
|
Packit |
577717 |
for mask_idx in range(0, nmasks):
|
|
Packit |
577717 |
em = EventMask()
|
|
Packit |
577717 |
em.name = pfm_py_get_event_mask_name(idx, mask_idx)
|
|
Packit |
577717 |
em.code = pfm_py_get_event_mask_code(idx, mask_idx)
|
|
Packit |
577717 |
em.desc = pfm_py_get_event_mask_description(idx, mask_idx)
|
|
Packit |
577717 |
e.masks.append(em)
|
|
Packit |
577717 |
self.__events.append(e)
|
|
Packit |
577717 |
|
|
Packit |
577717 |
def events(self):
|
|
Packit |
577717 |
if not self.__events:
|
|
Packit |
577717 |
self.__parse_events()
|
|
Packit |
577717 |
return self.__events
|
|
Packit |
577717 |
|
|
Packit |
577717 |
def __repr__(self):
|
|
Packit |
577717 |
return public_members(self)
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if __name__ == '__main__':
|
|
Packit |
577717 |
from perfmon import *
|
|
Packit |
577717 |
s = System()
|
|
Packit |
577717 |
print s
|
|
Packit |
577717 |
print s.pmu.events()
|