7 Star 118 Fork 46

AGeek / Keil5_disp_size_bar

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
LGPL-3.0

Keil5_disp_size_bar V1.0

简介

[Keil5_disp_size_bar]
以进度条百分比来显示keil编译后生成的固件对芯片的内存ram和存储flash的占用情况,
并生成各个源码文件对ram和flash的占比整合排序后的map信息的表格和饼图。

img_disp_size_bar

a_xlsx

原理是使用C语言遍历当前目录找到keil工程和编译后生成的map文件
然后读取工程文件和map文件来找到对应关键词内的ram和flash的各类信息
最后把信息整合以进度条字符串直观格式输出,同时把map的数据排序后导出csv和xlsx文件,绘制饼图。

注意:再次编译前先关闭已经使用excel打开的表格,或者先把原来的表格移走,不然excel占用表格文件导致没法输出新表格
注意:再次编译前先关闭已经使用excel打开的表格,或者先把原来的表格移走,不然excel占用表格文件导致没法输出新表格
注意:再次编译前先关闭已经使用excel打开的表格,或者先把原来的表格移走,不然excel占用表格文件导致没法输出新表格

该程序容易和keil的after bulid功能集成,以便嵌入式软件工程师方便知道芯片占用情况,进行裁剪和优化。

这个项目也有一个Qt的版本:https://gitee.com/nikolan/keil_development_assistant
表格和进度条等内容直接在图形化的Qt应用查看
不过这个命令行的版本虽然没法交互,但是更容易集成到项目工程内,不太占空间,且纯C库依赖少,执行更快,各有各的好处。

基本能找到编译后生成的map文件,
就能输出生成的代码对ram和flash的占用大小百分比进度条,和表格数据。
只要能找到工程文件和map文件,keil5环境下通用,对于没有使用分散加载的stm32和各种国产32一般都是可以直接适配的。
程序如果没有输出或输出有错误请查看运行日志 _alog.txt,看程序在哪个步骤断开没有往下执行。
项目内附上一个H7B0工程文件和map文件用于测试。

该项目代码可应用于二次开发,任何数据使用C语言整合信息用链表排序后,以表格方式输出。
例如统计自己源码的某些信息,例如RTOS创建的任务信息或者函数关系等。

使用方法:

  1. 把程序Keil5_disp_size_bar.exe放到工程目录下,
    要放在在.map文件更上一层的目录,
    例如可以放在和工程文件.uvoptx同一目录下。

img_dir

  1. 在工程打开魔术棒配置,在User的After Build/Rebuild下
    添加编译后执行程序#Run1或#Run2,
    在前面打钩,后面则选择要执行的程序Keil5_disp_size_bar.exe对应路径
    注意要选对是当前工程目录下的Keil5_disp_size_bar.exe
    最好还是使用相对路径,避免工程移动后导致找不到。
    (为避免移动工程后,路径找不到的情况。也可手动输入 相对当前工程文件的相对路径,例如:"./Keil5_disp_size_bar.exe")

如果选错其他工程的,编译出的信息则是其他工程的map文件

最新版本支持传入参数
./Keil5_disp_size_bar.exe 参数1 参数2 参数3 参数4 参数5

参数1:工程文件和map文件的递归查找目录,默认是"./"即exe所在目录
参数2:map文件的递归查找目录,默认是"./"即exe所在目录
参数3:是否输出程序详细运行过程,默认是0不输出,1则输出。
参数4:打印进度条已占用时的字符串,默认是"■"
参数4:打印进度条未占用时的字符串,默认是"_"

img_after_bild

  1. 接着每次对工程按下编译,编译完成后就能看到生成的代码对ram和flash的占用大小百分比进度条。
    img_disp_size_bar

同时生成了4个文件

  • xxx_alog.txt 是程序运行日志文件,当输出不对或没有输出时可以查看
  • xxx_sort_by_flash.csv是把文件按flash占用排序的表格
  • xxx_sort_by_ram.csv是把文件按ram占用排序的表格
  • xxx_analysis.xlsx是文件ram和flash的占用和绘制的百分比饼图

chart
csv
alog
xlsx

  1. 如果执行了Keil5_disp_size_bar.exe,却没有输出占用百分比进度条,或者输出的信息有误
    请检测输出的错误消息或alog日志文件,最大可能是当前工程或者你放置程序的目录下递归查找也找不到map文件,
    请检测工程的Output输出生成配置,然后按下全部重新编译一次再看看能不能输出占用百分比进度条。

