Matrix

CarlyleLiu‘s Blog

系统裁剪简介

固件中通常包含 boot0、 uboot、 kernel、 rootfs 等镜像。基于经验,各个镜像尺寸的量级如下表所示:

Image size
boot0 < 100k
uboot < 1M
kernel 3-15M
rootfs > 4M

可以看到 boot0、 uboot、 kernel、 rootfs 的尺寸是依次增大的。对于大尺寸的裁剪效果往往比小尺寸的裁剪效果明显,比如 rootfs 裁剪 1M 可能很容易,对于 uboot 来说,则非常困难。因此,后续主要介绍 kernel 以及 rootfs 的裁剪。

阅读全文 »

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_FRAMES 10

int myfunc1(int);
int myfunc2(int);
int myfunc3(int);

void printCallers()
{
int layers = 0, i = 0;
char ** symbols = NULL;

void * frames[MAX_FRAMES];
memset(frames, 0, sizeof(frames));
layers = backtrace(frames, MAX_FRAMES);
for (i=0; i<layers; i++) {
printf("Layer %d: %p\\n", i, frames[i]);
}
printf("------------------\\n");

symbols = backtrace_symbols(frames, layers);
if (symbols) {
for (i=0; i<layers; i++) {
printf("SYMBOL layer %d: %s\\n", i, symbols[i]);
}
free(symbols);
}
else {
printf("Failed to parse function names\\n");
}
}

int myfunc1(int a)
{
int b = a + 5;
int result = myfunc2(b);
return result;
}

int myfunc2(int b)
{
int c = b * 2;
int result = c + myfunc3(c);
return result;
}

int myfunc3(int c)
{
printCallers();
return 0;
}

int main()
{
int result = 0;
result = myfunc1(1);
printf("result = %d\\n", result);

return 0;
}
阅读全文 »

内存使用情况分析

DRAM 大小

硬件上 DDR 确定之后, DRAM 大小就已经确定。

uboot 会根据 DRAM 驱动提供的接口获取 DRAM 的大小,然后修改 dts 中的 memory 节点,Linux 启动时解析 dts 获取 DRAM 的大小。 uboot 启动 log 中会打印 dram 的大小。比如 R329 方案 uboot 启动时会有如下 log:

1
[01.300]DRAM: 128 MiB

执行:

1
2
3
root@TinaLinux:/# hexdump -C /sys/firmware/devicetree/base/memory@40000000/reg
00000000 00 00 00 00 40 00 00 00 00 00 00 00 08 00 00 00 |....@...........|
00000010

也可以获取 dram 的起始地址与大小。如下面 R329 例子所示,其中 0x40000000 为起始地址, 0x08000000 为 dram 的 size.

阅读全文 »

cpu 使用分析

top 命令

1
procps-ng-top -H -p 899 -w 120
  • -H 是线程模式
  • -p 指定进程 id
  • -w 指定显示宽度(列数)
  • -d 指定延时 ,屏幕更新间隔

shift+p 按照 cpu 使用率对线程排序。如下是一个实例:

阅读全文 »

概述

LeakTracer 是在检查 C++ 程序内存泄漏时编写的一个小工具。我无法让 dmalloc 显示我想要的内容,我只看到了提到的 __builtin_return_address gcc-extension。

要使用 LeakTracer,请使用提供的 LeakCheck 脚本运行您的程序。它使用 LD_PRELOAD 特性在你的函数之上“覆盖”一些函数(不需要重新编译)。如果您的平台不支持 LD_PRELOAD,您可以将 LeakTracer.o 对象文件添加到 Makefile 中的对象并运行您的应用程序。

LeakTracer 利用 gdb 去输出发生内存泄露所发生的位置,它是通过 override operator new, operator delete, operator malloc, operator free 来实现检测。

阅读全文 »

安装

ros 安装

设置 sources.list:

1
sudo sh -c 'echo "deb <http://packages.ros.org/ros/ubuntu> $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

设置 keys:

1
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

安装:

1
2
sudo apt-get update
sudo apt-get install ros-kinetic-desktop-full

设置环境:

1
2
3
4
5
echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
or
echo "source /opt/ros/kinetic/setup.zsh" >> ~/.zshrc
source ~/.zshrc

安装依赖:

1
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential

初始化 rosdep:

1
2
3
sudo apt install python-rosdep
sudo rosdep init
rosdep update
阅读全文 »

合并文件

1
ffmpeg -i "concat:file_name1.ts | file_name2.ts" -c copy_out.ts

在视频文件中提取图片

1
ffmpeg -i output.ts '%d.png'
阅读全文 »

Makefile 规则

一个简单的 Makefile 文件包含一系列的“规则”,其样式如下:

1
目标 (target)…: 依赖 (prerequiries)…<tab>命令 (command)
  • 目标 (target) 通常是要生成的文件的名称,可以是可执行文件或 OBJ 文件,也可以是一个执行的动作名称,诸如`clean’。
  • 依赖是用来产生目标的材料(比如源文件),一个目标经常有几个依赖。
  • 命令是生成目标时执行的动作,一个规则可以含有几个命令,每个命令占一行。 注意:每个命令行前面必须是一个 Tab 字符,即命令行第一个字符是 Tab。

通常,如果一个依赖发生了变化,就需要规则调用命令以更新或创建目标。但是并非所有的目标都有依赖,例如,目标“clern”的作用是清除文件,它没有依赖。 规则一般是用于解释怎样和何时重建目标。

make 首先调用命令处理依赖,进而才能创建或更新目标。当然,一个规则也可以是用于解释怎样和何时执行一个动作,即打印提示信息。一个 Makefile 文件可以包含规则以外的其他文本,但一个简单的 Makefile 文件仅仅需要包含规则。虽然真正的规则比这里展示的例子复杂,但格式是完全一样的。

对于上面的 Makefile,执行“make”命令时,仅当 hello.c 文件比 hello 文件新时才会执行命令“arm-linux-gcc –o hello hello.c”生成可执行文件 hello;如果还没有 hello 文件,这个命令也会执行。 运行“make clean”时,由于目标 clean 没有依赖,它的命令“rm -f hello”将被强制执行。

阅读全文 »
0%