P7 Library
P7 Library
P7 library
P7 library 2
Contents
Introduction .................................................................................................................................................. 4
Directory structure ........................................................................................................................................ 6
Components overview .................................................................................................................................. 7
Channel ..................................................................................................................................................... 7
Sink ............................................................................................................................................................ 7
Performance overview .............................................................................................................................. 7
Client ......................................................................................................................................................... 8
Trace .............................................................................................................................................................. 9
Telemetry ....................................................................................................................................................10
Speed tests ..................................................................................................................................................12
Initialization parameters .............................................................................................................................14
P7 library interfaces ....................................................................................................................................17
Client interface ........................................................................................................................................17
C++ interface .......................................................................................................................................18
C interface ...........................................................................................................................................20
C# interface .........................................................................................................................................22
Python interface ..................................................................................................................................24
Trace interface ........................................................................................................................................25
Configuration.......................................................................................................................................25
Trace verbosity levels ..........................................................................................................................26
Trace format string specification ........................................................................................................26
C++ interface .......................................................................................................................................31
C interface ...........................................................................................................................................37
C# interface .........................................................................................................................................43
Python interface ..................................................................................................................................47
Telemetry interface .................................................................................................................................50
Configuration.......................................................................................................................................50
C++ interface .......................................................................................................................................51
C interface ...........................................................................................................................................54
C# interface .........................................................................................................................................57
Python interface ..................................................................................................................................60
Sharing P7 instances....................................................................................................................................62
Process crush handling ................................................................................................................................63
Compilation .................................................................................................................................................64
Windows example script (Visual studio 2015 x64): ............................................................................64
Linux example script:...........................................................................................................................64
Problems & solutions ..................................................................................................................................65
SIGBUS error............................................................................................................................................65
P7 library 3
Introduction
P7 is cross platform library for handling your needs in delivering & storing your trace/log messages and
telemetry data (CPU, memory, buffers utilization, threads cyclograms, etc.)
Basic facts:
C++/C/C#/Python interfaces are available
Cross platform (Linux x86/x64, Windows x86/x64)
Speed is priority, library is designed to suit high load (for details see speed measurement
chapter), for example average performance for Intel i7-870 is:
o 50 000 traces per second - 0,5% CPU, max ~3.3 million traces per second to network,
~10 million traces per second to file
o 110 000 samples per second - 0,5% CPU, max ~3.8 million per second to network, ~11
million per second to file
Thread safe
Unicode support
o Linux: UTF-8, UTF-32, ANSI characters set
o Windows: UTF-16, ANSI characters set
No external dependencies
High-resolution time stamps (resolution depends on HW high-resolution performance counter,
usually it is 100ns)
Different sinks (transport & storages) are supported:
o Network (Baical server)
o Binary file
o Text file
o Console
o Syslog
o Auto (Baical server if reachable, else – file)
o Null
Files rotation setting (by size or time)
Files max count setting (deleting old files automatically)
Remote management from Baical server (set verbosity per module, enable/disable telemetry
counters)
Providing maximum information for every trace message:
o Format string
o Function name
o File name
o File line number
o Module ID & name (if it was registered)
o Trace ID
o Sequence Number
o Variable arguments
o Level (error, warning, .. etc.)
o Time with 100 nanoseconds granularity
o Current thread ID
o Current thread name (if it was registered)
o Current processor number
Shared memory is used – create your trace and telemetry channels once and access it from any
process module or class without passing handles
Simple way (one function) to flush all P7 buffers for all P7 objects in case of process crush
Trace & telemetry files have binary format (due to speed requirements – binary files much more
compact than raw text), export to text is available
Library is using asynchronous approach, data processed in separate thread(s)
P7 library 5
Library provides a way to handle system signals (seg. fault, access violation, division by 0, etc.)
and save/send remaining buffers to avoid data losses
P7 library 6
Directory structure
Components overview
Sink
Sink is a data destination (module which provides a way of delivering serialized data from channels to
final destination), instantiated once per client.
Library supports next sinks:
Baical – deliver data directly to Baical server using network
Binary file – writes all user data into single binary file
Text file – writes all user data into text file (Windows: UTF-16, Linux: UTF-8)
Console – writes all user data into console
Syslog – writes all user using syslog protocol
Auto – delivers to Baical server if it is reachable otherwise to file
Null – drops all incoming data, save CPU for the hosting process
Performance overview
Library is designed to suit high load and engineers and integrators have to take in account that
performance of different sinks are not equal, next list sorts sinks from most to less performant:
1. Null (~20M)
2. Binary file (~10M)
3. Baical over network (~3.5M)
4. Text file (~0.9M)
5. Syslog (~0.5M)
P7 library 8
6. Console (~0.1M)
Client
Client – is a core module, it aggregates sink & channels together and manage them. Every client object
can handle up to 32 independent channels
Let’s take an example (diagram below) – developed application has to writes 2 independent log (trace)
streams and 1 telemetry stream, and delivers them directly to Baical. Initialization sequence will be:
1. First of all you need to create P7 Client, and specify parameters for sink and destination address:
“/P7.Sink=Baical /P7.Addr=127.0.0.1”
2. Using the client create:
a. create first trace channel with name “Core”
b. create second trace channel named “Module A”
c. create telemetry channel named “CPU, MEM”
P7 Client instance
Channels …
00 01 02 31 Storages
Trace
“Core”
Trace
“Comp. A”
Telemetry
“CPU, MEM”
P7 library 9
Trace
From software engineer point of view trace is a source code line (function with variable arguments list):
It is very similar to logging, but unlike logging - trace gives your much more freedom, you don’t have to
choose which information to write, you may write everything (without impacting on application
performance, 50k traces per second with 0.5% CPU for example, for details see Speed test chapter) and
then during debugging session use flexible filtering engine to find interesting parts, in this case you will
be sure that all necessary information is available for you.
This approach became possible due to P7 performance. Trace module was designed with the idea of
performance, especially on small embedded system.
To be able to send so much information next optimizations are used:
Do not delivers & records duplicated information every time – the most heavy text fields
[Format string, Function name, File name, File line number, Module ID] are delivered & recorded
once - only for first call (the same information will be transmitted once in case of new
connection establishing)
Do not format trace string on client side, variable arguments formatting is a heavy operation
and it will be done on server side by request
Deliver only changes for every subsequent trace call [variable arguments, sequence number,
time with 100ns granularity, current thread, processor core number]
N.B.: The best performance is provided by C++ and C interfaces (release build), C# & Python wrappers
provides less performing solutions.
P7 library 10
Telemetry
From software engineer’s point of view telemetry is a few source code lines:
//deliver info
l_pTelemetry->Add(l_wCpuId, l_dbCPU);
l_pTelemetry->Add(l_wMemId, l_dbMem);
//do something …
}
Telemetry is a simple and fast way to record any dynamically changed values for further or real time
analysis on Baical server side. You may use it for a lot of things: system statistics (cpu, memory, hdd,
etc.), buffers filling, threads cyclograms or synchronization, mutexes, networks delays, packets sizes, etc.
There are plenty of possible usage cases.
Some facts about telemetry:
Every telemetry channel can handle up to 65535 independent counters
No (or minimal) impact on application performance – on modern hardware (2014) spend only
300 ns for processing one telemetry sample (add(...) -> network -> Baical srv -> HDD), it is about
220 000 of samples per second with about 1% CPU usage
P7 library 11
You can enable or disable counters online from Baical server – it allows you visualize and record
only necessary data
Every telemetry sample contains 64 bit double precision floating point value & high resolution
time stamp
N.B.: The best performance is provided by C++ and C interfaces, C# & Python wrappers provides less
performing solutions.
P7 library 12
Speed tests
P7 library was designed with the idea of performance, such approach allows software engineer to
deliver maximum information about program execution in real-time with minimum resources
consumption, and next few tests on different platforms will have to confirm this statement.
Test conditions:
Test application sent traces & telemetry data in cycle & make time measurement
P7 library use next option /P7.Sink=Baical, this means all data goes through network interface to
the Baical server (loopback network interface is used)
Every trace messages contains next fields: format string, function name, file name, file line
number, module ID, variable arguments, sequence number, time with 100ns granularity,
current thread, module ID, processor core number
Every telemetry sample contains next fields: counters ID, sample value, sample time with 100ns
granularity
Baical server will receive & save incoming data
Next screenshot shows delay between 2 trace messages about 200 nanoseconds on modern hardware
(2014):
You may build & run your own speed tests to estimate library performance on your hardware and
compare the performance of printing to the memory buffer, console and P7 trace channel, to do that
you need:
Compile under Linux or Windows project <P7 folder>\Tests\Speed. You can do it by using P7.sln
for visual studio or linux shell script – build.sh
Generated binaries are located in <P7 folder>\Binaries
Run the generated binary (Windows: Speed64.exe/Speed32.exe, Linux: Speed)
P7 library 13
Next diagram shows the test result on Intel i7-870 platform and saving trace messages to file:
P7 library 14
Initialization parameters
/////////////////////////////////////////////////////////////////////////////
//C++
#include "GTypes.h"
#include "P7_Client.h"
int main(int i_iArgC, char* i_pArgV[])
{
IP7_Client *l_pClient = P7_Create_Client(TM("/P7.Sink=Baical"));
//...
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//C
#include "GTypes.h"
#include "P7_Cproxy.h"
int main(int i_iArgC, char* i_pArgV[])
{
hP7_Client *l_pClient = P7_Client_Create(TM("/P7.Sink=Baical"));
//...
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//C#
using P7;
namespace CSharp_Example
{
class Program
{
static void Main(string[] args)
{
/////////////////////////////////////////////////////////////////
//initialize P7 client
P7.Client l_pClient = new P7.Client("/P7.Sink=Baical");
}
}
}
/////////////////////////////////////////////////////////////////////////////
#////////////////////////////////////////////////////////////////////////////
#Python
import P7
P7.Register_Client(P7.UTF(u"MyClient"), P7.UTF(u"/P7.Sink=Baical"))
#////////////////////////////////////////////////////////////////////////////
Or you may pass parameters through command line (if you are using both modes – console parameters
have priority over hardcoded parameters):
o “%ti” – thread ID
o “%tn” – thread name (if it was registered)
o “%cc” – CPU core index
o “%mi” – module ID
o “%mn” – module name
o “%ff” – file name + path
o “%fs” – file name
o “%fl” – file line
o “%fn” – function name
o “%ms” – text user message
Example: “/P7.Format=\"{%cn} [%tf] %lv %ms\"”
“/P7.Facility” – set Syslog facility, for details: https://tools.ietf.org/html/rfc3164#page-8
P7 library interfaces
Client interface
Client is a core module of P7 library, working with the library start form client creation. Client is
responsible for delivering your traces & telemetry data into final destination.
Every client object can handle up to 32 independent channels.
Number of clients per process is limited by available memory.
P7 library 18
C++ interface
Client header file is located in <P7>/Headers/P7_Client.h
P7_Create_Client
Function allows to create P7 client object
P7_Get_Shared
This functions allows you to get P7 client instance if it was created by someone else inside current
process and shared using IP7_Client::Share(…) function.
Sharing mechanism is very flexible way to redistribute your IP7_Client object among your modules
without passing pointer to it and modification your interfaces, function is thread safe.
N.B.: Every successful call of this function increase reference counter value on retrieved IP7_Client
object, do not forget to call Release() function
P7_Set_Crash_Handler
This function setup crash handler to catch and process exceptions like (access violation/segmentation
fault, division by zero, pure virtual call, etc.). When crash occurs the handler will call
P7_Exceptional_Flush function automatically, such procedure allows to flush all internal buffers to
file/socket right before process exits.
void P7_Set_Crash_Handler()
P7_Exceptional_Flush
If user wants to handle crash manually – this function HAS TO BE CALLED from user handler.
Function allows flushing (deliver) not delivered/saved P7 buffers for all opened P7 clients and related
channels owned by process in CASE OF your app/proc. crush. This function does not call system
memory allocation functions only write to file/socket.
Classical scenario: your application has been crushed you catch the moment of crush and call this
function once.
To read more about this function & usage scenario you may in chapter Process crush handling
P7 library 19
void P7_Exceptional_Flush()
P7_Flush
Call this function if you want to flush manually time to time buffers to disk/network/console.
It will found all sinks in current process and call flush on each of them
void P7_Flush()
IP7_Client::Add_Ref
Function increase object reference counter
tINT32 Add_Ref()
IP7_Client::Release
Function decrease object reference counter, object will be destroyed when reference counter is equal to
0.
tINT32 Release()
IP7_Client::Share
Function allows to share current client instance in address space of current process. Sharing mechanism
is very flexible way to redistribute your IP7_Client object among your modules without passing pointer
to it and modification your interfaces, function is thread safe.
IP7_Client::Flush
Call this function if you want to flush manually time to time buffers to disk/network/console.
void Flush()
P7 library 20
C interface
Client header file is located in <P7>/Headers/P7_Cproxy.h
P7_Client_Create
Function allows to create P7 client object
P7_Client_Get_Shared
This functions allows you to get P7 client instance if it was created by someone else inside current
process and shared using P7_Client_Share(…) function.
Sharing mechanism is very flexible way to redistribute your P7 client object among your modules
without passing pointer to it and modification your interfaces, function is thread safe.
N.B.: Every successful call of this function increase reference counter value on retrieved hP7_Client
object, do not forget to call P7_Client_Release(…) function
P7_Set_Crash_Handler
Function is described in C++ chapter P7_Set_Crash_Handler.
P7_Exceptional_Flush
Function is described in C++ chapter P7_Exceptional_Flush.
P7_Flush
Function is described in C++ chapter P7_Flush.
P7_Client_Add_Ref
Function increase object reference counter
P7_Client_Release
Function decrease object reference counter, object will be destroyed when reference counter is equal to
0.
P7_Client_Share
Function allows to share current client instance in address space of current process. Sharing mechanism
is very flexible way to redistribute your P7 client object among your modules without passing pointer to
it and modification your interfaces, function is thread safe.
Parameters:
i_hClient – P7 client object handle
i_pName – name of shared P7 client instance, should be unique
Return:
TRUE – success
FALSE – failure, the other object with the same name is already shared inside current process
P7_Client_Flush
Call this function if you want to flush manually time to time buffers to disk/network/console.
Parameters:
i_hClient – P7 client object handle
P7 library 22
C# interface
C# shell file is located in <P7>/ Wrappers/C#/P7.cs
C# shell depending on P7x64.dll/ P7x32.dll you may generate them by building P7 solution
P7.Client
Constructor allows to create P7 client object
P7.Client(String i_sArgs)
P7.Get_Shared
This functions allows you to get P7 client instance if it was created by someone else inside current
process and shared using P7::Client::Share(…) function.
Sharing mechanism is very flexible way to redistribute your P7 client object among your modules
without passing pointer to it and modification your interfaces, function is thread safe.
P7.Exceptional_Buffers_Flush
Function allows to flush (deliver) not delivered/saved P7 buffers for all opened P7 clients and related
channels owned by process in CASE OF your app/proc. crush.
Function is completely described in C++ chapter P7_Exceptional_Flush.
P7.Buffers_Flush
Call this function if you want to flush manually time to time buffers to disk/network/console buffers for
all opened P7 clients and related channels owned by process.
P7.Client.Add_Ref
Function increase object reference counter
System.Int32 AddRef()
P7 library 23
P7.Client.Release
Function decrease object reference counter, object will be destroyed when reference counter is equal to
0.
System.Int32 Release()
P7.Client.Share
Function allows to share current client instance in address space of current process. Sharing mechanism
is very flexible way to redistribute your P7 client object among your modules without passing pointer to
it and modification your interfaces, function is thread safe.
P7.Client.Flush
Call this function if you want to flush manually time to time buffers to disk/network/console internal P7
buffers for current client
void Flush()
P7 library 24
Python interface
Python shell file is located in <P7>/ Wrappers/Py/P7.py
Python shell depending on p7-shared.dll (Windows) and p7-shared.so (Linux) you may generate them by
building P7 library
Importing
To import P7 Python shell you have to specify “P7_Bin” environment variable, using that path P7 python
shell will find P7 dll/so shared library, and update system path by P7.py directory.
Here is an example:
import sys;
import os;
#-------------------------------------------------------------------------------
#Loading P7 module by relative path and update PATH system env. variable to be
#able to load P7Client_XX.dll/SO
l_sPath = os.path.dirname(os.path.realpath(__file__)) + "/../../Wrappers/Py/";
if l_sPath not in sys.path:
sys.path.insert(0, l_sPath)
l_sPath = os.path.dirname(os.path.realpath(__file__)) + "/../../Binaries/";
if l_sPath not in os.environ['PATH']:
os.environ['PATH'] += os.pathsep + l_sPath;
os.environ['P7_BIN'] = l_sPath;
import P7;
P7.Register_Client
Function allows to register P7 client in address space of current python session (execution one or group
of depended scripts)
Parameters:
i_sName – name of P7 client, should be unique, used for sharing P7 client in address space of
current python session
i_sArguments – argument string, see “Initialization parameters” chapter for details
Return:
True in case of success
False in case of failure
P7 library 25
Trace interface
Configuration
For fine configuration and controlling of trace channel special structure is defined:
typedef struct
{
void *pContext;
tUINT64 qwTimestamp_Frequency;
fnGet_Time_Stamp pTimestamp_Callback;
fnTrace_Verbosity pVerbosity_Callback;
fnConnect pConnect_Callback;
} stTrace_Conf;
Parameters:
pContext – used defined context pointer, will be used with all callbacks
qwTimestamp_Frequency – in most of the cases trace channel uses hi precision system
timestamps, but if you want to use more precise time stamp please fill this field with your time
precision in Hz. This parameter has to be used only together with pTimestamp_Callback
function. Separate usage isn’t allowed. Put 0 to use default system timestamp.
pTimestamp_Callback – call back to retrieve current user defined timestamp, will be called for
every trace item – so function should not bring performance penalties. Put NULL to use default
system timestamp.
pVerbosity_Callback – call back function to be called when verbosity for module has been
changed (trace, debug, error, … etc.) remotely from Baical. NULL is default value
pConnect_Callback – call back function to be called when connection state has been changed.
NULL is default value
EP7TRACE_LEVEL_COUNT ,
};
#define P7_TRACE_LEVEL_TRACE 0
#define P7_TRACE_LEVEL_DEBUG 1
#define P7_TRACE_LEVEL_INFO 2
#define P7_TRACE_LEVEL_WARNING 3
#define P7_TRACE_LEVEL_ERROR 4
#define P7_TRACE_LEVEL_CRITICAL 5
%[flags][width][.precision][Size modifier]type
Each field of the format specification is a character or a number that signifies a particular format option
or conversion specifier. The required type character specifies the kind of conversion to be applied to an
argument. The optional flags, width, and precision fields control additional format aspects. A basic
format specification contains only the percent sign and a type character.
Flags
In a format specification, the first optional field is flags. A flag directive is a character that specifies
output justification and output of signs, blanks, leading zeros, decimal points, and octal and hexadecimal
prefixes. More than one flag directive may appear in a format specification, and flags can appear in any
order.
the output value to contain a decimal point and digits follow it. Trailing zeros
prevents the truncation of trailing zeros. are truncated.
Ignored when used with c, d, i, u, or s.
0 If width is prefixed by 0, leading zeros are added until No padding.
the minimum width is reached. If both 0 and – appear,
the 0 is ignored. If 0 is specified as an integer format (i,
u, x, X, o, d) and a precision specification is also
present—for example, %04.d—the 0 is ignored.
Width
In a format specification, the second optional field is the width specification. The width argument is a
non-negative decimal integer that controls the minimum number of characters that are output. If the
number of characters in the output value is less than the specified width, blanks are added to the left or
the right of the values—depending on whether the left alignment flag (-) is specified—until the
minimum width is reached. If width is prefixed by 0, leading zeros are added to integer or floating-point
conversions until the minimum width is reached, except when conversion is to an infinity or NAN.
The width specification never causes a value to be truncated. If the number of characters in the output
value is greater than the specified width, or if width is not given, all characters of the value are output,
subject to the precision specification.
If the width specification is an asterisk (*), an int argument from the argument list supplies the value.
The width argument must precede the value that's being formatted in the argument list, as shown in
this example:
A missing or small width value in a format specification does not cause the truncation of an output
value. If the result of a conversion is wider than the width value, the field expands to contain the
conversion result.
Precision
In a format specification, the third optional field is the precision specification. It consists of a period
(.) followed by a non-negative decimal integer that, depending on the conversion type, specifies the
number of string characters, the number of decimal places, or the number of significant digits to be
output.
Unlike the width specification, the precision specification can cause either truncation of the output
value or rounding of a floating-point value. If precision is specified as 0 and the value to be converted
is 0, the result is no characters output, as shown in this example:
If the precision specification is an asterisk (*), an int argument from the argument list supplies the
value. In the argument list, the precision argument must precede the value that's being formatted, as
shown in this example:
Size
In a format specification, the 4th field is an argument size modifier.
The size field is optional for some argument types. When no size prefix is specified, the formatter
consumes integer arguments—for example, signed or unsigned char, short, int, long, and
enumeration types—as 32-bit int types, and floating-point arguments are consumed as 64-bit double
types. This matches the default argument promotion rules for variable argument lists.
Some types are different sizes in 32-bit and 64-bit code. For example, size_t is 32 bits long in code
compiled for x86, and 64 bits in code compiled for x64.
X32 System: 4
j d,b,i,o,u,x,X uintmax_t, intmax_t
It is not recommended to use this
size prefix due to compilers
specifics.
Type
A character that specifies the type of conversion to be applied. The conversion specifiers and their
meanings are:
Type Argument Output format
character
c character character
d Integer Signed decimal integer.
b Integer Unsigned binary integer.
Warning: this type isn’t standard one!
i Integer Signed decimal integer.
o Integer Unsigned octal integer.
u Integer Unsigned decimal integer.
x Integer Unsigned hexadecimal integer; uses "abcdef."
X Integer Unsigned hexadecimal integer; uses "ABCDEF."
s String Windows:
s, ls : wchar_t argument is expected (UTF-16)
hs: char argument is expected (ANSI)
Linux:
s: char argument is expected (UTF-8)
hs: char argument is expected (ANSI)
ls: wchar_t argument is expected (UTF-32)
e,E Floating-point The double argument is rounded and converted in the style
[-]d.ddde±dd where there is one digit before the decimal-point
character and the number of digits after it is equal to the precision;
if the precision is missing, it is taken as 6; if the precision is zero, no
decimal-point character appears. An E conversion uses the letter E
(rather than e) to introduce the exponent. The exponent always
contains at least two digits; if the value is zero, the exponent is 00.
f Floating-point The double argument is rounded and converted to decimal
notation in the style [-]ddd.ddd, where the number of digits after
the decimal-point character is equal to the precision specification.
If the precision is missing, it is taken as 6; if the precision is
explicitly zero, no decimal-point character appears. If a decimal
point appears, at least one digit appears before it.
g, G Floating-point The double argument is converted in style f or e (or F or E for G
conversions). The precision specifies the number of significant
digits. If the precision is missing, 6 digits are given; if the precision
is zero, it is treated as 1. Style e is used if the exponent from its
conversion is less than -4 or greater than or equal to the precision.
Trailing zeros are removed from the fractional part of the result; a
decimal point appears only if it is followed by at least one digit.
a, A Floating-point For a conversion, the double argument is converted to hexadecimal
notation (using the letters abcdef) in the style [-]0xh.hhhhp±; for A
conversion the prefix 0X, the letters ABCDEF, and the exponent
separator P is used. There is one hexadecimal digit before the
decimal point, and the number of digits after it is equal to the
P7 library 30
C++ interface
Trace header file is located in <P7>/Headers/P7_Trace.h
P7_Create_Trace
Function allows to create IP7_Trace object
Parameters:
i_pClient – pointer to client object
i_pName – name of the trace channel
i_pConf – trace channel configuration, optional
Return:
Valid pointer to IP7_Trace object in case of success
NULL in case of failure
P7_Get_Shared_Trace
This functions allows you to get P7 trace instance if it was created by someone else inside current
process and shared using IP7_Trace::Share(…) function.
Sharing mechanism is very flexible way to redistribute your IP7_Trace object among your modules
without passing pointer to it and modification your interfaces, function is thread safe.
N.B.: Every successful call of this function increase reference counter value on retrieved IP7_Trace
object, do not forget to call Release() function
IP7_Trace::Add_Ref
Function increase object reference counter
tINT32 Add_Ref()
IP7_Trace::Release
Function decrease object reference counter, object will be destroyed when reference counter is equal to
0.
tINT32 Release()
P7 library 32
IP7_Trace::Register_Thread
Function register thread name using it ID, used to match later on Baical side thread ID and human
readable thread name. Call this function when new thread is created and do not forget to call
Unregister_Thread when thread has to be closed.
Parameters:
i_pName – thread name
i_dwThread_ID – ID of the thread, if i_dwThread_ID == 0 then current thread ID will be used.
Return:
TRUE – success
FALSE – failure
IP7_Trace::Unregister_Thread
Function unregister thread, used to match later on Baical side thread ID and human readable thread
name.
Parameters:
i_dwThread_ID – ID of the thread, if i_dwThread_ID == 0 then current thread ID will be used.
Return:
TRUE – success
FALSE – failure
IP7_Trace::Register_Module
Function register application module. If application or library which uses P7 contains different parts
(modular architecture) you may use this function. It allows you:
To have nice output on Baical side, in addition to module ID – module name will be printed for
every trace message
Independent verbosity level management for every module. Module verbosity may be set
online through Baical.
Usage of this function does not have an impact on performance of traces, modules information are
transmitted only once.
Parameters:
i_pName – module name (case sensitive), if module with the same name is already exist –
handle to that module will be returned
o_pModule – module handle (output).
Return:
P7 library 33
TRUE – success
FALSE – failure
IP7_Trace::Set_Verbosity
Function sets trace channel verbosity level, all traces with less priority will be rejected, you may set
verbosity level on-line from Baical server.
If module is NULL sets default channel verbosity.
Verbosity levels are described in chapter Trace verbosity levels.
Parameters:
i_hModule – module handle, if handle is NULL global verbosity will be set for whole P7.Trace
object
i_eVerbosity – trace verbosity levels.
IP7_Trace::Get_Verbosity
Function gets trace channel verbosity level for specific module, if module is NULL returns default
channel verbosity.
Verbosity levels are described in chapter Trace verbosity levels.
IP7_Trace::Share
Function allows to share current P7 trace instance in address space of current process. Sharing
mechanism is very flexible way to redistribute your IP7_Trace object among your modules without
passing pointer to it and modification your interfaces, function is thread safe.
IP7_Trace::Trace
Function sent trace message, it has variable arguments list.
Parameters:
i_wTrace_ID – hardcoded trace ID, possible range is [0 .. 1023]. This ID is used to match trace
data and trace format string on server side. You can specify this parameter in range [1..1023] if
you want to send a trace as quickly as possible. Otherwise you can put 0 - and this function will
work a little bit slowly, and ID will be auto-calculated
i_eLevel – trace level (error, warning, debug, etc). Described in chapter Trace verbosity levels
i_hModule – module handle, it is useful for further filtering on Baical side, may be NULL
i_wLine – source file line number from where your trace is called (C/C++ preprocessor macro
__LINE__)
i_pFile – source file line number from where your trace is called (C/C++ preprocessor macro
__FILE__)
i_pFunction – source file name from where your trace is called. (C/C++ preprocessor macro
__FUNCTION__)
i_pFormat – format string (like "Value = %d, %08x"). Described in chapter Trace format string
… - variable arguments
Return:
TRUE – success
FALSE – failure, there are few possible reasons for failure (for details see logs):
o No free buffers to store new trace, P7 client do not have enough time to deliver all
trace/telemetry messages and there is no free buffers
o Baical server is not available (if Sink is Baical)
o No free space on HDD (if Sink is file)
N.B.: DO NOT USE VARIABLES for format string, file name, function name! You should always use
CONSTANT TEXT like "My Format %d, %s", ”myfile.cpp”, “myfunction”
IP7_Trace::Trace_Embedded
Function is similar to Trace(…) function, but intended for embedding into existing logging/trace function
inside your code.
Parameters:
i_wTrace_ID – hardcoded trace ID, possible range is [0 .. 1023]. This ID is used to match trace
data and trace format string on server side. You can specify this parameter in range [1..1023] if
you want to send a trace as quickly as possible. Otherwise you can put 0 - and this function will
work a little bit slowly, and ID will be auto-calculated
i_eLevel – trace level (error, warning, debug, etc). Described in chapter Trace verbosity levels
i_hModule – module handle, it is useful for further filtering on Baical side, may be NULL
i_wLine – source file line number from where your trace is called (C/C++ preprocessor macro
__LINE__)
i_pFile – source file line number from where your trace is called (C/C++ preprocessor macro
__FILE__)
i_pFunction – source file name from where your trace is called. (C/C++ preprocessor macro
__FUNCTION__)
i_pVaList – address of variable arguments list
Return:
TRUE – success
FALSE – failure, there are few possible reasons for failure (for details see logs):
o No free buffers to store new trace, P7 client do not have enough time to deliver all
trace/telemetry messages and there is no free buffers
o Baical server is not available (if Sink is Baical)
o No free space on HDD (if Sink is file)
N.B.: DO NOT USE VARIABLES for format string, file name, function name! You should always use
CONSTANT TEXT like "My Format %d, %s", ”myfile.cpp”, “myfunction”
IP7_Trace::Trace_Managed
Function is similar to Trace(…) function, but intended for usage with managed languages like C#, python,
VB, etc. It is not so efficient like Trace() or Trace_Embedded() functions (about 25% less efficient)
Parameters:
i_wTrace_ID – hardcoded trace ID, possible range is [0 .. 1023]. This ID is used to match trace
data and trace format string on server side. You can specify this parameter in range [1..1023] if
you want to send a trace as quickly as possible. Otherwise you can put 0 - and this function will
work a little bit slowly, and ID will be auto-calculated
i_eLevel – trace level (error, warning, debug, etc). Described in chapter Trace verbosity levels
i_hModule – module handle, it is useful for further filtering on Baical side, may be NULL
i_wLine – source file line number from where your trace is called (C/C++ preprocessor macro
__LINE__)
i_pFile – source file line number from where your trace is called (C/C++ preprocessor macro
__FILE__)
i_pFunction – source file name from where your trace is called. (C/C++ preprocessor macro
__FUNCTION__)
i_pMessage – trace text messsage
P7 library 36
Return:
TRUE – success
FALSE – failure, there are few possible reasons for failure (for details see logs):
o No free buffers to store new trace, P7 client do not have enough time to deliver all
trace/telemetry messages and there is no free buffers
o Baical server is not available (if Sink is Baical)
o No free space on HDD (if Sink is file)
P7 library 37
C interface
Trace header file is located in <P7>/Headers/P7_Cproxy.h
P7_Trace_Create
Function allows to create P7 trace object
Parameters:
i_pClient – client object handle
i_pName – name of the trace channel
i_pConf – trace channel configuration, optional
Return:
Valid handle of P7 trace object in case of success
NULL in case of failure
P7_Trace_Get_Shared
This functions allows you to get P7 trace instance if it was created by someone else inside current
process and shared using P7_Trace_Share(…) function.
Sharing mechanism is very flexible way to redistribute your hP7_Trace object among your modules
without passing pointer to it and modification your interfaces, function is thread safe.
N.B.: Every successful call of this function increase reference counter value on retrieved object handle,
do not forget to call P7_Trace_Release() function
P7_Trace_Add_Ref
Function increase object reference counter
Parameters:
i_hTrace – Trace object handle
Return: object’s reference counter new value
P7 library 38
P7_Trace_Release
Function decrease object reference counter, object will be destroyed when reference counter is equal to
0.
Parameters:
i_hTrace – Trace object handle
Return: object’s reference counter new value
P7_Trace_Register_Thread
Function register thread name using it ID, used to match later on Baical side thread ID and human
readable thread name. Call this function when new thread is created and do not forget to call
P7_Trace_Unregister_Thread when thread has to be closed.
Parameters:
i_hTrace – Trace object handle
i_pName – thread name
i_dwThread_ID – ID of the thread, if i_dwThread_ID == 0 then current thread ID will be used.
Return:
TRUE – success
FALSE – failure
P7_Trace_Unregister_Thread
Function unregister thread, used to match later on Baical side thread ID and human readable thread
name.
Parameters:
i_hTrace – Trace object handle
i_dwThread_ID – ID of the thread, if i_dwThread_ID == 0 then current thread ID will be used.
Return:
TRUE – success
FALSE – failure
P7_Trace_Register_Module
Function register application module. If application or library which uses P7 contains different parts
(modular architecture) you may use this function. It allows you:
To have nice output on Baical side, in addition to module ID – module name will be printed for
every trace message
P7 library 39
Independent verbosity level management for every module. Module verbosity may be set
online through Baical.
Usage of this function does not have an impact on performance of traces, modules information are
transmitted only once.
Parameters:
i_hTrace – Trace object handle
i_pName – module name (case sensitive), if module with the same name is already exist –
handle to that module will be returned
Return:
module handle
P7_Trace_Set_Verbosity
Function sets trace channel verbosity level, all traces with less priority will be rejected, you may set
verbosity level on-line from Baical server.
If module is NULL default channel verbosity is set.
Parameters:
i_hTrace – trace object handle
i_hModule – module handle, if handle is NULL global verbosity will be set for whole P7.Trace
object
i_dwVerbosity – verbosity level, next values are available:
o P7_TRACE_LEVEL_TRACE (0)
o P7_TRACE_LEVEL_DEBUG (1)
o P7_TRACE_LEVEL_INFO (2)
o P7_TRACE_LEVEL_WARNING (3)
o P7_TRACE_LEVEL_ERROR (4)
o P7_TRACE_LEVEL_CRITICAL (5)
P7_Trace_Get_Verbosity
Function gets trace channel verbosity level.
If module is NULL default channel verbosity is provided
Parameters:
i_hTrace – trace object handle
i_hModule – module handle, if handle is NULL global verbosity will be set for whole P7.Trace
object
Return: verbosity level, next values are available:
P7 library 40
o P7_TRACE_LEVEL_TRACE (0)
o P7_TRACE_LEVEL_DEBUG (1)
o P7_TRACE_LEVEL_INFO (2)
o P7_TRACE_LEVEL_WARNING (3)
o P7_TRACE_LEVEL_ERROR (4)
o P7_TRACE_LEVEL_CRITICAL (5)
P7_Trace_Share
Function allows to share current client instance in address space of current process. Sharing mechanism
is very flexible way to redistribute your P7 trace object among your modules without passing pointer to
it and modification your interfaces, function is thread safe.
Parameters:
i_hTrace – trace object handle
i_pName – name of shared P7 client instance, should be unique
Return:
TRUE - success
FALSE – failure, the other object with the same name is already shared inside current process
P7_Trace_Add
Function sent trace message, it has variable arguments list.
Parameters:
i_hTrace – trace object handle
i_wTrace_ID – hardcoded trace ID, possible range is [0 .. 1023]. This ID is used to match trace
data and trace format string on server side. You can specify this parameter in range [1..1023] if
you want to send a trace as quickly as possible. Otherwise you can put 0 - and this function will
work a little bit slowly, and ID will be auto-calculated
i_eLevel – trace level (error, warning, debug, etc). Described in chapter Trace verbosity levels
i_hModule – module handle, it is useful for further filtering on Baical side, may be NULL
i_wLine – source file line number from where your trace is called (C/C++ preprocessor macro
__LINE__)
i_pFile – source file line number from where your trace is called (C/C++ preprocessor macro
__FILE__)
i_pFunction – source file name from where your trace is called. (C/C++ preprocessor macro
__FUNCTION__)
i_pFormat – format string (like "Value = %d, %08x"). Described in chapter Trace format string
… - variable arguments
P7 library 41
Return:
TRUE - success
FALSE – failure, there are few possible reasons for failure (for details see logs):
o No free buffers to store new trace, P7 client do not have enough time to deliver all
trace/telemetry messages and there is no free buffers
o Baical server is not available (if Sink is Baical)
o No free space on HDD (if Sink is file)
N.B.: DO NOT USE VARIABLES for format string, file name, function name! You should always use
CONSTANT TEXT like "My Format %d, %s", ”myfile.cpp”, “myfunction”
To simplify function call you may use macro P7_TRACE_ADD defined in <P7>/Headers/P7_Cproxy.h.
P7_Trace_Embedded
Function is similar to P7_Trace_Add(…) function, but intended for embedding into existing logging/trace
function inside your code.
Parameters:
i_hTrace – trace object handle
i_wTrace_ID – hardcoded trace ID, possible range is [0 .. 1023]. This ID is used to match trace
data and trace format string on server side. You can specify this parameter in range [1..1023] if
you want to send a trace as quickly as possible. Otherwise you can put 0 - and this function will
work a little bit slowly, and ID will be auto-calculated
i_eLevel – trace level (error, warning, debug, etc). Described in chapter Trace verbosity levels
i_hModule – module handle, it is useful for further filtering on Baical side, may be NULL
i_wLine – source file line number from where your trace is called (C/C++ preprocessor macro
__LINE__)
i_pFile – source file line number from where your trace is called (C/C++ preprocessor macro
__FILE__)
i_pFunction – source file name from where your trace is called. (C/C++ preprocessor macro
__FUNCTION__)
i_pVaList – address of variable arguments list
Return:
TRUE - success
FALSE – failure, there are few possible reasons for failure (for details see logs):
o No free buffers to store new trace, P7 client do not have enough time to deliver all
trace/telemetry messages and there is no free buffers
o Baical server is not available (if Sink is Baical)
o No free space on HDD (if Sink is file)
P7 library 42
N.B.: DO NOT USE VARIABLES for format string, file name, function name! You should always use
CONSTANT TEXT like "My Format %d, %s", ”myfile.cpp”, “myfunction”
P7_Trace_Managed
Function is similar to P7_Trace_Add (…) function, but intended for usage with managed languages like
C#, python, VB, etc. It is not so efficient like P7_Trace_Add () or P7_Trace_Embedded() functions (about
25% less efficient)
Parameters:
i_hTrace – trace object handle
i_wTrace_ID – hardcoded trace ID, possible range is [0 .. 1023]. This ID is used to match trace
data and trace format string on server side. You can specify this parameter in range [1..1023] if
you want to send a trace as quickly as possible. Otherwise you can put 0 - and this function will
work a little bit slowly, and ID will be auto-calculated
i_eLevel – trace level (error, warning, debug, etc). Described in chapter Trace verbosity levels
i_hModule – module handle, it is useful for further filtering on Baical side, may be NULL
i_wLine – source file line number from where your trace is called (C/C++ preprocessor macro
__LINE__)
i_pFile – source file line number from where your trace is called (C/C++ preprocessor macro
__FILE__)
i_pFunction – source file name from where your trace is called. (C/C++ preprocessor macro
__FUNCTION__)
i_pMessage – trace text messsage
Return:
TRUE - success
FALSE – failure, there are few possible reasons for failure (for details see logs):
o No free buffers to store new trace, P7 client do not have enough time to deliver all
trace/telemetry messages and there is no free buffers
o Baical server is not available (if Sink is Baical)
o No free space on HDD (if Sink is file)
P7 library 43
C# interface
C# shell file is located in <P7>/ Wrappers/C#/P7.cs
C# shell depending on P7x64.dll/ P7x32.dll you may generate them by building P7 solution
P7.Traces
Constructor allows to create P7 trace object
Parameters:
i_pClient – client object class
i_pName – name of the trace channel
Return:
P7 trace object in case of success
ArgumentException(…) or ArgumentNullException(…) in case of failure
P7.Traces.Get_Shared
This functions allows you to get P7 trace instance if it was created by someone else inside current
process and shared using P7::Traces::Share(…) function.
Sharing mechanism is very flexible way to redistribute your P7 trace object among your modules
without passing pointer to it and modification your interfaces, function is thread safe.
P7.Traces.Add_Ref
Function increase object reference counter
System.Int32 AddRef()
P7.Trace.Release
Function decrease object reference counter, object will be destroyed when reference counter is equal to
0.
System.Int32 Release()
P7.Traces.Register_Thread
Function register thread name using it ID, used to match later on Baical side thread ID and human
readable thread name. Call this function when new thread is created and do not forget to call
P7_Trace_Unregister_Thread when thread has to be closed.
Parameters:
i_sName – thread name
i_dwThread_ID – ID of the thread, if i_dwThread_ID == 0 then current thread ID will be used.
Return:
true – success
false – failure
P7.Traces.Unregister_Thread
Function unregister thread, used to match later on Baical side thread ID and human readable thread
name.
Parameters:
i_dwThread_ID – ID of the thread, if i_dwThread_ID == 0 then current thread ID will be used.
Return:
TRUE – success
FALSE – failure
P7.Traces.Register_Module
Function register application module. If application or library which uses P7 contains different parts
(modular architecture) you may use this function. It allows you:
To have nice output on Baical side, in addition to module ID – module name will be printed for
every trace message
Independent verbosity level management for every module. Module verbosity may be set
online through Baical.
Usage of this function does not have an impact on performance of traces, modules information are
transmitted only once.
Parameters:
i_pName – module name (case sensitive), if module with the same name is already exist –
handle to that module will be returned
Return:
module handle
P7 library 45
P7.Traces.Set_Verbosity
Function sets trace channel verbosity level, all traces with less priority will be rejected, you may set
verbosity level on-line from Baical server.
If Module is null pointer default verbosity level for channel is set.
Parameters:
i_hModule – module handle, if handle is null global verbosity will be set for whole P7.Trace
object. To obtain module handle use P7.Traces.Register_Module() function
i_dwVerbosity – verbosity level
P7.Traces.Get_Verbosity
Function gets trace channel verbosity level. If Module is null pointer default verbosity level for channel is
returned.
Parameters:
i_hModule – module handle, if handle is null global verbosity will be set for whole P7.Trace
object. To obtain module handle use P7.Traces.Register_Module() function
Return: verbosity level
P7.Traces.Share
Function allows to share current client instance in address space of current process. Sharing mechanism
is very flexible way to redistribute your P7 trace object among your modules without passing pointer to
it and modification your interfaces, function is thread safe.
Parameters:
i_sName – name of shared P7 client instance, should be unique
Return:
TRUE - success
FALSE – failure, the other object with the same name is already shared inside current process
P7.Traces.Trace
Functions sent trace/debug/warning/error/critical messages.
Parameters:
P7 library 46
i_hModule – module handle, it is useful for further filtering on Baical side. To obtain module
handle use P7.Traces.Register_Module() function
i_sMessage – trace message
Return:
TRUE - success
FALSE – failure, there are few possible reasons for failure (for details see logs):
o No free buffers to store new trace, P7 client do not have enough time to deliver all
trace/telemetry messages and there is no free buffers
o Baical server is not available (if Sink is Baical)
o No free space on HDD (if Sink is file)
P7 library 47
Python interface
Python shell file is located in <P7>/ Wrappers/Py/P7.py
Python shell depending on P7x64.dll/P7x32.dll (Windows) and libP7.so (Linux) you may generate them
by building P7 solution under Windows or run build.sh under Linux
Importing
Importing is described in Client Importing chapter.
P7. Get_Trace_Channel
Function allows to get P7 trace instance by name or create new one.
Parameters:
i_sTraceName – name of P7 trace instance, should be unique, used for sharing P7 trace in
address space of current python session
i_sClientName – name of the client, registered by function call Register_Client(), may be empty
if client with i_sTraceName is already exists, otherwise i_sClientName is used to create new
trace object
Return:
True in case of success
None in case of failure
P7. Traces.Enable_Stack_Info
Function allows enable/disable collecting stack information (file name & line, function name). Extracting
information about stack takes a lot of time, about additional 500 microseconds on modern PC (2014). If
you disable stack information - trace functions will be accelerated about 50-150 times depending on
python version.
P7.Traces.Enable_Stack_Info(self, i_bEnabled)
Parameters:
i_bEnabled – disable – False, enable - True
P7.Traces.Trace
Functions sent trace/debug/info/warning/error/critical messages.
Parameters:
i_hModule – module handle, if handle is 0 global verbosity will be set for whole P7.Trace object.
To obtain module handle use P7.Traces.Register_Module() function
i_sMessage – trace message
P7 library 48
Return:
True – success
False – failure, there are few possible reasons for failure (for details see logs):
o No free buffers to store new trace, P7 client do not have enough time to deliver all
trace/telemetry messages and there is no free buffers
o Baical server is not available (if Sink is Baical)
o No free space on HDD (if Sink is file)
P7.Traces.Set_Verbosity
Function sets trace channel verbosity level, all traces with less priority will be rejected, you may set
verbosity level on-line from Baical server.
If module is 0 – default channel verbosity is set.
Parameters:
i_hModule – module handle, if handle is null global verbosity will be set for whole P7.Trace
object. To obtain module handle use P7.Traces.Register_Module() function
i_iLevel – verbosity level, there are next verbosity levels:
P7.Traces.m_iTrace (0)
P7.Traces.m_iDebug (1)
P7.Traces.m_iInfo (2)
P7.Traces.m_iWarning (3)
P7.Traces.m_iError (4)
P7.Traces.m_iCritical (5)
P7.Traces.Get_Verbosity
Function gets trace channel verbosity level.
If module is 0 – default channel verbosity is returned.
P7.Traces.Set_Verbosity(self, i_hModule)
Parameters:
i_hModule – module handle, if handle is null global verbosity will be set for whole P7.Trace
object. To obtain module handle use P7.Traces.Register_Module() function
Return: verbosity level, there are next verbosity levels:
P7.Traces.m_iTrace (0)
P7.Traces.m_iDebug (1)
P7.Traces.m_iInfo (2)
P7.Traces.m_iWarning (3)
P7.Traces.m_iError (4)
P7.Traces.m_iCritical (5)
P7 library 49
P7.Traces.Register_Module
Function register application module. If application or library which uses P7 contains different parts
(modular architecture) you may use this function. It allows you:
To have nice output on Baical side, in addition to module ID – module name will be printed for
every trace message
Independent verbosity level management for every module. Module verbosity may be set
online through Baical.
Usage of this function does not have an impact on performance of traces, modules information are
transmitted only once.
Parameters:
i_pName – module name (case sensitive), if module with the same name is already exist –
handle to that module will be returned
Return:
module handle (digit)
P7 library 50
Telemetry interface
Configuration
For fine configuration and controlling of telemetry channel special structure is defined:
Parameters:
pContext – used defined context pointer, will be used with all callbacks
qwTimestamp_Frequency – in most of the cases telemetry channel uses hi precision system
timestamps, but if you want to use more precise time stamp please fill this field with your time
precision in Hz. This parameter has to be used only together with pTimestamp_Callback
function. Separate usage isn’t allowed. Put 0 to use default system timestamp.
pTimestamp_Callback – call back to retrieve current user defined timestamp, will be called for
every telemetry sample – so function should not bring performance penalties. Put NULL to use
default system timestamp.
pEnable_Callback – call back function to be called when state of the counter has been changed
(ON/OFF) remotely from Baical. NULL is default value
pConnect_Callback – call back function to be called when connection state has been changed.
NULL is default value
C++ interface
Trace header file is located in <P7>/Headers/P7_Telemetry.h
P7_Create_Telemetry
Function allows to create P7 telemetry object
Parameters:
i_pClient – pointer to client object
i_pName – name of the telemetry channel
i_pConf – telemetry channel configuration, use NULL for default values.
Return:
Valid pointer to IP7_Telemetry object in case of success
NULL in case of failure
P7_Get_Shared_Telemetry
This functions allows you to get P7 telemetry instance if it was created by someone else inside current
process and shared using IP7_Telemetry::Share(…) function.
Sharing mechanism is very flexible way to redistribute your P7 telemetry object among your modules
without passing pointer to it and modification your interfaces, function is thread safe.
N.B.: Every successful call of this function increase reference counter value on retrieved IP7_Telemetry
object, do not forget to call Release() function
IP7_Telemetry::Add_Ref
Function increase object reference counter
tINT32 Add_Ref()
IP7_Telemetry::Release
Function decrease object reference counter, object will be destroyed when reference counter is equal to
0.
tINT32 Release()
P7 library 52
IP7_Telemetry::Share
Function allows to share current P7 telemetry instance in address space of current process. Sharing
mechanism is very flexible way to redistribute your P7 telemetry object among your modules without
passing pointer to it and modification your interfaces, function is thread safe.
IP7_Tlemetry::Create
Function creates new telemetry counter and return counter’s ID. One channel can handle up to 65534
independent counters.
Parameters:
i_pName - name of counter, max length 64 characters, should be unique for current channel
(case sensitive)
i_dbMin – minimal counter value, helping information for visualization, later you can override it
in telemetry viewer
i_dbAlarmMin – alarm counter value, values below will be highlighted
i_dbMax – maximal counter value, helping information for visualization, later you can override
it in telemetry viewer
i_dbAlarmMax – alarm counter value, values above will be highlighted
i_bOn – parameter specifies is counter enabled (1) or disabled (0) by default, later you can
enable/disable it in real time from Baical server.
o_pID – output parameter, receives ID of the counter, this value is used to add samples to the
counter
Return:
TRUE – in case of success
FALSE – in case of failure, there are few possible reasons:
o No empty counters, all slots are busy
o Not valid input parameters
o Counters name is already used
P7 library 53
IP7_Telemetry::Add
Function allows to add counter’s sample.
Parameters:
i_wID – counter ID
i_dbValue – sample value
Return:
TRUE – in case of success
FALSE – in case of failure, there are few possible reasons:
o No network connection (if Sink=Baical)
o No free HDD space (if Sink=File)
o Not valid input parameters
IP7_Telemetry::Find
Function finds counter’s ID by its name. Search is case sensitive.
Parameters:
i_pName - name of counter
o_pID – output parameter, receives ID of the counter, this value is used to add samples to the
counter
Return:
TRUE – success, counter is found
FALSE – failure, no counter with such name
P7 library 54
C interface
Trace header file is located in <P7>/Headers/P7_Cproxy.h
P7_Telemetry_Create
Function allows to create P7 telemetry object
Parameters:
i_hClient – client object handle
i_pName – name of the telemetry channel
i_pConf – telemetry channel configuration, use NULL for default values.
Return:
Valid handle of P7 telemetry object in case of success
NULL in case of failure
P7_Telemetry_Get_Shared
This functions allows you to get P7 telemetry instance if it was created by someone else inside current
process and shared using P7_Telemetry_Share(…) function.
Sharing mechanism is very flexible way to redistribute your P7 telemetry object among your modules
without passing pointer to it and modification your interfaces, function is thread safe.
N.B.: Every successful call of this function increase reference counter value on retrieved P7 telemetry
object, do not forget to call P7_Telemetry_Release() function
P7_Telemetry_Add_Ref
Function increase object reference counter
P7_Telemetry_Release
Function decrease object reference counter, object will be destroyed when reference counter is equal to
0.
P7 library 55
P7_Telemetry_Share
Function allows to share current P7 telemetry instance in address space of current process. Sharing
mechanism is very flexible way to redistribute your P7 telemetry object among your modules without
passing pointer to it and modification your interfaces, function is thread safe.
Parameters:
i_hTelemetry – P7 telemetry object handle
i_pName - name of shared P7 telemetry instance, should be unique
Return:
TRUE – success
FALSE – failure, the other object with the same name is already shared inside current process
P7_Tlemetry_Create_Counter
Function create new telemetry counter and return counter’s ID, one channel can handle up to 65534
independent counters.
Parameters:
i_hTelemetry – P7 telemetry object handle
i_pName - name of counter, max length 64 characters, should be unique for current channel
(case sensitive)
i_dbMin – minimal counter value, helping information for visualization, later you can override it
in telemetry viewer
i_dbAlarmMin – alarm counter value, values below will be highlighted
i_dbMax – maximal counter value, helping information for visualization, later you can override
it in telemetry viewer
i_dbAlarmMax – alarm counter value, values above will be highlighted
i_bOn – parameter specifies is counter enabled (1) or disabled (0) by default, later you can
enable/disable it in real time from Baical server.
o_pID – output parameter, receives ID of the counter, this value is used to add samples to the
counter
Return:
TRUE – in case of success
FALSE – in case of failure, there are few possible reasons:
P7 library 56
P7_Telemetry_Put_Value
Function allows to add counter’s sample.
Parameters:
i_hTelemetry – P7 telemetry object handle
i_wID – counter ID
i_dbValue – sample value
Return:
TRUE – in case of success
FALSE – in case of failure, there are few possible reasons:
o No network connection (if Sink=Baical)
o No free HDD space (if Sink=File)
o Not valid input parameters
P7_Telemetry_Find_Counter
Function finds counter’s ID by its name. Search is case sensitive.
Parameters:
i_hTelemetry – P7 telemetry object handle
i_pName - name of counter
o_pID – output parameter, receives ID of the counter, this value is used to add samples to the
counter
Return:
TRUE – success, counter is found
FALSE – failure, no counter with such name
P7 library 57
C# interface
C# shell file is located in <P7>/ Wrappers/C#/P7.cs
C# shell depending on P7x64.dll/ P7x32.dll you may generate them by building P7 solution
P7.Telemetry
Constructor allows to create P7 telemetry object
Parameters:
i_pClient – client object class
i_pName – name of the trace channel
Return:
P7 trace object in case of success
ArgumentException(…) or ArgumentNullException(…) in case of failure
P7.Telemetry.Get_Shared
This functions allows you to get P7 telemetry instance if it was created by someone else inside current
process and shared using P7::Telemetry::Share(…) function.
Sharing mechanism is very flexible way to redistribute your P7 telemetry object among your modules
without passing pointer to it and modification your interfaces, function is thread safe.
P7.Telemetry.Add_Ref
Function increase object reference counter
System.Int32 AddRef()
P7.Telemetry.Release
Function decrease object reference counter, object will be destroyed when reference counter is equal to
0.
System.Int32 Release()
P7.Telemetry.Share
Function allows to share current client instance in address space of current process. Sharing mechanism
is very flexible way to redistribute your P7 telemetry object among your modules without passing
pointer to it and modification your interfaces, function is thread safe.
Parameters:
i_sName – name of shared P7 client instance, should be unique
Return:
TRUE - success
FALSE – failure, the other object with the same name is already shared inside current process
P7.Tlemetry.Create
Function creates new telemetry counter and return counter’s ID. One channel can handle up to 65534
independent counters.
Parameters:
i_pName - name of counter, max length 64 characters, should be unique for current channel
(case sensitive)
i_dbMin – minimal counter value, helping information for visualization, later you can override it
in telemetry viewer
i_dbAlarmMin – alarm counter value, values below will be highlighted
i_dbMax – maximal counter value, helping information for visualization, later you can override
it in telemetry viewer
i_dbAlarmMax – alarm counter value, values above will be highlighted
i_bOn – parameter specifies is counter enabled (1) or disabled (0) by default, later you can
enable/disable it in real time from Baical server.
o_pID – output parameter, receives ID of the counter, this value is used to add samples to the
counter
Return:
TRUE – in case of success
FALSE – in case of failure, there are few possible reasons:
o No empty counters, all slots are busy
o Not valid input parameters
o Counters name is already used
P7.Telemetry.Add
Function allows to add counter’s sample.
Parameters:
i_wID – counter ID
i_dbValue – sample value
Return:
TRUE – in case of success
FALSE – in case of failure, there are few possible reasons:
o No network connection (if Sink=Baical)
o No free HDD space (if Sink=File)
o Not valid input parameters
P7.Telemetry.Find_Counter
Function finds counter’s ID by its name. Search is case sensitive.
Parameters:
i_sName - name of counter
o_rCounter_ID – output parameter, receives ID of the counter, this value is used to add samples
to the counter
Return:
TRUE – success, counter is found
FALSE – failure, no counter with such name
P7 library 60
Python interface
Python shell file is located in <P7>/ Wrappers/Py/P7.py
Python shell depending on P7x64.dll/P7x32.dll (Windows) and libP7.so (Linux) you may generate them
by building P7 solution under Windows or run build.sh under Linux
Importing
Importing is described in Client Importing chapter.
P7. Get_Telemetry_Channel
Function allows to get P7 telemetry instance by name or create new one.
Parameters:
i_sTelemetryName – name of P7 telemetry object, should be unique, used for sharing P7
telemetry object in address space of current python session
i_sClientName – name of the client, registered by function call Register_Client(), may be empty
if client with i_sTraceName is already exists, otherwise i_sClientName is used to create new
trace object
Return:
True in case of success
None in case of failure
P7. Telemetry.Create
Function creates new telemetry counter and return counter’s ID. One channel can handle up to 65534
independent counters.
ushort P7.Telemetry.Create(self,
i_sName,
i_dbMin,
i_dbAlarmMin,
i_dbMax,
i_dbAlarmMax,
i_bOn)
Parameters:
i_sName - name of counter, max length 64 characters, should be unique for current channel
(case sensitive)
i_dbMin – minimal counter value, helping information for visualization, later you can override it
in telemetry viewer
i_dbAlarmMin – alarm counter value, values below will be highlighted
i_dbMax – maximal counter value, helping information for visualization, later you can override
it in telemetry viewer
i_dbAlarmMax – alarm counter value, values above will be highlighted
i_bOn – parameter specifies is counter enabled (1) or disabled (0) by default, later you can
enable/disable it in real time from Baical server.
Return:
[0..65534] – in case of success
[65535] – in case of failure, there are few possible reasons:
P7 library 61
P7.Telemetry.Add
Function allows to add counter’s sample.
Parameters:
i_wID – counter ID
i_dbValue – sample value
Return:
TRUE – in case of success
FALSE – in case of failure, there are few possible reasons:
o No network connection (if Sink=Baical)
o No free HDD space (if Sink=File)
o Not valid input parameters
P7.Telemetry.Find_Counter
Function finds counter’s ID by its name. Search is case sensitive.
Parameters:
i_sName - name of counter
Return:
[0..65534] – success, counter is found
[65535] – failure, no counter with such name
P7 library 62
Sharing P7 instances
It is always difficult to integrate new library into project especially if library functionality have to be
called from many different projects parts. You have to update your internal interfaces to pass pointers,
handles, classes or create new abstraction layer or even worse – create singleton.
P7 has mechanism (thread safe) to simplify integration process and gives ability just use it without
internal interfaces modification – sharing mechanism.
It pretty simple to use it, for example you have some place in your project where you are going to
initialize P7 trace/telemetry instances:
And then from any place or your project you can do:
//using it
if (l_hTrace)
{
l_hTrace->P7_INFO(0, TM("Information message #%d”), 0);
...
//release the instance
l_hTrace->Release();
}
You may use sharing mechanism for P7 client, P7 telemetry or trace channels.
P7 library 63
Compilation
Library has no external dependencies and based on CMake build scripts, so build process should be as
simple as possible.
To build the library please download and install CMake v3.8 or greater (https://cmake.org/download/)
SIGBUS error
On some architectures (SPARC for example) access to memory have to be aligned.
By default P7 library is working with raw data, to respect architecture data alignment requirements
please uncomment P7TRACE_64BITS_ALIGNED_ACCESS macro in “P7_Trace.h” header file
////////////////////////////////////////////////////////////////////////////////
//in some platforms access to 64 not aligned variable is illegal, if it the/
//case please active the macro /
////////////////////////////////////////////////////////////////////////////////
//#define P7TRACE_64BITS_ALIGNED_ACCESS
P7 library 66
In addition inside <P7>/Headers/P7_Cproxy.h header file, function types definitions are described for
every exported C function, for example:
////////////////////////////////////////////////////////////////////////////////
//P7_Client_Create - function creates new P7 client, client is used as transport
//...
extern hP7_Client __cdecl P7_Client_Create(const tXCHAR *i_pArgs);
//dll/so function prototype
typedef hP7_Client (__cdecl *fnP7_Client_Create)(const tXCHAR *i_pArgs);
How to load & use dynamic (shared) libraries is described in next articles (with examples):
http://msdn.microsoft.com/en-us/library/windows/desktop/ms686944(v=vs.85).aspx
http://linux.die.net/man/3/dlopen
P7 library 67
Examples
There are few examples available on different languages, they are located in <P7 folder>/Examples.
Examples are available for next languages:
C
C++
Csharp
Python