img_find_map

二次开发环境搭建

  1. 系统:windos10
  2. 编译器mingw-64
  3. 编辑器:例如vscode(使用其他IDE环境也可)

工程结构如下:
├─.vscode
├─inc(头文件)
│ └─xlsxwriter(头文件)
│ └─third_party(头文件)
├─lib(静态库)
└─src(源码)

开发方式和linux下编译开发C语言差不多,通过make或者gcc指令编译。

源码是使用GB2312格式编码的字符,使用其他编码打开的话中文注释和特殊字符会乱码。 因为keil如果使用utf-8输出到cmd的会带乱码,这是因为window的cmd中文默认GB2312。

代码通过预编译实现了库的可裁剪
Makefile的USED_XLSXWRITER_LIB=1 默认是1,编译xlsxwriter库

如果USED_XLSXWRITER_LIB=0
则代码生成xlsx文件部分代码则被裁剪掉,只会生成csv文件。

版本更新日志

. 更新到v1.0 版本1.0进行了大更新

  • 代码规范化,大部分变量以结构体形式封装,且函数接口有较详细注释
  • 支持main函数传参 参数1:工程和map的递归查找地址 参数2:map递归查找地址 参数3是否输出运行过程到终端,参数4进度条占用字符串 参数5进度条不占用字符串
  • 支持显示ram和flash段的基地址,且按基地址纠正是ram还是flash
  • 程序运行后直接输出结果,程序的运行过程默认不输出到终端而是保存在 工程名_alog.txt内,要输出则传参数4为 1
  • 解析文件在已使用的ram和flash的占比,导出csv和xlsx表格结果,xlsx表格会画出百分比的饼图,csv则需要自己使用excel画

. 更新到v0.4

  • 把uint64_t改为uint32_t,因为发现sscanf函数的%x给赋值时,64位好像会因为对齐问题错误。

  • 修复递归查找不彻底导致子目录下的map找不到

  • 添加C51支持8051 测试STC89C52和WCH552均测试可以,但是部分工程没有写xram的大小的默认只能以iram大小替代。 还有部分工程是没有在工程定义真正大小的,也就是芯片本身没有keil开发包,用其他芯片或通用开发包定义的工程。 在keil上是没有定义对应芯片型号或用了其他芯片的定义的8051这就会导致显示占用的最大值错误。 要确保工程文件里面的IRAM,XRAM,IROM都是正确的才行。

  • 同时发现部分例如stm32F0系列的工程map文件格式不同,可能早期map不怎么统一规范,给的max都是0xFFFFFFFF,无法输出进度条,只能读工程的里芯片定义的max,来替代map文件的max,所以部分自定义的显示不出来,工程文件有些格式也是会不一样有的以逗号分隔有的以-分隔。

. 更新到v0.3

  • 修改进度条部分字符对齐问题,方块字符选择了正方形等宽
  • 根据网友的反馈由于关键词(Exec关键词有部分map文件不存在,关键词改成Execution Region检索执行段
  • 加大ram和flash的占用信息存储数组的上限为30,有的map的flash分开的段比较多,或者自定义了.bss的内存池
  • 根据网友反馈使用了自定义malloc的内存池的ram被归类为了flash,除了带RAM外添加带ER$$的也视为RAM
  • 百分比修改以KB单位的显示占用分子分母
  • 最后以B为单位显示剩余可用空间
  • %d显示改为%u显示无符号整数

. 更新到V0.2

  • 更改进度条样式

  • 采用关键词(Exec模糊检索ram和flash的size和max

  • 支持多个ram和flash的占用百分比进度条显示

  • 一个极客 ageek nikola 开源

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

简介

[Keil5_disp_size_bar]:以进度条百分比来显示keil编译后代码对芯片的内存ram和存储flash的占用情况。 原理是使用C语言遍历目录找到keil工程生成出的.map文件,然后找到对应的ram和flash的总大和占用大小,然后以进度条和百分比的直观格式输出来,以便嵌入式软件工程师方便调试,知道芯片占用情况,进行裁剪和优化。 展开 收起
C 等 2 种语言
LGPL-3.0
取消

发行版 (1)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/nikolan/keil5_disp_size_bar.git
git@gitee.com:nikolan/keil5_disp_size_bar.git
nikolan
keil5_disp_size_bar
Keil5_disp_size_bar
master

搜索帮助