Think Different

这篇内容是对那些与众不同、敢于挑战常规、勇于打破现状的人们的致敬。这些被视为疯狂的人实际上往往是社会进步的重要推动力,他们用自己的行动证明了改变世界的可能性。

向那些疯狂的家伙们致敬。
那些我行我素的家伙。
那些桀骜不驯的家伙。
那些惹事生非的家伙。
那些方孔中的圆桩。
他们总是异想天开,
既不喜欢循规蹈矩,
也不尊重既成事实。
你尽可以赞美他们,否定他们,引用他们,
质疑他们,颂扬抑或是诋毁他们。
不过惟独不能漠视他们。
因为他们进行着变革。
他们推动着人类的进程。
他们是别人眼里的疯子,
却是我们眼中的天才。
因为,只有疯狂到认为
自己能够改变世界的人,
才能真正做到这一点。

Here’s to the crazy ones.
The misfits.
The rebels.
The troublemakers.
The round pegs in the square holes.
The ones who see things differently.
They’re not fond of rules.
And they have no respect for the status quo.
You can quote them, disagree with them, glorify or vilify them.
About the only thing you can’t do is ignore them.
Because they change things.
They push the human race forward.
And while some see them as the crazy ones,
We see genius.
Because the people who are crazy enough to think
they can change the world,
Are the ones who do.

