Solaris 动态跟踪指南

计时器分辨率

profile 提供器使用操作系统中的任意分辨率间隔计时器。在不支持真正基于任意分辨率时间中断的体系结构中,此频率受系统时钟频率的限制,由 hz 内核变量指定。此类体系结构中频率高于 hz 的探测器将每隔 1/hz 秒触发若干次。例如,这种体系结构中一个 1000 赫兹的 profile 探测器(hz 设置为 100)将每隔 10 毫秒快速连续触发 10 次。在支持任意分辨率的平台上,1000 赫兹的 profile 探测器将准确地每隔 1 毫秒触发一次。

以下示例测试给定体系结构的分辨率:

profile-5000
{
	/*
	 * We divide by 1,000,000 to convert nanoseconds to milliseconds, and
	 * then we take the value mod 10 to get the current millisecond within
	 * a 10 millisecond window.  On platforms that do not support truly
	 * arbitrary resolution profile probes, all of the profile-5000 probes
	 * will fire on roughly the same millisecond.  On platforms that
	 * support a truly arbitrary resolution, the probe firings will be
	 * evenly distributed across the milliseconds.
	 */
	@ms = lquantize((timestamp / 1000000) % 10, 0, 10, 1);
}

tick-1sec
/i++ >= 10/
{
	exit(0);
}

在支持任意分辨率 profile 探测器的体系结构中,运行此示例脚本将产生均匀分布:


# dtrace -s ./restest.d
 dtrace: script './restest.d' matched 2 probes
CPU     ID                    FUNCTION:NAME
  0  33631                       :tick-1sec 


           value  ------------- Distribution ------------- count    
             < 0 |                                         0        
               0 |@@@                                      10760    
               1 |@@@@                                     10842    
               2 |@@@@                                     10861    
               3 |@@@                                      10820    
               4 |@@@                                      10819    
               5 |@@@                                      10817    
               6 |@@@@                                     10826    
               7 |@@@@                                     10847    
               8 |@@@@                                     10830    
               9 |@@@@                                     10830

在不支持任意分辨率 profile 探测器的体系结构中,运行此示例脚本将产生不均匀分布:


# dtrace -s ./restest.d
 dtrace: script './restest.d' matched 2 probes
 CPU     ID                    FUNCTION:NAME
  0  28321                       :tick-1sec 


           value  ------------- Distribution ------------- count    
               4 |                                         0        
               5 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  107864   
               6 |                                         424      
               7 |                                         255      
               8 |                                         496      
               9 |                                         0

在这些体系结构中,可在 /etc/system 中手动调整 hz,以提高有效的配置文件分辨率。

当前,UltraSPARC (sun4u) 的所有变体均支持任意分辨率 profile 探测器。x86 体系结构 (i86pc) 的许多变体也支持任意分辨率 profile 探测器,但是一些较旧的变体不支持。