Gnuradio C++;块:高CPU 我创建了一个Python GnuraDo块,现在我正在用C++重新编码它。我注意到了一些非常意外的事情——C++块(Python流图处理)比Python版本(18%)消耗更多的CPU(125%)。我一定是做错了什么。。。所以-

Gnuradio C++;块:高CPU 我创建了一个Python GnuraDo块,现在我正在用C++重新编码它。我注意到了一些非常意外的事情——C++块(Python流图处理)比Python版本(18%)消耗更多的CPU(125%)。我一定是做错了什么。。。所以-,c++,signal-processing,gnuradio,C++,Signal Processing,Gnuradio,我创建了一个没有自定义代码的新块,只将变量类型设置为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

我创建了一个没有自定义代码的新块,只将变量类型设置为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;
}
int
完成所有CPP项目::一般工作(整数项),
gr_矢量输入和输入项,
gr\u矢量\u常数\u无效\u星型和输入\u项,
gr_矢量_无效_星和输出_项)
{
常量浮点*in=(常量浮点*)输入_项[0];
浮点*输出=(浮点*)输出_项[0];
//做
//告诉运行时系统我们在上消耗了多少输入项
//每个输入流。
每项消费(零支出项目);
//告诉运行时系统我们生成了多少输出项。
退货零配件;
}
无论我是否在
general\u work
函数中执行任何工作,该进程的CPU消耗大约为125%。当然,每次代码更改后,我都会进行清理、创建和安装,以将块放入gnuradio。如果我添加调试消息,我会在控制台上看到它们,这样我就知道在运行流程图时会看到并使用我的代码更改

如果我绕过donothing块并运行流程图,它将消耗0.3%的CPU

我尝试了空信号接收器和探测信号接收器,但两者似乎都不是一个因素


当我运行自定义C++块时,我无法解释高CPU消耗。p> 您消耗的是输出样本的数量,但在一般情况下是错误的(在同步块情况下是正确的,其中输出项目的数量始终与消耗的输入项目的数量相同)

现在,由于您的块没有检查是否有足够的输入项,所以它总是被要求运行——因此,CPU被烧毁


我觉得您“意外”创建了一个普通块(使用
普通工作
),但却打算创建一个同步块(使用
工作
)。

工作非常出色,谢谢。我必须使用
-t sync
创建块,并将我的信号处理逻辑放入
work()
函数中,如您所说。新的块CPU使用率约为0.0x