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 WVEventBase, WVContext, and WVEvent respectively, and are defined in installDir/host/include/wvapi.h.
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 WVCoords and is defined in wvapi.h.
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.
The API ships as a dynamically-linked shared library and functions as a Tcl extension package that can be loaded into tclsh or wish at runtime with the load command.
To instantiate an object representing a complete event log, an object of class WVEventBase is created. Its constructor requires the name of the event-log file, usually ending in a .wvr 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 wv_error exception is thrown.
The WVEventBase class exposes the following useful public member functions:
WVEventBase(Tcl_Interp *pTcl=0);
STATUS load(const char *fileName);
UINT32 size() const;
WVContext operator[](unsigned index) const;
const_iterator begin() const;
const_iterator end() const;
string name() const;
int cpuId() const;
string eventName(const WVEvent& ev) const;
WVContext contextFromUniqueId(int uid) const;
WV_TIME startTime() const; WV_TIME endTime() const;
This section details the public member functions of the WVContext 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.
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.
UINT32 size() const;
int uniqueId() const;
VX_ID taskId() const;
string name() const;
int priority() const;
iterator begin() const;
iterator end() const;
BOOL isInterrupt() const;
BOOL isIdle() const;
This section details the public member functions and public data members of the class WVEvent, 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 WVEvent object. You then access this data using public member functions.
Do not create too many WVEvent 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 WVContext with an WVContext::iterator object and dereferencing the iterator each time, as shown by the following example:
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... }
The following public member-functions are available from the class:
string name() const;
UINT32 type() const;
WV_TIME timeStamp() const;
int numParams() const;
UINT32 param(int index) const;
bool isStateChange() const;
UINT32 state() const;
|
NOTE: The WVEventBase class manages memory internally using a temporary file to provide a form of virtual memory, allowing WindView to load very large event base files without requiring very large amounts of physical memory. Copying data into non-WindView data structures incurs the memory usage that WVEventBase avoids.
|
||||||||||||||||||
This class provides a simple way of traversing the event base and limiting or filtering the events displayed in various ways. Given an existing WVEventBase object, a WVCoords object can be created to look at events inside the event base, applying various restrictions. These restrictions include the type of event to look at, which can be any event or a specific type, and the context to search, which can be any context or a specific one.
The public member function move( ) and the operators ++ and -- move the WVCoords object through the event base. They return a boolean value indicating whether the movement was made or not. If not, no more events meeting the current search criteria could be found. The WVCoords object can be dereferenced using the operator *( ) and results in a WVContext::iterator, which can itself be dereferenced to retrieve an actual WVEvent object.
The following public member functions are available from the class:
WVCoords();
WVCoords(const WVEventBase*, WV_TIME, const WVContext&, EVENT_TYPE);
WVCoords(const WVEventBase*, const WVContext::iterator&);
BOOL move(int direction);
static WVContext anyContext();
static EVENT_TYPE anyEvent();
const WVEventBase& eventBase() const;
WVContext::iterator operator*() const;
BOOL operator++(int);
BOOL operator--(int);
void contextLock(BOOL);
void eventTypeLock(BOOL);
void eventTypeSet(EVENT_TYPE);
void contextSet(const WVContext&);
void timeSet(WV_TIME);
string contextName() const;
Table D-1 shows the compiler that can be used with the C++ API library on each host. The API library can only be expected to work with other applications if compiled with these toolchains.
|
|||||||||||||||||||
|
|||||||||||||||||||
|
|||||||||||||||||||
In general, the WindView API classes report runtime errors with C++ exceptions. All standard library exceptions, like bad_alloc, are caught internally. The API classes re-throw wv_error exceptions with suitable human-readable messages plus an integer error code. The error-code values are defined in the header installDir/host/include/wvapi.h which ships with the library.