0%

Basic

Here is A little basic knowledge of shell.

env

1
2
3
4
5
6
$USER
$UID
$PATH

set | more # check the variables including shell-local variables(including shell functions)
env | less # check the variables except shell-local variables(including shell functions)

Parameters

Here is a cheetsheet about parameters of shell.

Parameters Comments
$0 script name
$<n> the <n>th parameter
$# nums of parameters
$@ All parameters, could be a list
$* All parameters, but behave as a whole
$$ PID of the current progress
$? return of last cmd
$! PID of the last background cmd
Read more »

之前为了让终端炫酷好用,配置了 Terminator + Oh My ZSH + autosuggestions + highlighting + Agnoster theme + powerline fonts + solarized colors,可是终端的反应速度受到了影响,移植性也不高,最主要的是对于我来说,Terminator 不够 Terminal + Tmux 酷,所以最近决定切回 Terminal + Tmux

TerminalUbuntu 自带的终端,就不做介绍了。今天主要聊聊Tmux 的基本用法,做一个备忘录。 Tmux 除了分屏功能外,还有一个功能我很喜欢,即 persistent,也就是运行在 Tmux 中的程序在其断开前会一直保持运行状态。譬如:远程登录服务器,通过 Tmux 运行程序,即使本地登录客户端断开,程序也会保持运行,除非我们在服务器端退出 Tmux 或者重启服务器。

Read more »

日常开发和调试中,用好 Linux 下的各种工具能事半功倍。本文记录了除基础命令外,一些非常实用但又容易被忽略的工具和技巧。

系统调试

查看内核/设备信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 查看内核 Oops 信息
objdump -dS vmlinux > /tmp/kernel.s
objdump -t vmlinux

# 查看内核模块符号
nm -n char.ko
ld char.ko --print-map

# 查看内存布局
cat /proc/iomem
cat /sys/kernel/debug/memblock/reserved

# 查看 MTD 分区
cat /proc/mtd

# 查看内核配置中的 debugfs
zgrep -i debugfs /proc/config.gz

# 实时查看内核日志
dmesg -w
Read more »

How does the repo of android source code work ?

.repo

通常情况下, Android 的 .repo 里面有如下内容:

1
2
$ ls .repo
manifests manifests.git manifest.xml project.list project-objects projects repo

manifests

manifests 路径是项目 manifest 仓的 git checkout,其中的 .gitmanifest.git 的软链接,追踪 repo init --manifest-branch 指定的分支。

1
2
3
4
5
6
7
.repo$ ls manifests/.git/
config HEAD index logs ORIG_HEAD refs shallow
description hooks info objects packed-refs rr-cache svn

.repo$ ls manifests.git/
branches description HEAD info objects refs svn
config FETCH_HEAD hooks logs packed-refs rr-cache

不管远程分支名字是什么,manifests 的本地分支命名为 default。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
.repo$ cat manifests/.git/HEAD 
ref: refs/heads/default

.repo$ cat manifests.git/config
# cat manifests/.git/config
[core]
repositoryformatversion = 0
filemode = true
[filter "lfs"]
smudge = git-lfs smudge --skip -- %f
[remote "origin"]
url = https://<url>/platform/manifest.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "default"]
remote = origin
merge = refs/heads/<remote_branch_name>

manifests.git

manifests.git 是当前项目 manifest 仓的一个没有工作空间的 checkout,即只 checkout .git ,追踪repo init --manifest-url 指定的 Git 仓。不能手动修改这部分,如果需要修改的话,可重新运行 repo init 来更新设置。

.repo_config.json

缓存 manifests.git/config,用来提升 repo 的速度。

manifest.xml

repo 使用的 manifest , 此文件由 repo init --manifest-name 指定链接到 manifests 中的哪一个文件,如下:

1
manifest.xml -> manifests/<manifest-name>.xml # 指向用户希望用来同步源码的 manifest
Read more »

俗话说“雨过留痕,雁过留声”,之前因为工作需要折腾了小几个月的性能 BUG,还是得留下一点东西,这是第一篇:Android 性能调试手册,这篇文章简单聊聊工作中应该怎么进行性能分析。因为没有深入研究 Performance 相关内容,所以保留出错的权利。

0. 写在开头

