Welcome 微信登录

首页 / 操作系统 / Linux / latencytop深度了解你的Linux系统的延迟

我们在系统调优或者定位问题的时候,经常会发现多线程程序的效率很低,但是又不知道问题出在哪里,就知道上下文切换很多,但是为什么上下文切换,是谁导致切换,我们就不知道了。上下文切换可以用dstat这样的工具查看,比如:[shell]
$dstat
—-total-cpu-usage—- -dsk/total- -net/total- —paging– —system–
usr sys idl wai hiq siq| read writ| recv send| in out | int csw
9 2 87 2 0 1|7398k 31M| 0 0 | 9.8k 11k| 16k 64k
20 4 69 3 0 4| 26M 56M| 34M 172M| 0 0 | 61k 200k
21 5 64 6 0 3| 26M 225M| 35M 175M| 0 0 | 75k 216k
21 5 66 4 0 4| 25M 119M| 34M 173M| 0 0 | 66k 207k
19 4 68 5 0 3| 23M 56M| 33M 166M| 0 0 | 60k 197k#或者用systemtap脚本来看
$sudo stap -e ‘global cnt; probe scheduler.cpu_on {cnt<<<1;} probe timer.s(1){printf("%d ", @count(cnt)); delete cnt;}"
217779
234141
234759
[/shell]每秒高达200k左右的的上下文切换, 谁能告诉我发生了什么? 好吧,latencytop来救助了!它的官网:http://www.latencytop.org/Skipping audio, slower servers, everyone knows the symptoms of latency. But to know what’s going on in the system, what’s causing the latency, how to fix it… that’s a hard question without good answers right now.LatencyTOP is a Linux* tool for software developers (both kernel and userspace), aimed at identifying where in the system latency is happening, and what kind of operation/action is causing the latency to happen so that the code can be changed to avoid the worst latency hiccups.
它是Intel贡献的另外一个性能查看器,还有一个是powertop,都是很不错的工具.Latencytop通过在内核上下文切换的时候,记录被切换的进程的内核栈,然后通过匹配内核栈的函数来判断是什么原因导致上下文切换,同时他把几十种容易引起切换的场景的函数都记录起来,这样在判断系统问题的时候能容易定位到问题。latencytop分成2个部分,内核部分和应用部分。内核部分负责调用栈的收集并且通过/proc来暴露, 应用部分负责显示. 工作界面截图如下:latencytop在2.6.256后被内核吸收成为其中一部分,只要编译的时候打开该选项就好,如何确认呢?
[shell]
$ cat /proc/latency_stats
Latency Top version : v0.1
[/shell]
看到这个就好了, 遗憾的是RHEL6竟然带了latencytop应用部分,而没有打开编译选项,让我们情何以堪呢?
在Ubuntu下可以这么安装:[shell]
$ uname -r
2.6.38-yufeng
$ apt-get install latencytop
$ sudo latencytop #就可以使用了
[/shell]但是latencytop比较傻的是默认是开图像界面的,我们很不习惯,我们要文本界面, 自己动手把![shell]
$ apt-get source latencytop
$ diff -up Makefile.orig Makefile
— Makefile.orig 2011-03-29 20:10:29.025845447 +0800
+++ Makefile 2011-03-28 14:48:11.232318002 +0800
@@ -1,5 +1,5 @@
# FIXME: Use autoconf ?
-HAS_GTK_GUI = 0
+#HAS_GTK_GUI = 0DESTDIR =
SBINDIR = /usr/sbin
[/shell]
  • 1
  • 2
  • 3
  • 4
  • 下一页
Ubuntu 11.04 安装 JAVA 方法Linux下新系统调用sync_file_range提高数据sync的效率相关资讯      Linux系统 
  • 是否将Linux作为第二系统的七个理  (今 09:15)
  • 四套专为儿童设计的 Linux 系统  (01/23/2015 08:59:43)
  • 开发者移情别恋 Linux系统为何遭到  (05/21/2014 06:28:16)
  • Linux 系统是否适合于您?  (09/21/2015 13:09:51)
  • 为什么应该将Linux系统“一分为二  (09/15/2014 17:01:29)
  • Linux内核管理--之定制一个属于自  (03/07/2014 17:08:19)
本文评论 查看全部评论 (0)
表情: 姓名: 字数