GithubHelp home page GithubHelp logo

gamernetwork / yolk-profiler Goto Github PK

View Code? Open in Web Editor NEW
1.0 11.0 1.0 20 KB

A simple profiling library for benchmarking code execution speed, memory usage and database queries

License: MIT License

PHP 77.64% CSS 11.27% JavaScript 11.09%

yolk-profiler's Introduction

Want to work for Gamer Network? We are hiring!

Yolk Profiler

Scrutinizer Code Quality

A simple profiling library for benchmarking code execution speed, memory usage and database queries.

Requirements

This library requires only PHP 5.4 or later and the Yolk Contracts package (gamernetwork/yolk-contracts).

Installation

It is installable and autoloadable via Composer as gamer-network/yolk-profiler.

Alternatively, download a release or clone this repository, and add the \yolk\profiler namespace to an autoloader.

License

Yolk Profiler is open-sourced software licensed under the MIT license.

Quick Start

use yolk\profiler\GenericProfiler;

$profiler = new GenericProfiler();

$profiler->start('Op 1');
lengthyOperation1();
$profiler->stop('Op 1');

$profiler->start('Op 2');
lengthyOperation2();
$profiler->stop('Op 2');

// profile a query
$profiler->start('Query1');
doDatabaseQuery($sql, $params);
$profiler->stop('Query1');

$profiler->query($sql, $params, $profiler->getElapsed('Query1'));

// add some additional info
$profiler->meta('get', $_GET);
$profiler->meta('post', $_POST);

$profiler->stop();

// assign a configuration object to the profiler to be included in the report
$profiler->config(Config $config);

// get a report
print_r(
	$profiler->getData()
);

Timers

GenericProfiler makes use of the GenericTimer class, which may also be used independently to record periods of time at microsecond resolution.

use yolk\profiler\GenericTimer;

$t = new GenericTimer();

$t->start();
$t->isRunning();	// returns true
$t->getElapsed();	// returns microseconds since last call to start()
$t->stop();
$t->isRunning();	// returns false
$t->getTotalElapsed();	// returns microseconds between all calls to start()/stop()

Debug Bar

An HTML debug bar is provided that can be rendered to a web page and provide a pretty representation of the Profiler's data.

The relevant HTML can be obtained by calling the getHTML() method on the profiler and can then be inserted into a template, send to the client, etc.

The debug bar source is self-contained and is designed to be placed just before the closing </body> tag.

yolk-profiler's People

Contributors

simon-downes avatar

Stargazers

 avatar

Watchers

Dave Hansen avatar  avatar James Cloos avatar  avatar  avatar Vicky Stephens avatar Faye Butler avatar Sam Hayes avatar Izzy Smillie avatar Igor avatar  avatar

Forkers

simon-downes

yolk-profiler's Issues

Undefined variable $report

Sometimes this line breaks the page because the $report variable is undefined. This seems pretty sporadic and I've had what appears to be the same request yield different results, but I'm guessing it's a case of files being included in the wrong order

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.