License, Readme, comments
This commit is contained in:
parent
ba0aa95117
commit
da9a917945
2
LICENSE
2
LICENSE
@ -58,7 +58,7 @@ APPENDIX: How to apply the Apache License to your work.
|
|||||||
|
|
||||||
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
||||||
|
|
||||||
Copyright [2023] [Marcel Bandić]
|
Copyright [2023] [Marcel Bandić - marcelb96@yahoo.com]
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
61
README.md
61
README.md
@ -0,0 +1,61 @@
|
|||||||
|
|
||||||
|
# A library for tracking statistics and metrics
|
||||||
|
|
||||||
|
A simple library for measuring incremental parameters in C++ programs based on the key-value principle.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Object oriented
|
||||||
|
- Thread safe
|
||||||
|
- Easy access to counters using the [] operator
|
||||||
|
- Simple incrementing of counters using the ++ operator
|
||||||
|
- Initial setup of the list of counters and values
|
||||||
|
- List of counter names
|
||||||
|
- Retrieving the status of all counters
|
||||||
|
- Reset all counters
|
||||||
|
- Retrieving the state of all counters and resetting the counters
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Just download the latest release and unzip it into your project. You can turn it on with:
|
||||||
|
|
||||||
|
```
|
||||||
|
#include "metrics/lib/metrics.hpp"
|
||||||
|
using namespace marcelb;
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```c++
|
||||||
|
// init
|
||||||
|
Metrics stats;
|
||||||
|
// operator [] and increment ++
|
||||||
|
stats["access"]++;
|
||||||
|
// print couter access
|
||||||
|
cout << stats["access"];
|
||||||
|
// get counters names
|
||||||
|
auto listCounterNames = stats.keys();
|
||||||
|
// get all couters
|
||||||
|
auto data = stats.get_data();
|
||||||
|
// reset counters
|
||||||
|
stats.clear();
|
||||||
|
// set counters
|
||||||
|
map<string, uint> MyStats = {{"access", 3},{ "error", 0}};
|
||||||
|
stats.set(MyStats);
|
||||||
|
// get and clear all counters
|
||||||
|
auto dataWithClear = stats.get_data_and_clear();
|
||||||
|
```
|
||||||
|
## License
|
||||||
|
|
||||||
|
[APACHE 2.0](http://www.apache.org/licenses/LICENSE-2.0/)
|
||||||
|
|
||||||
|
|
||||||
|
## Support & Feedback
|
||||||
|
|
||||||
|
For support and any feedback, contact the address: marcelb96@yahoo.com.
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
Contributions are always welcome!
|
||||||
|
|
||||||
|
Feel free to fork and start working with or without a later pull request. Or contact for suggest and request an option.
|
||||||
|
|
@ -11,28 +11,34 @@ using namespace std;
|
|||||||
|
|
||||||
namespace marcelb {
|
namespace marcelb {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Klasa za mjerenje proizvoljne statistike
|
* A class for measuring arbitrary statistics
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Metrics {
|
class Metrics {
|
||||||
mutex io;
|
mutex io;
|
||||||
map<string, uint> counters;
|
map<string, uint> counters;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor, without predefining the name of the counter
|
||||||
|
*/
|
||||||
Metrics ();
|
Metrics ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor, with predefined counters from the passed object
|
||||||
|
*/
|
||||||
Metrics (map<string, uint> _counters);
|
Metrics (map<string, uint> _counters);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Operator[] za pristup svakoj brojaču mjerenja
|
* Operator[] to access each measurement counter
|
||||||
*/
|
*/
|
||||||
uint& operator[](const string& key) {
|
uint& operator[](const string& key) {
|
||||||
return counters[key];
|
return counters[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Operator++ za inkrementalno povećanje brojača mjerenja
|
* Operator++ to increment the measurement counter incrementally
|
||||||
*/
|
*/
|
||||||
Metrics& operator++ (int n) {
|
Metrics& operator++ (int n) {
|
||||||
lock_guard<mutex> _io(io);
|
lock_guard<mutex> _io(io);
|
||||||
@ -40,27 +46,30 @@ class Metrics {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to set the counter from the passed object
|
||||||
|
*/
|
||||||
void set(map<string, uint> _counters) {
|
void set(map<string, uint> _counters) {
|
||||||
counters = _counters;
|
counters = _counters;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metoda za resetiranje brojača
|
* A method to reset the counter
|
||||||
*/
|
*/
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metoda koja vraća vektor stringova svih naziva brojača
|
* A method that returns a vector os strings of all counter names
|
||||||
*/
|
*/
|
||||||
vector<string> keys();
|
vector<string> keys();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metoda vraća map<string, uint> svih mjerenja
|
* The method returns a map<string, uint> of all measurements
|
||||||
*/
|
*/
|
||||||
map<string, uint> get_data();
|
map<string, uint> get_data();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metoda vraća map<string, uint> svih mjerenja i resetira brojače
|
* The method returns a map<string, uint> of all measurements and resets the counters
|
||||||
*/
|
*/
|
||||||
map<string, uint> get_data_and_clear();
|
map<string, uint> get_data_and_clear();
|
||||||
|
|
||||||
|
@ -16,7 +16,23 @@ int main() {
|
|||||||
cout << " error " << metrika["error"] << endl;
|
cout << " error " << metrika["error"] << endl;
|
||||||
cout << " access " << metrika["access"] << endl;
|
cout << " access " << metrika["access"] << endl;
|
||||||
|
|
||||||
|
// // init
|
||||||
|
// Metrics stats;
|
||||||
|
// // operator [] and increment ++
|
||||||
|
// stats["access"]++;
|
||||||
|
// // print couter access
|
||||||
|
// cout << stats["access"];
|
||||||
|
// // get counters names
|
||||||
|
// auto listCounterNames = stats.keys();
|
||||||
|
// // get all couters
|
||||||
|
// auto data = stats.get_data();
|
||||||
|
// // reset counters
|
||||||
|
// stats.clear();
|
||||||
|
// // set counters
|
||||||
|
// map<string, uint> MyStats = {{"access", 3},{ "error", 0}};
|
||||||
|
// stats.set(MyStats);
|
||||||
|
// // get and clear all counters
|
||||||
|
// auto dataWithClear = stats.get_data_and_clear();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user