Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Small library helping you with basic stuff like getting metrics out of your code, thread naming, etc.

License

NotificationsYou must be signed in to change notification settings

daedric/commonpp

Repository files navigation

Build status

This reposiroty is being reworked a bit. The readme is not up to date: TBB isnot required anymore and nor is there a metric library

CommonPP

commonpp is a multi purpose library easing very few operations like:

  • Getting metrics out of your program (counter, gauge, statistical descriptionof sample);
  • Naming your threads (and have the custom name appearing inhtop,top,gdb);
  • Have a really simple thread pool on top ofboost::asio;
  • Quick setup ofboost::log;

License

I chose the BSD 2-clause license, so the library can be used in any project,however I'd appreciate any bug fix, pull request and comment.

Dependencies

commonpp depends on Boost and TBB, a C++11 compiler and CMake to be built.It builds on Mac OS X and Linux. It probably build on *BSD but I did not test(yet).

Building

$> make cmake$> make$> make test

On windows

commonpp can be built and used on windows. The prefered way is to usevcpkg.

The required dependencies can be installed using the following command:

$> .\vcpkg.exe install boost:x64-windows tbb:x64-windows hwloc:x64-windows

Then you can generate a Visual Studio solution giving the vcpkg toolchain file.

Please note that only VS2017 has been tested. Also, staticTBB installationcannot be done, so the DLL will need to be in the path to execute binariesdepending oncommonpp.

Why?

Although Boost and TBB are very complete low-level libraries, there are stillbasic features missing, the biggest being getting out metrics out of your code.commonpp will never replace Boost or TBB but instead adds some features thatintegrate well.

Libraries

Core

The core part is mostly utility functions or class.

  • ExecuteOnScopeExit: executes a callable on scope exit. It can be canceled;
  • LoggingInterface: It is a header containing several logging function on topofboost::log. Every record produced withcommonpp is tagged so that itcan be used in a project already usingboost::log (thereforeinit_loggingshould not be called).
  • RandomValuePicker: select a random value in a read only container;
  • FloatingArithmeticTools: Knuth's double comparison functions;
  • Options: an utility class working along with an enum to offer a simpleinterface to manage options, seethe test;
  • There are several string functions to stringify, encode, join, or get aformatted date.

Thread

The thread library is quite small:

  • Thread.hpp contains a function to get/set the current thread name;

  • ThreadPool is a class managing several threads calling theboost::asio::io_service::run member function:

    * It can schedule a callable to be called periodically;* It supports several `io_service`;* A function can be called on thread startup to setup any thread specific  data;
  • Spinlock: should be obvious

  • ThreadTimer: it allows one to get the load of the current thread. This isexperimental;

Metrics

This is the main reason thiscommonpp exists. I often found myself strugglingto get metrics out of my code to monitor performances, behavior, resourceusage, etc. Most of the library counters are based on the RRD ones, theExponentiallyDecayingReservoir is based on the implementation in Codahale aswell as the test.

  • Metrics.hpp is the entry point of the metric library; one should use it toregister counters;
  • MetricTag: This represents the metadata associated with a counter; forinstance if you use Graphite, the tag will be converted in a path(concatenation of all the value separated by a point), if you use InfluxDB,it will be converted in a list of tag;
  • MetricValue: This holds the actual value(s) of a counter.

The counters

There are 3 types of counter:

  • Counter orSharedCounter should be used to represent a value that alwaysincreases and never goes back like a request counter. The actual value sentis the rate at which the counter increases. The SharedCounter can be sharedamong several thread safely.
  • Gauge: It represents an absolute value like a number of active connections.
  • DescStat: Associated with a reservoir, it will describe the distribution ofthe values, for instance, one can use a reservoir to push the time a functionX takes to run, and theStatDesc will give several information like themin, max, variance, quantile, mean, etc.

There is also a helper:

  • TimeScope is an helper to measure the time we spent in the current scope.

Examples

There is a complete example how to use the metric libraryhere

The reservoirs

Currently only one is implemented:ExponentiallyDecayingReservoir.Documentation can be foundthere.

The sinks

  • Graphite: It sends a list ofMetricTag andMetricValue pair in a formatunderstood by Graphite (actually Carbon). As stated before, the values areconcatenated to form the metric path, therefore the order used to insert thetag is important.
  • InfluxDB: It sends the measure name along with all the tags and the valueas described in the documentation. TheMetricTag andMetricValue classwere designed with InfluxDB primarely in mind.

Net

This library for now consist in a HTTP request generator and parser and URLencode and decode functions.

Next step

  • Migrate my other project HTTPP to use commonpp;
  • Add tests.

About

Small library helping you with basic stuff like getting metrics out of your code, thread naming, etc.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp