Skip to content

Commit

Permalink
v1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoHaw committed Nov 20, 2023
1 parent ec93079 commit da529e8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# keil-build-viewer v1.3
# keil-build-viewer v1.4

![演示界面](images/main.png)

Expand Down Expand Up @@ -37,6 +37,11 @@
6. 显示最大的栈使用
- 数据来自 keil ,静态无法精确分析,数据仅供参考

7. 支持放置于公共目录后,可在任意目录调用本工具,无需跟随 keil uvproj(x) 工程
- v1.4 新增功能
- **必须设置好系统环境变量,并把 `keil-build-viewer.exe` 放置于系统环境变量所指定的目录中**,建议使用系统环境变量 `Path`
- 可节省拷贝 `keil-build-viewer.exe` 至对应 keil uvproj(x) 工程的步骤,但 `after build` 仍需填写,详见 `2 在 keil 中使用`

> **说明:** 本工具的所有参数可不按顺序输入,为空时表示选择默认值,但参数与参数之间需用**空格**隔开
> **双击打开对应文件动画演示**
Expand Down Expand Up @@ -108,13 +113,13 @@
## 修改记录
| 版本 | 日期 |修改者 |修改内容 |
|:----:|:----------:|--------------|-----------------------------------------|
| v1.0 | 2023-11-10 | Dino | 初版发布 |
| v1.1 | 2023-11-11 | Dino | 1. 适配 RAM 和 ROM 的解析 |
| 版本 | 日期 |修改者 |修改内容 |
|:----:|:----------:|--------------|---------------------------------------------------|
| v1.0 | 2023-11-10 | Dino | 初版发布 |
| v1.1 | 2023-11-11 | Dino | 1. 适配 RAM 和 ROM 的解析 |
| v1.2 | 2023-11-11 | Dino | 1. 适配 keil4 的 map 文件<br>2. 增加检测到开启 LTO 后打印提示信息<br>3. 修复开启 LTO 后无打印 region 的问题 |
| v1.3 | 2023-11-12 | Dino | 1. 修复工程存在多个 lib 时仅解析一个的问题 |
| v1.3 | 2023-11-12 | Dino | 1. 修复工程存在多个 lib 时仅解析一个的问题 |
| v1.4 | 2023-11-21 | Dino | 1. 增加将本工具放置于系统环境变量 Path 所含目录的功能 |
## 重要说明
> **1. 目前仅支持 keil MDK。**
Expand Down
47 changes: 28 additions & 19 deletions keil-build-viewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* This file is keil-build-viewer.
*
* Author: Dino Haw <[email protected]>
* Version: v1.3
* Version: v1.4
* Change Logs:
* Version Date Author Notes
* v1.0 2023-11-10 Dino the first version
Expand All @@ -38,6 +38,7 @@
* 2. 增加检测到开启 LTO 后打印提示信息
* 3. 修复开启 LTO 后无打印 region 的问题
* v1.3 2023-11-12 Dino 1. 修复工程存在多个 lib 时仅解析一个的问题
* v1.4 2023-11-21 Dino 1. 增加将本工具放置于系统环境变量 Path 所含目录的功能
*/

/* Includes ------------------------------------------------------------------*/
Expand Down Expand Up @@ -94,20 +95,15 @@ int main(int argc, char *argv[])
{
clock_t run_time = clock();

/* 1. 获取本程序所在目录 */
GetModuleFileName(NULL, _current_dir, MAX_PATH);

char *last_slash = strrchr(_current_dir, '\\');
if (last_slash) {
*last_slash = '\0';
}
/* 1. 获取程序运行的工作目录 */
GetCurrentDirectory(MAX_PATH, _current_dir);

/* 创建 log 文件 */
char file_path[MAX_PATH];
snprintf(file_path, sizeof(file_path), "%s\\%s.log", _current_dir, APP_NAME);
_log_file = fopen(file_path, "w+");

log_print(_log_file, "\n=================================================== %s %s ==================================================\n", APP_NAME, APP_VERSION);
log_print(_log_file, "\n=================================================== %s %s ==================================================\n ", APP_NAME, APP_VERSION);

/* 2. 搜索同级目录或指定目录下的所有 keil 工程并打印 */
_keil_prj_path_list = prj_path_list_init(MAX_PATH_QTY);
Expand Down Expand Up @@ -187,7 +183,7 @@ int main(int argc, char *argv[])
{
keil_prj_path = _keil_prj_path_list->items[_keil_prj_path_list->size - 1];

last_slash = strrchr(keil_prj_path, '\\');
char *last_slash = strrchr(keil_prj_path, '\\');
if (last_slash)
{
last_slash += 1;
Expand Down Expand Up @@ -625,14 +621,23 @@ int main(int argc, char *argv[])
}

/* 11.2 开始打印 */
bool is_print_null = true;
for (struct load_region *l_region = _load_region_head;
l_region != NULL;
l_region = l_region->next)
{
log_print(_log_file, "%s\n", l_region->name);
memory_print_process(_memory_info_head, l_region->exec_region, MEMORY_TYPE_SRAM, max_region_name, is_has_region);
memory_print_process(_memory_info_head, l_region->exec_region, MEMORY_TYPE_FLASH, max_region_name, is_has_region);
memory_print_process(_memory_info_head, l_region->exec_region, MEMORY_TYPE_UNKNOWN, max_region_name, is_has_region);
memory_print_process(_memory_info_head, l_region->exec_region, MEMORY_TYPE_SRAM, max_region_name, is_has_region, is_print_null);
memory_print_process(_memory_info_head, l_region->exec_region, MEMORY_TYPE_FLASH, max_region_name, is_has_region, is_print_null);
memory_print_process(_memory_info_head, l_region->exec_region, MEMORY_TYPE_UNKNOWN, max_region_name, is_has_region, is_print_null);

for (struct memory_info *memory_temp = _memory_info_head;
memory_temp != NULL;
memory_temp = memory_temp->next)
{
memory_temp->is_printed = false;
}
is_print_null = false;
}

/* 12. 打印栈使用情况 */
Expand Down Expand Up @@ -2046,13 +2051,15 @@ void object_print_process(struct object_info *object_head,
* @param type: 指定打印的 execution region 内存类型
* @param max_region_name: 最大的 execution region 名称长度
* @param is_has_record: 是否有记录文件
* @param is_print_null: 是否打印未使用的存储器
* @retval None
*/
void memory_print_process(struct memory_info *memory_head,
struct exec_region *e_region,
MEMORY_TYPE type,
size_t max_region_name,
bool is_has_record)
bool is_has_record,
bool is_print_null)
{
size_t sram_id = 0;
size_t flash_id = 0;
Expand Down Expand Up @@ -2136,7 +2143,7 @@ void memory_print_process(struct memory_info *memory_head,
else
{
used_size = (double)region->used_size / (1024 * 1024);
snprintf(used_size_str, sizeof(used_size_str), "%5.2f MB", used_size);
snprintf(used_size_str, sizeof(used_size_str), "%5.1f MB", used_size);
}

if (region->size < 1024)
Expand All @@ -2152,7 +2159,7 @@ void memory_print_process(struct memory_info *memory_head,
else
{
size = (double)region->size / (1024 * 1024);
snprintf(size_str, sizeof(size_str), "%5.2f MB", size);
snprintf(size_str, sizeof(size_str), "%5.1f MB", size);
}

double percent = (double)region->used_size * 100 / region->size;
Expand All @@ -2168,8 +2175,10 @@ void memory_print_process(struct memory_info *memory_head,
strncat_s(progress, sizeof(progress), USED_SYMBOL, strlen(USED_SYMBOL));
}
/* 小于显示比例,避免是空的 */
if (used == 0 && region->used_size != 0) {
if (used == 0 && region->used_size != 0)
{
strncpy_s(progress, sizeof(progress), USED_SYMBOL, strlen(USED_SYMBOL));
used = 1;
}
/* 将占用部分的 ZI 部分替换 */
for (struct region_block *block = region->zi_block;
Expand All @@ -2179,7 +2188,7 @@ void memory_print_process(struct memory_info *memory_head,
size_t zi_start = ((double)block->start_addr - region->base_addr) * 100 / region->size / 2;
size_t zi_end = ((double)block->start_addr + block->size - region->base_addr) * 100 / region->size / 2;

if (zi_start == 0) {
if (region->base_addr > block->start_addr) {
zi_start = 1;
}
log_save(_log_file, " [zi start] %d [zi end] %d\n", zi_start, zi_end);
Expand Down Expand Up @@ -2240,7 +2249,7 @@ void memory_print_process(struct memory_info *memory_head,

if (is_print_region == false)
{
if (type != MEMORY_TYPE_UNKNOWN)
if (is_print_null && type != MEMORY_TYPE_UNKNOWN)
{
log_print(_log_file, " %s%*s [0x%.8X | 0x%.8X (%d)]\n",
str, max_region_name, " ", memory_temp->base_addr, memory_temp->size, memory_temp->size);
Expand Down
5 changes: 3 additions & 2 deletions keil-build-viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <windows.h>

#define APP_NAME "keil-build-viewer"
#define APP_VERSION "v1.3"
#define APP_VERSION "v1.4"

#define MAX_DIR_HIERARCHY 32 /* 最大目录层级 */
#define MAX_PATH_QTY 32 /* 最大目录数量 */
Expand Down Expand Up @@ -259,7 +259,8 @@ void memory_print_process (struct memory_info *memory_
struct exec_region *e_region,
MEMORY_TYPE type,
size_t max_region_name,
bool is_has_record);
bool is_has_record,
bool is_print_null);
void stack_print_process (const char *file_path);
void log_write (FILE *p_log,
bool is_print,
Expand Down

0 comments on commit da529e8

Please sign in to comment.