Detailed explanation of SylixOS debugging method - performance analysis

1. SylixOS debugging method introduction

SylixOS implements a powerful debugging stub (stub), which can debug the application online on the device or simulator. RealEvo-IDE also provides a matching debugging plug-in. Currently, RealEvo-IDE supports both automatic push debugging and the traditional debugging method of manually starting gdbserver. Several debugging methods that are very practical in daily development are not detailed in the official manual. This article mainly introduces the debugging methods of performance analysis.

In the daily development process, it is often encountered that the program is not fast enough, but I don't know where the slowness is. I often search for function optimization at will, and I haven't really located where the program is slow. There is a lot of chance. The performance analysis tool uses dynamic sampling to locate the really slow position, and then optimizes at this point after positioning. The final program running time comparison is very obvious.

2. Detailed explanation of SylixOS performance analysis and debugging steps

2.1.1 Performance analysis demo

The performance analysis of SylixOS is mainly to view the CPU time consumed by each function by loading the performance analysis module (sperfs.ko), and to accurately find the points that need to be optimized. The following is a demonstration of performance analysis and debugging by creating a "perfoms_check_app", the code is shown in program listing 2‑1.

Program Listing 2‑1 static_check_app code

//sperfstart sperfs

#include <stdio.h>

 

#define   USE_SLEEP

 

void module_sleep(int iSecond)

{

#ifdef USE_SLEEP

   sleep(1);

#else

   bspDelayUs(iSecond*1000*1000);

#endif

}

 

void calc_value(void)

{

   static int i;

 

   i++;

}

void do_something(void)

{

   /*

    *  do something

    */

   calc_value();

   module_sleep(1);

}

 

int main (int argc, char **argv)

{

   while (1){

//     do_something();

   }

    return  (0);

}

 

2.1.2   加载性能分析模块(sperfs.ko)

(sperfs.ko模块为SylixOS性能分析检查提供一种调试工具)

点击IDE界面右上角“Device”;选择目标机器IP地址,这里使用的是虚拟机的IP地址:192.168.7.32,右击IP号打开“Launch FTP”进行传输;然后在本地文件夹中找到sperfs.ko模块,传输路径选择在“/lib/modules”目录下;最后双击sperfs.ko即可完成模块加载的准备工作,具体步骤如图 2‑1所示。

图 2‑1  加载sperfs.ko模块方法一

除上述方法外还可以通过“cp”指令将性能分析模块的拷贝在“/lib/modules”目录下,如图 2‑2所示。

图 2‑2  加载sperfs.ko模块方法二

完成后在“cd /lib/modules”目录下用“ls”查看是否完成拷贝,结果如图 2‑2所示。

图 2‑3  查看是否完成加载

然后通过“chmod”改变文件的权限,再用“modulereg”命令注册性能分析模块,如图 2‑3所示。

图 2‑4 注册内核模块

最后通过“sperfstart”命令开启性能分析的功能,再用“sperfs”命令查看性能分析结果,如图 2‑4所示。

图 2‑5  开启性能分析模块

除此之外我们通过Talnet再打开一个调试窗口,运行演示程序“perfoms_check_app”,性能分析结果如图 2‑5所示,除空闲线程t_idleo和sperfs.ko外消耗CPU时间最多的函数是程序是performs_check中的main函数,在这里只需要优化该函数就可以减少程序运行时间。

                                                                         图 2‑6  性能分析结果                                                

对该函数进行优化,优化结果如程序清单 2‑2所示。

程序清单 2‑2  main函数优化结果

int main (int argc, char **argv)

{

   while (1){

    do_something();

   }

    return  (0);

}

 

 

再次进行性能分析,结果如图 2‑6所示,main函数消耗的CPU时间已经大大减少。

图 2‑7  优化后性能分析结果

3. 总结

在SylixOS中可以使用多种调试方式进行相关调试,根据实际情况对程序进行调试,本节主要介绍性能分析检查工具。下一篇文档将通过一个完整的工程文件来描述多种调试方式。

4. 参考资料

《SylixOS应用程序开发手册》

《RealEvo-IDE使用手册》

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325943059&siteId=291194637