📄 c-trigger3.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title> Triggering </title></head><body bgcolor="FFFFFF"><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="c-trigger.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-trigger.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-trigger2.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-datacol.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p><font face="Helvetica, sans-serif" class="sans"><h3 class="H2"><i><a name="84774">6.3 Using Triggers</a></i></h3></font><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84356">Using a Trigger to Start Log Collection</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84357"> </a>The main challenge in defining a trigger to start data collection is isolating an event which precedes the sequence of interest but is as close to the start of the sequence as possible. Examining your application code or collecting a broad log which incorporates the sequence of interest may allow you to identify unique events preceding that sequence that may be used as potential trigger points. </p><dd><p class="Body"><a name="84358"> </a>For instance, you may observe that, shortly before the sequence of interest, a semaphore is given. It may be possible to identify the task context from which the <b class="routine"><i class="routine">semGive</i></b><b>( )</b> is performed and possibly the ID of the semaphore being given. These criteria can be used to define when the trigger which initiates logging fires.</p><dd><p class="Body"><a name="84359"> </a>However, this may not be sufficient to uniquely detect the start of the region of interest if this task takes and gives the same semaphore more than once. In this case it will be necessary to further refine the trigger by using a conditional qualification. This may be achieved by examining some variable (by symbol or address) for a specific value or range of values or by invoking a specific function and testing the result.</p><dd><p class="Body"><a name="84360"> </a>Note that it is possible to use functions written specifically for this purpose, by making the function available on the target and entering its function name as the condition item. (For a simple example, see <a href="c-trigger3.html#85867">Example 6-1</a>.) These functions can also further assist in diagnosis by collecting data such as the value of the system tick count when the trigger fired or some internal value of the target application.</p><dd><p class="Body"><a name="84364"> </a>Once you have determined when the trigger will fire, set the action of the trigger to <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Start WV</font></b> (start WindView logging). Calling <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">StartWV</font></b> more than once results in an error, so it is important to disable the trigger that starts logging after it fires. Defining a trigger which references WindView in this way will invoke the WindView tool and request its configuration if this has not already been done.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84365">Using a Trigger to Stop Log Collection</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84366"> </a>Although not required, it is often desirable to define a trigger to stop log collection. This focuses the log on the sequence of interest and saves both resources and analysis effort. </p><dd><p class="Body"><a name="84367"> </a>Approach defining a trigger to stop log collection in the same way you defined the trigger to start collection: identify an event that will not occur until the sequence of interest has completed. One technique is to write a function that fires after a specified time period, for instance, by comparing the value of the system tick count against its value when the trigger to start the sequence fired.</p><dd><p class="Body"><a name="86857"> </a>Once you have defined when the trigger will fire, set the action of the trigger to <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">StopWV</font></b> (stop WindView logging). If you chain this trigger to the trigger that starts logging, you can ensure that this trigger can not fire before the log collection has been started. </p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="86859">Triggering Examples </a></i></h4></font><dl class="margin"><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="84712">Downloading Trigger Definitions </a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="85871"> </a><a href="c-trigger3.html#85867">Example 6-1</a> and <a href="c-trigger3.html#84820">Example 6-2</a> demonstrate loading and running saved trigger configurations. </p></dl></dl><h4 class="EntityTitle"><a name="85867"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 6-1: Simple Conditional Trigger</font></a></h4><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84826"> </a>To run the trigger you loaded from the file <b class="file">simpleCond.trg</b> (see <a href="c-trigger2.html#84542"><i class="title">Loading a Trigger Configuration File</i></a>), you must download it. However, before downloading the <b class="symbol_lc">simpleCond</b> trigger, you need to prepare your target. The triggering implementation requires that all the variables and functions referred to in the trigger definition be declared before triggering is started. </p><dd><p class="Body"><a name="84899"> </a>Start WindSh and create the variables <b class="symbol_lc">foo</b> and <b class="symbol_lc">helloString</b> as follows:</p><dl class="margin"><dd><pre class="Code2"><b><a name="84827"></b><tt class="output">-></tt><b> foo=0 </b><tt class="output">new symbol "foo" added to symbol table. foo = 0x125980: value = 0 = 0x0 -></tt><b> helloString="hello\n" </b><tt class="output">new symbol </tt><b>"</b><tt class="output">helloString</tt><b>"</b><tt class="output"> added to symbol table. helloString = 0x125970: value = 1202552 = 0x125978 = helloString + 0x8</tt><b></a></b></pre></dl><dd><p class="Body"><a name="84831"> </a>Before downloading your trigger, open the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Trigger Maintenance</font></b> dialog box and look again at the definition. Note that the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Safe</font></b> box must be checked since a call to <b class="routine"><i class="routine">printf</i></b><b>( )</b> is not allowed in ISR or system context. See <a href="c-trigger3.html#85707">Figure 6-4</a>. <div class="frame"><h4 class="EntityTitle"><a name="85707"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 6-4: Simple Conditional Trigger</font></a></h4><dl class="margin"><div class="Anchor"><a name="85709"> </a><img class="figure" border="0" src="images/c-trigger29.gif"></div></dl></div></p><dd><p class="Body"><a name="85698"> </a>Click the <img class="figure" border="0" src="images/c-trigger8.gif"> button. This compiles and downloads your trigger. The <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Target ID</font></b> changes from "not set" to a hexadecimal ID number and the status is "Armed." (See <a href="c-trigger2.html#84502">Figure 6-3</a>). To fire your trigger, the condition for <b class="symbol_lc">foo</b> must be met. Enter the following in WindSh:</p><dl class="margin"><dd><pre class="Code2"><b><a name="84835"></b><tt class="output">-></tt><b> foo = 1 </b><tt class="output">foo = 0x125980: value = 1 = 0x1</tt><b></a></b></pre></dl><dd><p class="Body"><a name="84821"> </a>The string "hello" prints on the target console (or wherever you are directing target output). Click the <img class="figure" border="0" src="images/c-trigger9.gif"> button. The trigger status is updated to show that it has fired.</p><dd><p class="Body"><a name="85693"> </a>It is important to note that the following is not valid:<img class="figure" border="0" src="images/c-triggerb7.gif"></p><dd><p class="Body"><a name="87630"> </a>This is because the action function is expecting an integer argument, whereas "hello\n" is a string.</p></dl></dl><h4 class="EntityTitle"><a name="84820"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 6-2: Chaining Triggers</font></a></h4><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84721"> </a>To see a simple example of chained triggers, click <img class="figure" border="0" src="images/c-trigger11.gif"> and load the configuration file <i class="textVariable">installDir</i><b class="file">/host/src/windview/samples/wv10secs.trg</b>. These chained triggers start and stop WindView. If you have not already configured WindView, the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Collection Configuration</font></b> dialog box opens; configure WindView so it is ready to start when the first trigger fires. If you wish, click <img class="figure" border="0" src="images/c-trigger12.gif"> and review the specifications for triggers #0 and #1. Trigger #0 starts WindView logging when <b class="symbol_lc">vxTicks</b> is greater than 0x1800. Trigger #1 stops WindView logging when <b class="symbol_lc">vxTicks</b> is greater than 0x1a58. </p></dl></dl><dl class="margin"><dd><p class="table" callout><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td valign="top" width="40"><br><img border="0" alt="*" src="icons/note.gif"></td><td><hr><div class="CalloutCell"><a name="87484"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">NOTE: </font></b></a><b class="symbol_lc">vxTicks</b> is a global variable that counts ticks. Use the shell to find its current value and reset the values in the<b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans"> Trigger Maintenance</font></b> dialog box to be greater than the current value. Otherwise, one or both triggers will fire immediately and the log you collect will be almost empty.</div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout><dl class="margin"><dd><p class="Body"><a name="85868"> </a>Click <img class="figure" border="0" src="images/c-trigger13.gif"> to download the triggers. Click the <img class="figure" border="0" src="images/c-trigger14.gif"> button until the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Triggering</font></b> window shows that both triggers have fired. Click <img class="figure" border="0" src="images/c-trigger20.gif"> to stop triggering. If you have WindView configured for deferred upload mode, the <b class="guiLabel"><font face="Helvetica, sans-serif" size="-1" class="sans">Control</font></b> window shows that there is data in the buffer and the <img class="figure" border="0" src="images/c-trigger23.gif"> button is active. If you have WindView configured for continuous upload mode, there is a new view graph displayed. </p></dl></dl><dl class="margin"><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="87506">Evaluating Conditions </a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="85878"> </a><a href="c-trigger3.html#88687">Example 6-3</a>, <a href="c-trigger3.html#88663">Example 6-4</a>, and <a href="c-trigger3.html#88634">Example 6-5</a> demonstrate how conditional triggers are evaluated and highlight issues in creating conditional triggers. Because <b class="symbol_lc"><operand2></b> is interpreted as a numeric constant, you may generate unexpected results by entering a symbol in this box. </p><dd><p class="Body"><a name="85829"> </a>Suppose we have the following identifiers in the symbol table:<p class="table"><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="85812"> </a><b class="symbol_lc">foo1</b> </p></td><td width="10"> </td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="85814"> </a> address = 0x0a001000 </p></td><td width="10"> </td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="85816"> </a> value = 30</p></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="85818"> </a><b class="symbol_lc">foo2</b> </p></td><td width="10"> </td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="85820"> </a> address = 0x0a001004 </p></td><td width="10"> </td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="85822"> </a> value = 20</p></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="85824"> </a><b class="symbol_lc">pFoo</b> </p></td><td width="10"> </td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="85826"> </a> address = 0x0a001008 </p></td><td width="10"> </td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="85828"> </a> value = 0x0a001000</p></td><td width="10"> </td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p></p><dd><p class="Body"><a name="88684"> </a><div class="frame"><h4 class="EntityTitle"><a name="88687"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 6-3: Evaluating a Conditional Using a Numeric Value</font></a></h4><dl class="margin"><div class="Anchor"><a name="88689"> </a><img class="figure" border="0" src="images/c-triggera37.gif"></div></dl></div></p><dd><p class="Body"><a name="87633"> </a>Specifying the conditional as shown causes the value of the variable <b class="symbol_lc">foo1</b> to be compared with the constant 0x20. In this case, the trigger condition is not satisfied since the value of <b class="symbol_lc">foo1</b> (30 decimal) is less than 0x20. This result is expected. <div class="frame"><h4 class="EntityTitle"><a name="88663"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 6-4: Evaluating a Conditional Using a String </font></a></h4><dl class="margin">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -