GithubHelp home page GithubHelp logo

nicolasventer / breakpoint-detector Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 150 KB

C++ Breakpoint Detector

License: MIT License

C++ 100.00%
breakpoint-detection cpp header-only single-header cpp-library

breakpoint-detector's Introduction

Breakpoint Detector

Description

Breakpoint Detector is a single header c++ library that allows you to detect when the execution has been paused by a breakpoint with the ability to retrieve the elapsed time while the execution was paused.

Features

  • Detect breakpoint
  • Brekapoint detection configurable
  • Callback on detection
  • Multiple callback supported

Installation

Include the file BreakpointDetector.hpp in your project.

c++11 or later compilation required.
No external dependencies.

Example

Screenshot of example.cpp: breakpointExample

Show content of example.cpp
#include <chrono>
#include <iostream>
#include <thread>

#include "BreakpointDetector.hpp"

int main()
{
	// the breakpoint detection is immediately done at start

	using namespace std::chrono_literals;

	breakpoint_detector::addDetectedBreakpointCallback(breakpoint_detector::example::displayDetectedBreakpoint);

	std::this_thread::sleep_for(200ms);
	std::cout << "Hello" << std::endl;
	std::this_thread::sleep_for(200ms);
	std::cout << "Nice to meet you" << std::endl;
	std::this_thread::sleep_for(200ms);
	std::cout << "Bye" << std::endl;
	std::cout << "Total breakpoint duration: " << breakpoint_detector::getBreakpointTotalDuration().count() << "ms" << std::endl;
	return 0;
}

Possible output:

Hello
Breakpoint detected: 3001ms
Nice to meet you
Breakpoint detected: 1695ms
Bye
Total breakpoint duration : 4696ms

Usage

#define DECTECTED_BREAKPOINT_PARAM const std::chrono::milliseconds& breakpointDuration
// parameters are captures
#define DECTECTED_BREAKPOINT_LAMBDA(...) [__VA_ARGS__](DECTECTED_BREAKPOINT_PARAM)
using DetectedBreakpointCallback = std::function<void(DECTECTED_BREAKPOINT_PARAM)>;

namespace breakpoint_detector
{
	// add a function to call on breakpoint detection
	static void addDetectedBreakpointCallback(DetectedBreakpointCallback detectedBreakpointCallback);

	// sum of all detected breakpoint duration
	static std::chrono::milliseconds getBreakpointTotalDuration();

	// set the minimum duration from which a breakpoint is detected
	template <class _Rep, class _Period>
	void setBreakpointDetectionDuration(const std::chrono::duration<_Rep, _Period>& breakpointDetectionDuration_);

	// set the duration used for periodic check of a breakpoint
	template <class _Rep, class _Period> void setCheckDuration(const std::chrono::duration<_Rep, _Period>& checkDuration_);

	namespace example
	{
		// example of detected breakpoint callback that displays the duration of the detected breakpoint
		static void displayDetectedBreakpoint(DECTECTED_BREAKPOINT_PARAM);

	} // namespace example
} // namespace breakpoint_detector

Warning: the breakpoint will not be immediately detected.

Licence

MIT Licence. See LICENSE file. Please refer me with:

Copyright (c) Nicolas VENTER All rights reserved.

breakpoint-detector's People

Contributors

nicolasventer avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.