Package: palanteer-scripting
Look into Palanteer and get an omniscient view of your programPalanteer is a set of lean and efficient tools to improve the quality of software, for C++ and Python programs.Simple code instrumentation, mostly automatic in Python, delivers powerful features:Collection of meaningful atomic eventson timings, memory, locks wait and usage, context switches, data values..Visual and interactive observationof record: timeline, plot, histograms, flame graph...Remote command call and events observation can be scripted in Python: deep testing has never been simplerC++:ultra-light single-header cross-platform instrumentation librarycompile-time selection of groups of instrumentationcompile-time hashing of static string to minimize their costcompile-time striping of all instrumentation static stringsenhanced assertions, stack trace dump...Python:Automatic instrumentation of functions enter/leave, memory allocations, raised exceptions, garbage collection runsSupport of multithread, coroutines, asyncio/geventPalanteer is an efficient, lean and comprehensive solution for better and enjoyable software development!UsageThis scripting module processes the events sent by instrumented programs, independently of their language (Python or C++).Typical usages are:Tests based on stimulations/configuration with CLI and events observation, as data can also be tracedEvaluation of the program performanceMonitoring...Below is a simple example of a Python program instrumented with Palanteer and generating 100 000 random integers.The range can be remotely configured with a user-definedPalanteerCLI.#! /usr/bin/env python3importsysimportrandomfrompalanteerimport*globalMinValue,globalMaxValue=0,10# Handler (=implementation) of the example CLI, which sets the rangedefsetBoundsCliHandler(minValue,maxValue):# 2 parameters (both integer) as declaredglobalglobalMinValue,globalMaxValueifminValue>maxValue:# Case where the CLI execution fails (non null status). The text answer contains some information about itreturn1,"Minimum value (%d) shall be lower than the maximum value (%d)"%(minValue,maxValue)# Modify the state of the programglobalMinValue,globalMaxValue=minValue,maxValue# CLI execution was successful (null status)return0,""defmain(argv):globalglobalMinValue,globalMaxValueplInitAndStart("example")# Start the instrumentationplDeclareThread("Main")# Declare the current thread as "Main", so that it can be identified more easily in the scriptplRegisterCli(setBoundsCliHandler,"config:setRange","min=int max=int","Sets the value bounds of the random generator")# Declare the CLIplFreezePoint()# Add a freeze point here to be able to configure the program at a controlled momentplBegin("Generate some random values")foriinrange(100000):value=int(globalMinValue+random.random()*(globalMaxValue+1-globalMinValue))plData("random data",value)# Here are the "useful" valuesplEnd("")# Shortcut for plEnd("Generate some random values")plStopAndUninit()# Stop and uninitialize the instrumentation# Bootstrapif__name__=="__main__":main(sys.argv)The Python scripting module can remotely control this program, in particular:call the setBoundsCliHandler to change the configurationtemporarily halt the program at the freeze pointsee all "random data" values and the timing of the scope event "Generate some random values"#! /usr/bin/env python3importsysimportpalanteer_scriptingaspsdefmain(argv):iflen(sys.argv)<2:print("Error: missing parameters (the program to launch)")sys.exit(1)# Initialize the scripting moduleps.initialize_scripting()# Enable the freeze mode so that we can safely configure the program once stopped on its freeze pointps.program_set_freeze_mode(True)# Launch the program under testps.process_launch(sys.argv[1],args=sys.argv[2:])# From here, we are connected to the remote program# Configure the selection of events to receivemy_selection=ps.EvtSpec(thread="Main",events=["random data"])# Thread "Main", only the event "random data"ps.data_configure_events(my_selection)# Configure the programstatus,response=ps.program_cli("config:setRange min=300 max=500")ifstatus!=0:print("Error when configuring:%s\nKeeping original settings."%response)# Disable the freeze mode so that the program resumes its executionps.program_set_freeze_mode(False)# Collect the events as long as the program is alive or we got some events in the last roundqty,sum_values,min_value,max_value,has_worked=0,0,1e9,0,Truewhileps.process_is_running()orhas_worked:has_worked=Falseforeinps.data_collect_events(timeout_sec=1.):# Loop on received events, per batchhas_worked,qty,sum_values,min_value,max_value=True,qty+1,sum_values+e.value,min(min_value,e.value),max(max_value,e.value)# Display the result of the processed collection of dataprint("Quantity:%d\nMinimum :%d\nAverage :%d\nMaximum :%d"%(qty,min_value,sum_values/max(qty,1),max_value))# Cleaningps.process_stop()# Kills the launched process, if still runningps.uninitialize_scripting()# Uninitialize the scripting module# Bootstrapif__name__=="__main__":main(sys.argv)The execution of this last script, with the first one as parameter, gives the following output:> ./remoteScript.py example.py
Quantity: 100000
Minimum : 300
Average : 400
Maximum : 500Details can be foundhere.Installation of the scripting moduleDirectly from the PyPI storage (from sources on Linux, binary on Windows)pipinstallpalanteer_scriptingDirectly from GitHub sourcespipinstall"git+https://github.com/dfeneyrou/palanteer#egg=palanteer_scripting&subdirectory=server/scripting"From locally retrieved sourcesGet the sources:gitclonehttps://github.com/dfeneyrou/palanteercdpalanteer
mkdirbuildcdbuildBuild on Linux:cmake..-DCMAKE_BUILD_TYPE=Release
make-j$(nproc)installBuild on Windows:(vcvarsall.bator equivalent shall be called beforehand, so that the MSVC compiler is accessible)cmake..-DCMAKE_BUILD_TYPE=Release-G"NMake Makefiles"nmakeinstallImportant!To be useful, this module requires an "instrumentation side" in the program under analysis (C++ or Python):For Python language, the instrumentation module is availableon PyPIor from thegithub sourcesFor C++ language, the instrumentation library is a single header file available in thegithub sourcesAlso, agraphical vieweris available for non-scripted analysis of the program behaviors.NOTE: It isstronglyrecommended to have a matching version between the scripting module and the instrumentation sides