dfeneyrou / palanteer
- четверг, 24 июня 2021 г. в 00:30:50
High performance visual profiler, debugger, tests enabler for C++ and Python
Palanteer is a set of lean and efficient tools to improve the general software quality, for C++ and Python programs.
Simple code instrumentation, mostly automatic in Python, delivers powerful features:
Palanteer is an efficient, lean and comprehensive solution for better and enjoyable software development!
Below is a simple example of a C++ program instrumented with Palanteer and generating 100 000 random integers. The range can be remotely configured with a user-defined CLI.
The Python scripting module can control this program, in particular:
// File: example.cpp
// On Linux, build with: g++ -DUSE_PL=1 -I <palanteer C++ instrumentation folder> example.cpp -lpthread -o example
#include <stdlib.h> // For "rand"
#define PL_IMPLEMENTATION 1 // The instrumentation library shall be "implemented" once
#include "palanteer.h"
int globalMinValue = 0, globalMaxValue = 10;
// Handler (=user implementation) of the example CLI, which sets the range
void setBoundsCliHandler(plCliIo& cio) // 'cio' is a communication helper passed to each C++ CLI handler
{
int minValue = cio.getParamInt(0); // Get the 2 CLI parameters as integers (as declared)
int maxValue = cio.getParamInt(1);
if(minValue>maxValue) { // Case where the CLI execution fails. The text answer contains some information about it
cio.setErrorState("Minimum value (%d) shall be lower than the maximum value (%d)", minValue, maxValue);
return;
}
// Modify the state of the program. No care about thread-safety here, to keep the example simple
globalMinValue = minValue;
globalMaxValue = maxValue;
// CLI execution was successful (because no call to cio.setErrorState())
}
int main(int argc, char** argv)
{
plInitAndStart("example"); // Start the instrumentation, for the program named "example"
plDeclareThread("Main"); // Declare the current thread as "Main" so that it can be identified more easily in the script
plRegisterCli(setBoundsCliHandler, "config:setRange", "min=int max=int", "Sets the value bounds of the random generator"); // Declare our CLI
plFreezePoint(); // Add a freeze point here to be able to configure the program at a controlled moment
plBegin("Generate some random values");
for(int i=0; i<100000; ++i) {
int value = globalMinValue + rand()%(globalMaxValue+1-globalMinValue);
plData("random data", value); // Here are the "useful" values
}
plEnd(""); // Shortcut for plEnd("Generate some random values")
plStopAndUninit(); // Stop and uninitialize the instrumentation
return 0;
}
Some C++ performance figures (see here for more details):
More details and an example of remote script is provided here
Execution of unmodified Python programs can be analyzed directly with a syntax similar to the one of cProfile
, as a large part of the instrumentation is automated by default:
In some cases, a manual instrumentation which enhances or replaces the automatic one is desired.
The example below is such an equivalent of the C++ one above but in Python:
#! /usr/bin/env python3
import sys
import random
from palanteer import *
globalMinValue, globalMaxValue = 0, 10
# Handler (=implementation) of the example CLI, which sets the range
def setBoundsCliHandler(minValue, maxValue): # 2 parameters (both integer) as declared
global globalMinValue, globalMaxValue
if minValue>maxValue: # Case where the CLI execution fails (non null status). The text answer contains some information about it
return 1, "Minimum value (%d) shall be lower than the maximum value (%d)" % (minValue, maxValue)
# Modify the state of the program
globalMinValue, globalMaxValue = minValue, maxValue
# CLI execution was successful (null status)
return 0, ""
def main(argv):
global globalMinValue, globalMaxValue
plInitAndStart("example") # Start the instrumentation
plDeclareThread("Main") # Declare the current thread as "Main", so that it can be identified more easily in the script
plRegisterCli(setBoundsCliHandler, "config:setRange", "min=int max=int", "Sets the value bounds of the random generator") # Declare the CLI
plFreezePoint() # Add a freeze point here to be able to configure the program at a controlled moment
plBegin("Generate some random values")
for i in range(100000):
value = int(globalMinValue + random.random()*(globalMaxValue+1-globalMinValue))
plData("random data", value) # Here are the "useful" values
plEnd("") # Shortcut for plEnd("Generate some random values")
plStopAndUninit() # Stop and uninitialize the instrumentation
# Bootstrap
if __name__ == "__main__":
main(sys.argv)
More details and an example of remote script, the same as for the C++ example, is provided here
The complete documentation is accessible inside the repository, and online:
Palanteer is lean, its full installation requires only usual components:
In particular, the C++ single-header instrumentation library requires only C++11 or above.
See here for more details on the requirements per component.
Other dependencies are snapshotted inside this repository, so for information only:
Dependency name | License type | URL |
---|---|---|
Khronos OpenGL API and Extension | MIT | https://www.khronos.org/registry/OpenGL/api/GL |
Dear ImGui | MIT | https://github.com/ocornut/imgui |
stb_image | Public domain | https://github.com/nothings/stb |
Fonts 'Roboto-Medium.ttf' | Apache License, Version 2.0 | https://fonts.google.com/specimen/Roboto |
ZStandard | BSD | https://facebook.github.io/zstd |
Markdeep | BSD | https://casual-effects.com/markdeep |
The instrumentation libraries are under the MIT license.
The viewer and the Python scripting module are under the AGPLv3+.
See LICENSE.md for details.
Even if no major bugs are known and a special care has been taken to test as many cases as possible, this project is young and in beta state.
Your feedback and raised issues are warmly welcome to improve its quality, especially as it aims at improving software quality...