首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何理解系统开发脚本中的"$location“?

如何理解系统开发脚本中的"$location“?
EN

Stack Overflow用户
提问于 2014-11-12 09:00:31
回答 1查看 227关注 0票数 0

Systemtap脚本:

代码语言:javascript
复制
# Array to hold the list of drop points we find
global locations

# Note when we turn the monitor on and off
probe begin { printf("Monitoring for dropped packets\n") }
probe end { printf("Stopping dropped packet monitor\n") }

# increment a drop counter for every location we drop at
#probe kernel.trace("kfree_skb") { locations[$location] <<< 1 }

# Every 5 seconds report our drop locations
probe timer.sec(5)
{
        printf("\n")
        foreach (l in locations-) {
                printf("%d packets dropped at location %p\n",
                           @count(locations[l]), l)
        }
        delete locations
}

kfree_skb()的源代码是:

代码语言:javascript
复制
void kfree_skb(struct sk_buff *skb)
{
    if (unlikely(!skb))
        return;
    if (likely(atomic_read(&skb->users) == 1))
        smp_rmb();
    else if (likely(!atomic_dec_and_test(&skb->users)))
        return;
    trace_kfree_skb(skb, __builtin_return_address(0));
    __kfree_skb(skb);
}

我只想知道$location从哪里来?和

$locationkfree_skb()之间的关系是什么?

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-12 18:00:05

根据stap.1手册页:

代码语言:javascript
复制
   Many types of probe points provide context variables, which are
   run-time values, safely extracted from the kernel or userspace
   program being probed.  These are pre‐ fixed with the $
   character.  The CONTEXT VARIABLES section in stapprobes(3stap)
   lists what is available for each type of probe point.

根据stapprobes.3stap .3 page手册页:

代码语言:javascript
复制
KERNEL TRACEPOINTS

   This family of probe points hooks up to static probing
   tracepoints inserted into the kernel or modules.  [...]

   Tracepoint probes look like: kernel.trace("name").  The
   tracepoint name string, which may contain the usual wildcard
   characters, is matched against the names defined by the kernel
   developers in the tracepoint header files.

   The handler associated with a tracepoint-based probe may read
   the optional parame‐ ters specified at the macro call site.
   [...] For example, the tracepoint probe kernel.trace("sched_switch")
   provides the parameters $rq, $prev, and $next.  [...]

   The name of the tracepoint is available in $$name, and a string
   of name=value pairs for all parameters of the tracepoint is
   available in $$vars or $$parms.

根据linux内核源代码:

代码语言:javascript
复制
% cd net/core
% git grep trace_kfree_skb

dev.c: [...]
drop_monitor.c: [...]
skbuff.c: [...]

% cd ../../include/trace/events
% git grep -A5 'TRACE_EVENT.*kfree_skb'

skb.h:TRACE_EVENT(kfree_skb,
skb.h-
skb.h-  TP_PROTO(struct sk_buff *skb, void *location),
skb.h-
skb.h-  TP_ARGS(skb, location),
skb.h-
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26882923

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档