5. Event filtering ================== Trace events can be filtered in the kernel by associating boolean 'filter expressions' with them. As soon as an event is logged into the trace buffer, its fields are checked against the filter expression associated with that event type. An event with field values that 'match' the filter will appear in the trace output, and an event whose values don't match will be discarded. An event with no filter associated with it matches everything, and is the default when no filter has been set for an event. 5.1 Expression syntax --------------------- A filter expression consists of one or more 'predicates' that can be combined using the logical operators '&&' and '||'. A predicate is simply a clause that compares the value of a field contained within a logged event with a constant value and returns either 0 or 1 depending on whether the field value matched (1) or didn't match (0): field-name relational-operator value Parentheses can be used to provide arbitrary logical groupings and double-quotes can be used to prevent the shell from interpreting operators as shell metacharacters. The field-names available for use in filters can be found in the 'format' files for trace events (see section 4). The relational-operators depend on the type of the field being tested: The operators available for numeric fields are: ==, !=, <, <=, >, >=, & And for string fields they are: ==, !=, ~ The glob (~) accepts a wild card character (*,?) and character classes ([). For example: prev_comm ~ "*sh" prev_comm ~ "sh*" prev_comm ~ "*sh*" prev_comm ~ "ba*sh" 5.2 Setting filters ------------------- A filter for an individual event is set by writing a filter expression to the 'filter' file for the given event. For example: # cd /sys/kernel/debug/tracing/events/sched/sched_wakeup # echo "common_preempt_count > 4" > filter A slightly more involved example: # cd /sys/kernel/debug/tracing/events/signal/signal_generate # echo "((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter If there is an error in the expression, you'll get an 'Invalid argument' error when setting it, and the erroneous string along with an error message can be seen by looking at the filter e.g.: # cd /sys/kernel/debug/tracing/events/signal/signal_generate # echo "((sig >= 10 && sig < 15) || dsig == 17) && comm != bash" > filter -bash: echo: write error: Invalid argument # cat filter ((sig >= 10 && sig < 15) || dsig == 17) && comm != bash ^ parse_error: Field not found Currently the caret ('^') for an error always appears at the beginning of the filter string; the error message should still be useful though even without more accurate position info. 5.3 Clearing filters -------------------- To clear the filter for an event, write a '0' to the event's filter file. To clear the filters for all events in a subsystem, write a '0' to the subsystem's filter file. 5.3 Subsystem filters --------------------- For convenience, filters for every event in a subsystem can be set or cleared as a group by writing a filter expression into the filter file at the root of the subsystem. Note however, that if a filter for any event within the subsystem lacks a field specified in the subsystem filter, or if the filter can't be applied for any other reason, the filter for that event will retain its previous setting. This can result in an unintended mixture of filters which could lead to confusing (to the user who might think different filters are in effect) trace output. Only filters that reference just the common fields can be guaranteed to propagate successfully to all events. Here are a few subsystem filter examples that also illustrate the above points: Clear the filters on all events in the sched subsystem: # cd /sys/kernel/debug/tracing/events/sched # echo 0 > filter # cat sched_switch/filter none # cat sched_wakeup/filter none Set a filter using only common fields for all events in the sched subsystem (all events end up with the same filter): # cd /sys/kernel/debug/tracing/events/sched # echo common_pid == 0 > filter # cat sched_switch/filter common_pid == 0 # cat sched_wakeup/filter common_pid == 0 Attempt to set a filter using a non-common field for all events in the sched subsystem (all events but those that have a prev_pid field retain their old filters): # cd /sys/kernel/debug/tracing/events/sched # echo prev_pid == 0 > filter # cat sched_switch/filter prev_pid == 0 # cat sched_wakeup/filter common_pid == 0 5.4 PID filtering ----------------- The set_event_pid file in the same directory as the top events directory exists, will filter all events from tracing any task that does not have the PID listed in the set_event_pid file. # cd /sys/kernel/debug/tracing # echo $$ > set_event_pid # echo 1 > events/enabled Will only trace events for the current task. To add more PIDs without losing the PIDs already included, use '>>'. # echo 123 244 1 >> set_event_pid全部翻译
最新发布
07-23
### 5. 事件过滤 内核可以通过为事件关联布尔型"过滤表达式"来实现事件过滤。当一个事件被记录到跟踪缓冲区时,其字段值会与该事件类型关联的过滤表达式进行比对。字段值"匹配"过滤条件的事件将出现在跟踪输出中,不匹配的事件则会被丢弃。未设置过滤器的事件默认匹配所有情况。 #### 5.1 表达式语法 过滤表达式由一个或多个"谓词"组成,可通过逻辑运算符'&&'(与)和'||'(或)进行组合。谓词是通过关系运算符将事件字段值与常量进行比较的子句: ``` 字段名 关系运算符 值 ``` 可用括号进行逻辑分组,使用双引号可防止shell将运算符解释为元字符。可用字段名可在事件的'format'文件中查询(见第4节)。 关系运算符根据字段类型有所不同: - 数值字段支持:==、!=、<、<=、>、>=、& - 字符串字段支持:==、!=、~(通配符匹配) 通配符~支持使用*和?进行匹配,以及字符类[]。例如: ``` prev_comm ~ "*sh" // 匹配以sh结尾的字符串 prev_comm ~ "sh*" // 匹配以sh开头的字符串 prev_comm ~ "*sh*" // 匹配包含sh的字符串 prev_comm ~ "ba*sh" // 匹配ba开头sh结尾的字符串 ``` #### 5.2 设置过滤器 通过向事件的'filter'文件写入表达式来设置过滤器: ```bash # 设置简单过滤器 cd /sys/kernel/debug/tracing/events/sched/sched_wakeup echo "common_preempt_count > 4" > filter # 设置复合过滤器 cd /sys/kernel/debug/tracing/events/signal/signal_generate echo "((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter ``` 若表达式存在错误,设置时会返回"Invalid argument"错误,可通过查看filter文件获取具体错误信息: ```bash # 错误示例 echo "((sig >= 10 && sig < 15) || dsig == 17) && comm != bash" > filter cat filter # 输出显示错误位置和原因 ((sig >= 10 && sig < 15) || dsig == 17) && comm != bash ^ parse_error: Field not found ``` #### 5.3 清除过滤器 - 清除单个事件过滤器: ```bash echo 0 > filter ``` - 清除整个子系统的事件过滤器: ```bash cd /sys/kernel/debug/tracing/events/sched echo 0 > filter ``` #### 5.4 子系统过滤器 可在子系统根目录批量设置过滤器,但需注意: 1. 若子系统内某事件不包含过滤器指定的字段,该事件将保留原过滤器 2. 只有使用通用字段(common_前缀)的过滤器能确保作用于所有事件 操作示例: ```bash # 清空调度子系统所有过滤器 cd /sys/kernel/debug/tracing/events/sched echo 0 > filter # 设置通用字段过滤器(对所有事件生效) echo "common_pid == 0" > filter # 尝试设置非通用字段过滤器(仅对部分事件生效) echo "prev_pid == 0" > filter ``` #### 5.5 PID过滤 通过set_event_pid文件可限定只跟踪特定进程: ```bash # 仅跟踪当前shell进程 cd /sys/kernel/debug/tracing echo $$ > set_event_pid echo 1 > events/enabled # 追加跟踪其他进程(不覆盖现有PID) echo 123 244 1 >> set_event_pid ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值