我創建了一個python Gnuradio塊,現在我用C++重新編寫它。我注意到的是一件非常意外的事情 - 與Python版本(18%)相比,C++塊(python流程圖進程)消耗更多的CPU(〜125%)。我必須做一些錯誤的...所以 -Gnuradio C++代碼塊:高CPU
我創建的投入和產出比設定變量類型爲float沒有其他自定義代碼和編號的新塊1,我看到相同的行爲。我一定是做錯了什麼,但我不能告訴什麼...
$ gnuradio-config-info -v
3.7.11
Platform: Mac/x86_64
以下是我對我現有的模塊中創建的塊:
$ gr_modtool add -t general donothingcpp
GNU Radio module name identified: acsound
Language (python/cpp): cpp
Language: C++
Block/code identifier: donothingcpp
Enter valid argument list, including default arguments:
Add Python QA code? [Y/n] n
Add C++ QA code? [Y/n] n
Adding file 'lib/donothingcpp_impl.h'...
Adding file 'lib/donothingcpp_impl.cc'...
Adding file 'include/acsound/donothingcpp.h'...
Editing swig/acsound_swig.i...
Adding file 'grc/acsound_donothingcpp.xml'...
Editing grc/CMakeLists.txt...
我修改的構造,以指定一個輸入和一個輸出,然後我調整在general_work函數的變量類型,它現在看起來像這樣:
int
donothingcpp_impl::general_work (int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const float *in = (const float *) input_items[0];
float *out = (float *) output_items[0];
// Do <+signal processing+>
// Tell runtime system how many input items we consumed on
// each input stream.
consume_each (noutput_items);
// Tell runtime system how many output items we produced.
return noutput_items;
}
我是否在general_work
函數中做過任何工作,該進程的CPU消耗約爲125%。當然,每次更改代碼後,我都會進行清理,製作和安裝,以便將代碼塊放入gnuradio中。如果我添加調試消息,我可以在控制檯上看到它們,所以我知道在運行流程圖時我的代碼更改正在被查看和使用。
如果我繞過donothing塊並運行流圖,它消耗0.3%的CPU。
我都嘗試空和探測信號接收器,但既不似乎是一個因素。
我不知所措但是我解釋,當我運行定製的C++塊CPU佔用率較高。
工作就像一個魅力,謝謝。我必須使用'-t sync'創建塊,並如您所說將我的信號處理邏輯放在'work()'函數中。新的塊CPU使用率約爲0.0x –