In the first article we defined a pattern log configuration to read and extract given log data. As a result the reader was able to read the text and create signals with text information inside. Now assume that we have numerical data in this log to be extracted. The numerical shall be displayed as a line diagram.
The part of the log data we need to look at is this:
NOTE00000[216 735 876.000 ns] in top.F4.generics : Calculated load 47%
So far we just extracted the text behind the first ':' character (Calculated load 47%).
There are 3 ways to extract this numerical data with impulse:
A simple pattern could look like this:
NOTE[\s0]*\[([ 0-9a-z\.]+)\] in top.F4.generics : Calculated load ([0-9]+).*
Create a new log pattern and select "Timestamp" for group 1. Select "Float value" and "Parse unit from value" for the field "Domain unit".
For the value group, typing in the label "Value" and select "Integer" as its type. This tells the log reader to use an integer member and to convert the value, instead of raw text.
Select "Explicit name" and type 'Load' in field "Name". The pattern will create a signal with the name 'Load'.
Please be reminded that additional patterns mean additional processing time for reading. Also it is important to put the pattern before the default pattern. Otherwise it would not hit !
A view combines a set of plots organized in rows. You may switch between multiple views using the the combo box in the top right corner.
You can use an unlimited number of views for a record file. The upper-right button in the toolbar is used to switch between multiple views.
The signal area is used to find signals in the record (wave, trace, log,..) file and convert them into a plot that can be shown in the Plot Area.
Inside of a view you find Plots to display the signal data and Folders to organize the presentation in a hierarchical structure. This enables the user to hide/show parts of the presentation.
The parsed values is now a separate integer member of your log samples (a signal of type "Struct").
To display the data in a line diagram, you need to extract the member "Value" from the sample. This is done by using the "Member Extract" production.
Create a new Plot, select the signal "Load" as source and "Member Extract" as production. Select the member "Value" and switch to Line diagram.
This approach is more flexible and can be assigned to any kind of data. But it requires some java script code!
Signal scripts allow you to combine signals with mathematical operations, implement protocol parsers, compare signals, extract statistical information or automatically detect problems.
Signal scripts can analyse existing signals and always create one new resulting signals. This is what we do now with signal "#generics".
To create a signal script, get to your viewer and add a new plot. Set production to "Signal Script", signal type to "Float" and enter the script below.
Finally set "#generics" as primary source
The script iterates over all samples. When the sample is not none, it reads the member value of the member "Message".
After checking if the text is correct, it extracts the value and converts to in. Then it writes the float value into the signal.
Signal scripts are evaluated as soon the viewer wants to display a signal. If required you can iterate over multiple signals. "in0" is the primary source, in1..n are additional sources. Both can be configured in the plot dialogue. For debugging purpose, you might use the console object to output debug text.
As the final step, set type to Line.
// in0 : Primary input (de.toem.impulse.samples.ISamplePointer,de.toem.impulse.samples.IReadableSamples) // in1.. : Additional inputs (de.toem.impulse.samples.ISamplePointer,de.toem.impulse.samples.IReadableSamples) // input: : An array of all inputs // out : Output signal writer (? extends de.toem.impulse.samples.ISamplesWriter) // iter : Sample iterator (de.toem.impulse.samples.ISamplesIterator) // progress : Progress control (de.toem.impulse.samples.producer.IScriptProgress) // console : Console output (de.toem.impulse.scripting.IScriptConsole) var Float = Java.type("java.lang.Float"); while (iter.hasNext()) { var current = iter.next(out); if (!in0.isNone()) { var message /*:java.lang.String:*/ = in0.stringValueOf('Message'); if (message != null && message.startsWith('Calculated load')) { var val = Float.parseFloat(message.substring(15, 18)); console.log("found", current, val) out.write(current, false, val); } } } progress.cont(); // Indicates that the script can be re-called if the input signals grow
The "Value Extract" production filters all non-relevant samples and extract textual information from the relevant ones. This information is converted into a given output signal type.
Create a new plot, change the production to "Text Extract", select "Float" signal type and type in the member name ('Message').
Finally define the extract definition. The extract definition may be either a text fragment or a regular expression.
If text fragment is chosen, the production will try to find the text in the value representation and extracts the following text fragment surrounded by white-spaces.
Example: Sample value = "nx=400 mx=500"; if extract is set to "nx=", the value 400 will be extracted.
If a regular expression is given, the production will try to find a match in the value representation and extracts the 1st group value.
Example: Sample value = "nx=400 mx=500"; if extract is set to "mx\=([0-9]+)", the value 500 will be extracted.
In our case, the extract definition is:
Calculated load ([0-9]*)