📄 x-event2.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title> Event-Base API </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="x-event.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="x-event.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="x-event1.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="x-event3.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="86892">D.2 C++ API</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="86893"> </a>In order to maximize the power of the API, it is written in C++ and exports a number of classes to the client. These classes represent the event base, the event contexts (task contexts, interrupt contexts, and the idle context), and the individual events. These classes are called <b class="symbol_lc">WVEventBase</b>, <b class="symbol_lc">WVContext</b>, and <b class="symbol_lc">WVEvent</b> respectively, and are defined in <i class="textVariable">installDir</i><b class="file">/host/include/wvapi.h</b>.</p><dd><p class="Body"><a name="83764"> </a>There is also a class that acts as a cursor, which points into the event base and can be moved around to search for events of specific kinds, in one context or in any. This class is called <b class="symbol_lc">WVCoords</b> and is defined in <b class="file">wvapi.h</b>.</p><dd><p class="Body"><a name="83777"> </a>In keeping with the latest C++ Standards, these public classes are implemented as containers similar to STL containers. They provide iterator classes which allow searching and extraction of sub-ranges using Standard Library algorithms.</p><dd><p class="Body"><a name="83782"> </a>The API ships as a dynamically-linked shared library and functions as a Tcl extension package that can be loaded into <b class="command">tclsh</b> or <b class="command">wish</b> at runtime with the load command.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="83707">WVEventBase Class</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83708"> </a>To instantiate an object representing a complete event log, an object of class <b class="symbol_lc">WVEventBase</b> is created. Its constructor requires the name of the event-log file, usually ending in a <b class="file">.wvr</b> suffix. If the file cannot be opened, is not in the required format, or some error occurs while building the in-memory data structures, a <b class="symbol_lc">wv_error</b> exception is thrown. </p><dd><p class="Body"><a name="83802"> </a>The <b class="symbol_lc">WVEventBase</b> class exposes the following useful public member functions: </p></dl><dl class="margin"><dd><pre class="Code"><b><a name="83805">WVEventBase(Tcl_Interp *pTcl=0); </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85164"> </a>takes an optional Tcl interpreter and constructs an empty event base. If no Tcl interpreter is supplied, one is created.</div><br></dl></dl><dd><pre class="Code"><b><a name="83808">STATUS load(const char *fileName); </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85171"> </a>attempts to load an event-log file or files into the event base. The routine returns <b class="symbol_UC">OK</b> or <b class="symbol_UC">ERROR</b> and may throw <b class="symbol_lc">wv_error</b> exceptions if underlying file-system errors occur.</div><br></dl></dl><dd><pre class="Code"><b><a name="83812">UINT32 size() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85174"> </a>returns the number of contexts in the event base.</div><br></dl></dl><dd><pre class="Code"><b><a name="87175">WVContext operator[](unsigned index) const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="87176"> </a>returns a <b class="symbol_lc">WVContext</b> object from the index position in the event-base sequence of contexts.</div><br></dl></dl><dd><pre class="Code"><b><a name="83817">const_iterator begin() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85176"> </a>returns a <b class="symbol_lc">WVEventBase::const_iterator</b> representing the start of the sequence.</div><br></dl></dl><dd><pre class="Code"><b><a name="83820">const_iterator end() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85177"> </a>returns a <b class="symbol_lc">WVEventBase::const_iterator</b> representing the first position past the end of the sequence.</div><br></dl></dl><dd><pre class="Code"><b><a name="83823">string name() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85182"> </a>returns the name of the event base.</div><br></dl></dl><dd><pre class="Code"><b><a name="83825">int cpuId() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85183"> </a>returns the processor ID of the event base.</div><br></dl></dl><dd><pre class="Code"><b><a name="83834">string eventName(const WVEvent& ev) const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85184"> </a>returns the name of the event <b class="symbol_lc">ev</b> in human-readable format. This name is gathered from the event-description file loaded when the parser is loaded.</div><br></dl></dl><dd><pre class="Code"><b><a name="83839">WVContext contextFromUniqueId(int uid) const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85187"> </a>returns a <b class="symbol_lc">WVContext</b> object that corresponds to the unique ID given as the argument.</div><br></dl></dl><dd><pre class="Code"><b><a name="83842">WV_TIME startTime() const; WV_TIME endTime() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85189"> </a>return the first and last timestamps of the events contained within the event base.</div><br></dl></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="87023">WVContext Class</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="87024"> </a>This section details the public member functions of the <b class="symbol_lc">WVContext</b> class, which represents a single context (task, interrupt, or idle) within the instrumented target. Internally, it is composed of a simple reference into the private internal data structures which takes up very little real application memory. Thus, it is safe for the application to build lists or vectors of these objects, for whatever reason.</p><dd><p class="Body"><a name="83850"> </a>The class also exposes an iterator type. It represents positions inside the context, viewing the context as a sequence of events and allowing application of STL standard algorithms to perform binary searches and other functions. </p><dd><p class="Body"><a name="83854"> </a>The public member functions of the <b class="symbol_lc">WVContext</b> class are:</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="83856">UINT32 size() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85205"> </a>returns the size of the context when viewed as a sequence of events, in other words, the number of events in the sequence.</div><br></dl></dl><dd><pre class="Code"><b><a name="83859">int uniqueId() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85209"> </a>returns a unique integer which distinguishes this context from all others within the same event base, including those that may have the same <b class="symbol_lc">taskID</b><b>( )</b> or <b class="symbol_lc">name</b><b>( )</b> values.</div><br></dl></dl><dd><pre class="Code"><b><a name="83861">VX_ID taskId() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85216"> </a>returns the target-specific task ID, which may not be unique because task IDs can be reused by VxWorks. To uniquely identify a task within the event base, use the <b class="symbol_lc">uniqueID</b><b>( )</b> method to get a unique integer value. </div><br></dl></dl><dd><pre class="Code"><b><a name="83864">string name() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85221"> </a>returns the task name (for example, <b class="task">tMainTask</b>).</div><br></dl></dl><dd><pre class="Code"><b><a name="83866">int priority() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85224"> </a>returns the task priority.</div><br></dl></dl><dd><pre class="Code"><b><a name="83868">iterator begin() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85225"> </a>returns a <b class="symbol_lc">WVContext::iterator</b> representing the start of the sequence.</div><br></dl></dl><dd><pre class="Code"><b><a name="83870">iterator end() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85226"> </a>returns a <b class="symbol_lc">WVContext::iterator</b> representing the first position past the end of the sequence.</div><br></dl></dl><dd><pre class="Code"><b><a name="83873">BOOL isInterrupt() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85268"> </a>tests whether this is an interrupt context (as opposed to a task context).</div><br></dl></dl><dd><pre class="Code"><b><a name="85269">BOOL isIdle() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85270"> </a>tests whether this is the idle context.</div><br></dl></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="83711">WVEvent Class</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83712"> </a>This section details the public member functions and public data members of the class <b class="symbol_lc">WVEvent</b>, which represents a single event from the event base. When you create an object of this class, it retrieves the real event data from the private event-base data structures within the API library and stores them in the private data members of the <b class="symbol_lc">WVEvent</b> object. You then access this data using public member functions.</p><dd><p class="Body"><a name="84133"> </a>Do not create too many <b class="symbol_lc">WVEvent</b> objects at once when dealing with a large event log, because each object takes up some small but significant amount of application memory when created. Instead, create events one at a time within a loop, by iterating over a <b class="symbol_lc">WVContext</b> with an <b class="symbol_lc">WVContext::iterator</b> object and dereferencing the iterator each time, as shown by the following example:</p><dl class="margin"><dd><pre class="Code2"><b><a name="84138">WVContext::iterator i; for (i = ctxt.begin(); i != ctxt.end(); i++) { WVEvent e = *i; // do something useful with e like look at its time, its // parameters, etc... }</a></b></pre></dl><dd><p class="Body"><a name="84148"> </a>The following public member-functions are available from the class:</p></dl><dl class="margin"><dd><pre class="Code"><b><a name="83881">string name() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85505"> </a>returns a C++ SL string object containing the event name (for example, <b class="symbol_lc">semTake</b>). </div><br></dl></dl><dd><pre class="Code"><b><a name="83884">UINT32 type() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85290"> </a>returns the event-type code as an integer number (for example, 10015).</div><br></dl></dl><dd><pre class="Code"><b><a name="83886">WV_TIME timeStamp() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85291"> </a>returns the timestamp of the event in standard WindView format.</div><br></dl></dl><dd><pre class="Code"><b><a name="83888">int numParams() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85293"> </a>returns the number of parameters to the event.</div><br></dl></dl><dd><pre class="Code"><b><a name="83890">UINT32 param(int index) const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85294"> </a>returns the <i class="textVariable">index</i>th parameter of the event. The order, type, and meanings of the event parameters can be found in the event dictionary (see <a href="x-evtdic.html#121129"><i class="title">B. Event Dictionary</i></a>).</div><br></dl></dl><dd><pre class="Code"><b><a name="83893">bool isStateChange() const; </a></b></pre><dl class="margin"><dl class="margin"><dd><div class="Indent2"><a name="85295"> </a>indicates whether a particular event was a state-change event.</div><br></dl></dl><dd><pre class="Code"><b><a name="83895">UINT32 state() const; </a></b></pre><dl class="margin"><dl class="margin">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -