Skip to content

Commit

Permalink
Add cpu cycles counter
Browse files Browse the repository at this point in the history
  • Loading branch information
slacrherbst committed Sep 20, 2023
1 parent 41ddae0 commit 6774789
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
1 change: 1 addition & 0 deletions pip_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ gitpython
pygithub
pydm
matplotlib
hwcounter
52 changes: 34 additions & 18 deletions tests/test_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@
import pyrogue.interfaces.simulation
import rogue.interfaces.memory
import time
import hwcounter

#rogue.Logging.setLevel(rogue.Logging.Debug)
#import logging
#logger = logging.getLogger('pyrogue')
#logger.setLevel(logging.DEBUG)

MinRate = { 'remoteSetRate' : 42000,
'remoteSetNvRate' : 46000,
'remoteGetRate' : 54000,
'localSetRate' : 36000,
'localGetRate' : 55000,
'linkedSetRate' : 36000,
'linkedGetRate' : 45000 }
MaxCycles = { 'remoteSetRate' : 42000,
'remoteSetNvRate' : 46000,
'remoteGetRate' : 54000,
'localSetRate' : 36000,
'localGetRate' : 55000,
'linkedSetRate' : 36000,
'linkedGetRate' : 45000 }

class TestDev(pr.Device):

Expand Down Expand Up @@ -106,57 +107,72 @@ def test_rate():

with DummyTree() as root:
count = 100000
result = {}
resultRate = {}
resultCycles = {}

stime = time.time()
scount = hwcounter.count()
with root.updateGroup():
for i in range(count):
root.TestDev.TestRemote.set(i)
result['remoteSetRate'] = 1/((time.time()-stime) / count)
resultCycles['remoteSetRate'] = hwcounter.count_end() - scount
resultRate['remoteSetRate'] = int(1/((time.time()-stime) / count))

stime = time.time()
scount = hwcounter.count()
with root.updateGroup():
for i in range(count):
root.TestDev.TestRemoteNoVerify.set(i)
result['remoteSetNvRate'] = 1/((time.time()-stime) / count)
resultCycles['remoteSetNvRate'] = hwcounter.count_end() - scount
resultRate['remoteSetNvRate'] = int(1/((time.time()-stime) / count))

stime = time.time()
scount = hwcounter.count()
with root.updateGroup():
for i in range(count):
root.TestDev.TestRemote.get()
result['remoteGetRate'] = 1/((time.time()-stime) / count)
resultCycles['remoteGetRate'] = hwcounter.count_end() - scount
resultRate['remoteGetRate'] = int(1/((time.time()-stime) / count))

stime = time.time()
scount = hwcounter.count()
with root.updateGroup():
for i in range(count):
root.TestDev.TestLocal.set(i)
result['localSetRate'] = 1/((time.time()-stime) / count)
resultCycles['localSetRate'] = hwcounter.count_end() - scount
resultRate['localSetRate'] = int(1/((time.time()-stime) / count))

stime = time.time()
scount = hwcounter.count()
with root.updateGroup():
for i in range(count):
root.TestDev.TestLocal.get()
result['localGetRate'] = 1/((time.time()-stime) / count)
resultCycles['localGetRate'] = hwcounter.count_end() - scount
resultRate['localGetRate'] = int(1/((time.time()-stime) / count))

stime = time.time()
scount = hwcounter.count()
with root.updateGroup():
for i in range(count):
root.TestDev.TestLink.set(i)
result['linkedSetRate'] = 1/((time.time()-stime) / count)
resultCycles['linkedSetRate'] = hwcounter.count_end() - scount
resultRate['linkedSetRate'] = int(1/((time.time()-stime) / count))

stime = time.time()
scount = hwcounter.count()
with root.updateGroup():
for i in range(count):
root.TestDev.TestLink.get(i)
result['linkedGetRate'] = 1/((time.time()-stime) / count)
resultCycles['linkedGetRate'] = hwcounter.count_end() - scount
resultRate['linkedGetRate'] = int(1/((time.time()-stime) / count))

passed = True

for k,v in MinRate.items():
for k,v in MaxCycles.items():

print(f"{k} target {v} result {result[k]}")
print(f"{k} cyles {resultCycles[k]}, maximum {v}, rate {resultRate[k]}")

if result[k] < v:
if resultCycles[k] > v:
passed = False

if passed is False:
Expand Down

0 comments on commit 6774789

Please sign in to comment.