在我司处理 Performance 问题时,大多数情况不会像顶级大厂那样优化每一帧,尽量榨干每一个硬件的性能。因为没有前人提供经验,全是自己总结的,如果存在有失偏颇的地方,你也只能看着。我理解的主要处理方式如下:

  • 第一种,推不解。

    • gaps 小, 个人经验是 10% 以内即可以尝试推不解,譬如:问题机 Chrome 启动时间为 800 ms, 对比机为 750 ms。
    • 分析出时间消耗,列出与对比机的对比, 详细阐述差分部分,一般来说大部分差分是原生代码引起,或者 gaps 很小。
  • 第二种嘛,当然就是想办法解决或优化了。

1. 怎么开始?

针对任何性能问题,我觉得第一步都先需要做如下三个确认:

  1. 确认问题现象,最好自己复现一次。
  2. 确认有没有大量 crash 发生。
  3. 查看 kernel footprint(config), 确认是否使用 perf config: msmxxx-perf_defconfig。
Read more »

“雨过留痕,雁过留声”的第二篇:APP 启动,触摸事件和 UI 绘制的简单分析示例,此文通过 systrace 分析一个示例 APP 的启动、触摸事件和 UI 绘制的流程和时间消耗。本文的示例 APP (SimpleApplication.apk)只有一个简单的按钮, 点击按钮时会改变屏幕的颜色。同样因为没有深入研究 Performance 相关内容,所以保留出错的权利。

如果对第一篇感兴趣,请查看: Android 性能调试手册.

0. 写在开头

我一开始看到 systrace 文件时,是一脸懵逼的,所以在开始正文之前先简单说一下 systrace 文件中的一些基本信息,如下:

  • Frames: 一个圆圈代表一帧。
    • 绿色:正常;
    • 黄色、红色: 异常,如卡顿、掉帧(Jank) 等,可能是它的渲染时间超过了 16.67ms(60fps)。
    • 点击圆圈可查看详细信息
  • Alerts: 右侧标签,跟踪记录中出现的问题以及这些问题导致出现卡顿的频率
  • system_server iq: 第一帧的触发
  • gfx3d_clk : GPU 频率
  • iq in systemsever : 触发中断
  • bindApplication, activityStart ...: 表示冷启动, 热启动不会有这些信息。
  • surfaceflinger->UI Thread->HIDL::IComposerClient:setPowerMode_2_2:client: 代表 LCD 上电时间

    一般使用 Chrome 打开 systrace.html, 右上角的 也可以提供一些基本的帮助

1. 获取 systrace

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
a. python systrace.py gfx input view sched am wm dalvik freq idle power video app -b 40960 -t 10 -o traceout.html

Explaination of these categories:
gfx - Graphics
input - Input
view - View System
wm - Window Manager
am - Activity Manager
hal - Hardware Modules
res - Resource Loading
dalvik - Dalvik VM
power - Power Management
sched - CPU Scheduling
freq - CPU Frequency
idle - CPU Idle

b. Motion: Click icon of SimpleApplication to open it, click first time to change background as white, click sencond time to change background as black.
Read more »

之前折腾局域网搭建 Gitbook,并写了一篇简易教程:Gitbook + Jenkins + Gitlab 搭建内网自动构建的 Gitbook。最近兴趣使然又用 docker 搭建了一套方便部署的内网 Gitbook 镜像,因此也总结一篇简易教程如下。

Install Docker

1
sudo apt install docker

Gitbook

Gitbook Image

下载 Gitbook Docker 镜像,我选择了 billryan/gitbook 镜像

1
docker pull billryan/gitbook

mkdir gitbook 创建一个 gitbook 路径,我们也可以将启动的镜像存储为另一个镜像:

1
2
3
4
5
6
7
8
# init
docker run --rm -v "$PWD/gitbook:/gitbook" -p 4000:4000 billryan/gitbook gitbook init
# serve
docker run --rm -v "$PWD/gitbook:/gitbook" -p 4000:4000 billryan/gitbook gitbook serve


docker ps # Get CONTAINER ID of gitbook
docker commit <CONTAINER ID> andylee/gitbook:1.0
Read more »

日常使用 Linux 终端时,掌握一些高效的快捷键和技巧可以大幅提升工作效率。本文整理了 Bash 终端中常用的效率技巧。

历史命令操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 重复上一条命令
!!

# 获取上一条命令的所有参数
!*

# 获取上一条命令的最后一个参数
!$

# 反向搜索历史命令(持续按 Ctrl + R 继续向上搜索)
Ctrl + r

# 允许多个终端同时写历史文件
shopt -s histappend

# 查看最常使用的历史命令
history | awk 'BEGIN {FS="[ \t]+|\\|"} {print $3}' | sort | uniq -c | sort -nr | head
Read more »