Skip to content

Commit

Permalink
Update doc.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Aug 22, 2024
1 parent d8ccc27 commit fa14bc6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ If you want to disable it, please check bellow configure options:
--sanitizer-log=on|off Whether hijack the log for libasan(asan). Default: off
```

Enable leaks detection, see [halt_on_error](https://github.com/google/sanitizers/wiki/AddressSanitizerFlags)
and [detect_leaks](https://github.com/google/sanitizers/wiki/SanitizerCommonFlags):

```bash
ASAN_OPTIONS=halt_on_error=1:detect_leaks=1 ./objs/srs -c conf/console.conf
```

> Note: SRS disable memory leak detection by default, because it will cause daemon to exit with error.
Highly recommend to enable ASAN because it works great.

### ASAN: CentOS
Expand All @@ -143,7 +152,6 @@ yum install -y libasan
If you encounter the following error:

```bash
./objs/srs -c conf/console.conf
==4181651==ASan runtime does not come first in initial library list; you should either link runtime
to your application or manually preload it with LD_PRELOAD.
```
Expand All @@ -156,6 +164,29 @@ LD_PRELOAD=$(find /usr -name libasan.so.5 2>/dev/null) ./objs/srs -c conf/consol

> Note: Generally, the libasan.so file should be located at `/usr/lib64/libasan.so.5`
### ASAN: Options

By default, SRS use the following ASAN options:

```text
extern "C" const char *__asan_default_options() {
return "halt_on_error=0:detect_leaks=0:alloc_dealloc_mismatch=0";
}
```

* `halt_on_error=0`: Disable halt on errors by halt_on_error, only print messages, note that it still quit for fatal errors, see [halt_on_error](https://github.com/google/sanitizers/wiki/AddressSanitizerFlags).
* `detect_leaks=0`: Disable the memory leaking detect for daemon by detect_leaks, see [detect_leaks](https://github.com/google/sanitizers/wiki/SanitizerCommonFlags).
* `alloc_dealloc_mismatch=0`: Also disable alloc_dealloc_mismatch for gdb.

You can override the options by `ASAN_OPTIONS`:

```bash
ASAN_OPTIONS=halt_on_error=1:detect_leaks=1:alloc_dealloc_mismatch=1 ./objs/srs -c conf/console.conf
```

Note that the `ASAN_OPTIONS` will be loaded before the `main()` function, so you can set it in the shell,
but can not set in the `main()` function.

## GPROF

GPROF is a GNU tool, see [SRS GPROF](./gprof.md) and [GNU GPROF](http://www.cs.utah.edu/dept/old/texinfo/as/gprof.html).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ SRS5+内置和默认支持[ASAN](https://github.com/google/sanitizers/wiki/Addre
--sanitizer-log=on|off Whether hijack the log for libasan(asan). Default: off
```

开启内存泄露检测,参考[halt_on_error](https://github.com/google/sanitizers/wiki/AddressSanitizerFlags)
[detect_leaks](https://github.com/google/sanitizers/wiki/SanitizerCommonFlags) 的详细说明:

```bash
ASAN_OPTIONS=halt_on_error=1:detect_leaks=1 ./objs/srs -c conf/console.conf
```

ASAN检查内存问题很准确,推荐开启。

### ASAN: CentOS
Expand All @@ -146,7 +153,6 @@ yum install -y libasan
如果你遇到下面的错误:

```bash
./objs/srs -c conf/console.conf
==4181651==ASan runtime does not come first in initial library list; you should either link runtime
to your application or manually preload it with LD_PRELOAD.
```
Expand All @@ -159,6 +165,28 @@ LD_PRELOAD=$(find /usr -name libasan.so.5 2>/dev/null) ./objs/srs -c conf/consol

> Note: 一般而言,libasan.so 的路径是 `/usr/lib64/libasan.so.5`
### ASAN: Options

默认情况下,SRS使用以下ASAN选项:

```text
extern "C" const char *__asan_default_options() {
return "halt_on_error=0:detect_leaks=0:alloc_dealloc_mismatch=0";
}
```

* `halt_on_error=0`: 出现错误时不会退出,只是打印消息,注意fatal错误还是会退出,参考 [halt_on_error](https://github.com/google/sanitizers/wiki/AddressSanitizerFlags).
* `detect_leaks=0`: 禁用内存泄露的检测,由于daemon父进程会退出,全局变量会被认为是内存泄露,导致daemon启动失败,参考 [detect_leaks](https://github.com/google/sanitizers/wiki/SanitizerCommonFlags).
* `alloc_dealloc_mismatch=0`: GDB调试程序时,可能会出现这个错误。

尽管这样,你可以覆盖这些选项,比如开启内存泄露检测等:

```bash
ASAN_OPTIONS=halt_on_error=1:detect_leaks=1:alloc_dealloc_mismatch=1 ./objs/srs -c conf/console.conf
```

请注意,`ASAN_OPTIONS` 会在 `main()` 函数之前加载,因此可以在 shell 中设置,但不能在 `main()` 函数中设置。

## GPROF

GPROF是个GNU的CPU性能分析工具。参考[SRS GPROF](./gprof.md),以及[GNU GPROF](http://www.cs.utah.edu/dept/old/texinfo/as/gprof.html)
Expand Down

0 comments on commit fa14bc6

Please sign in to comment.