redhawksdr

How to create C code to start RedHawk application


I have use python code to start RedHawk application as below.

#!/usr/bin/python

from ossie.utils import redhawk
from bulkio.bulkioInterfaces import BULKIO
from time import sleep

DefaultDomainName = "REDHAWK_DEV"
domain_list = redhawk.scan()
dom = redhawk.attach(domain_list[0])
wave0 = dom.createApplication("/waveforms/rx_waveform/rx_waveform.sad.xml")

i=0
while True:
  if not dom.devices[i].name in 'GPP':
     break
  i+=1
print("device number =", i)

dom.devices[i].connect(wave0.comps[0], usesPortName='out_data_rx', providesPortN
wave0.comps[2].connect(dom.devices[i], providesPortName='in_data_rx', usesPortNa
dom.devices[i].connect(wave0.comps[0], usesPortName='out_cnt_rx', providesPortNa
wave0.comps[2].connect(dom.devices[i], providesPortName='in_cnt_rx', usesPortNam

wave0.start()
dom.devices[i].start()

while True:
   sleep(10)

This python code is very slow, it will take 10 seconds. In particular, it takes 6 seconds to "from ossie.util import redhawk". Can you convert the above python code to C code that can be activated at high speed?


Solution

  • You absolutely could rewrite it in C++ since almost all the calls you are making are remote calls that have C++/Python/Java bindings however you may want to look at the trade offs first. The python API is a lot easier to work with and really is not that slow, like I said most of what it is doing is making remote calls to C++ based processes. The slow down in importing redhawk is (I believe) due to the number of files it references and imports. The linux kernel does a great job of caching these meaning that if you were to execute it again you would see a huge speed improvement. In the example below I've forced the kernel to drop its cache and show the difference in speed between two consecutive runs.

    [ylbagou@axios tmp]$echo "from ossie.utils import redhawk" > testing.py
    [ylbagou@axios tmp]$sudo bash -c 'sync; echo 1 > /proc/sys/vm/drop_caches; echo 2 > /proc/sys/vm/drop_caches; echo 3 > /proc/sys/vm/drop_caches'
    [ylbagou@axios tmp]$time python testing.py
    
    real    0m4.670s
    user    0m0.178s
    sys 0m0.098s
    [ylbagou@axiosws-ylb1(0) tmp]$time python testing.py
    
    real    0m0.181s
    user    0m0.145s
    sys 0m0.036s
    

    So if you have to do it at startup and you have to meet a certain time constraint then maybe C++ would work but if you can live with the first run taking longer then the python API is the way to go.