Skip to content

Commit

Permalink
More test rig changes
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl committed Nov 9, 2016
1 parent 864ca84 commit 93043bc
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 13 deletions.
32 changes: 32 additions & 0 deletions examples/P45-MALC01.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/home/tmc43/common/python/pymalcolm/malcolm/imalcolm.py
#/dls_sw/prod/common/python/RHEL6-x86_64/pymalcolm/2-0a6/malcolm/imalcolm.py
# This sample is intended for use with the test lab setup LAB-MO-IOC-01

- blocks.ADCore.SimDetectorManager:
pvPrefix: LAB-MO-MAP-01:MIC
mriPrefix: P45-MIC

- blocks.demo.TestRigPMACManager:
mriPrefix: P45-BRICK01

- blocks.pandabox.PandABoxManager:
pvPrefix: LAB-MO-PANDA-01
mriPrefix: P45-PANDA01
hostname: 172.23.252.201

- blocks.zebra.ZebraManager:
pvPrefix: LAB-MO-MAP-01:ZEBRA
mriPrefix: P45-ZEBRA01

- blocks.demo.TestRigManager:
mri: P45-SCAN01
mic: P45-MIC
brick: P45-BRICK01
pandabox: P45-PANDA01
zebra: P45-ZEBRA01

#- comms.pva.PvaServerComms:

- comms.websocket.WebsocketServerComms:
port: 8080

2 changes: 1 addition & 1 deletion examples/pandabox_onboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Input params
HOSTNAME = "localhost"
PORT = 8888
WSPORT = 8081
WSPORT = 8080

# Make the top level objects
sf = SyncFactory("Sync")
Expand Down
43 changes: 31 additions & 12 deletions malcolm/core/profilingsampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,39 @@ class ProfilingSampler(object):
def __init__(self, interval=0.1):
self.stack_counts = collections.defaultdict(int)
self.interval = interval
self._started = False
signal.signal(signal.SIGPROF, self._sample)

def _format_stack(self, frame):
stack = []
while frame is not None:
if frame.f_code.co_name == "wait":
return
stack.append(frame)
frame = frame.f_back
formatted = []
for frame in reversed(stack):
formatted_frame = '%s(%s)' % (
frame.f_code.co_name, frame.f_globals.get('__name__'))
formatted.append(formatted_frame)
return ';'.join(formatted)

def _sample(self, _, _2):
print "sample"
for frame in sys._current_frames().values():
stack = []
while frame is not None:
formatted_frame = '{}({})'.format(
frame.f_code.co_name, frame.f_globals.get('__name__'))
stack.append(formatted_frame)
frame = frame.f_back

formatted_stack = ';'.join(reversed(stack))
self.stack_counts[formatted_stack] += 1
signal.setitimer(signal.ITIMER_VIRTUAL, self.interval, 0)
formatted_stack = self._format_stack(frame)
if formatted_stack:
self.stack_counts[formatted_stack] += 1
if self._started:
signal.setitimer(signal.ITIMER_PROF, self.interval, 0)

def start(self):
signal.signal(signal.SIGVTALRM, self._sample)
signal.setitimer(signal.ITIMER_VIRTUAL, self.interval, 0)
self._started = True
signal.setitimer(signal.ITIMER_PROF, self.interval, 0)

def stop(self):
self._started = False

def most_common_stack_frames(self):
for v, k in sorted((v, k) for k, v in self.stack_counts.items()):
print "%06d: %s" % (v, "\n ".join(k.split(";")))

0 comments on commit 93043bc

Please sign in to comment.