Linux下那么多Tracer如何选择

如果你想要在linux下调调kernel, 抓抓程序的性能, 那么首先想到的可能是 OProfile 和 Linux Perf. 但是显然, 开源有一个非常显著地你无法回避的特点, 就是你会有太多的选择: perf, oprofile, systemtap, dtrace4linux, lttng, kgtp, ktap, sysdig, ftrace, eBPF. 是不是已经眼花了? 那么你不能错过这篇文章:

http://www.brendangregg.com/blog/2015-07-08/choosing-a-linux-tracer.html

介绍了目前常用的各类工具:

  1. ftrace
  2. perf_events
  3. eBPF
  4. SystemTap
  5. LTTng
  6. ktap
  7. dtrace4linux
  8. OL DTrace
  9. sysdig

作者非常细心的列出了大量的工具原理及使用教程, 保证会花掉你大把的晚上才能看完.

其实我日常使用的只有 perf, 只能算是 ‘most people’ 🙂

‘#include_next’ 的用途

最近在阅读开源项目代码的时候看到一个很少见的预处理命令:

#include_next

查询了一下, 并不是标准中的一部分, 属于 GNU 扩展, 使用的场合也比较少, 在某些新旧代码共存时或许会比较常见.

https://gcc.gnu.org/onlinedocs/cpp/Wrapper-Headers.html

2.7 Wrapper Headers

Sometimes it is necessary to adjust the contents of a system-provided header file without editing it directly. GCC’s fixincludes operation does this, for example. One way to do that would be to create a new header file with the same name and insert it in the search path before the original header. That works fine as long as you’re willing to replace the old header entirely. But what if you want to refer to the old header from the new one?

You cannot simply include the old header with ‘#include’. That will start from the beginning, and find your new header again. If your header is not protected from multiple inclusion (see Once-Only Headers), it will recurse infinitely and cause a fatal error.

You could include the old header with an absolute pathname:

#include “/usr/include/old-header.h”

This works, but is not clean; should the system headers ever move, you would have to edit the new headers to match.

There is no way to solve this problem within the C standard, but you can use the GNU extension ‘#include_next’. It means, “Include the next file with this name”. This directive works like ‘#include’ except in searching for the specified file: it starts searching the list of header file directories after the directory in which the current file was found.

OSDT 2015随笔

小雨夹着点雪

大家从各地陆陆续续的赶来

小会场

不过,氛围很好,聊的很热闹

不觉天色已晚

江湖人谈江湖事,以茶代酒风波庄

clang
Clang内部实现

SDCC
SDCC