GithubHelp home page GithubHelp logo

dev's People

Contributors

dependabot[bot] avatar jmalloc avatar koden-km avatar langabi avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

langabi

dev's Issues

Suggestion - debug_backtrace() replacements

Suggestion, for utility functions - I put them in Trace.php. Almost-dropin replacements for PHP debug_backtrace() and debug_print_backtrace(), useful for retrieving backtrace without having to throw a fatal exception. Happy to create as pull request, but quite possible I missed something vital in writing these.

    /**
     * Replacement for debug_print_backtrace() PHP function. Returns the current stack as a string
     * 
     * Call as `yield Trace::debug_print_backtrace();`
     */
    public static function debug_print_backtrace() : \Generator
    {
        /** @var Trace $trace */
        $trace = \class_exists(\Recoil\Dev\Instrumentation\Trace::class) ? yield \Recoil\Dev\Instrumentation\Trace::install() : null;
        $e = new Exception();
        $trace->updateStackTrace($e);
        return $e->getTraceAsString();
    }

    /**
     * Replacement for debug_backtrace() PHP function. Returns the current stack as an array
     * 
     * Call as `$backtrace = yield Trace::debug_backtrace();`
     */
    public static function debug_backtrace() : \Generator
    {
        /** @var Trace $trace */
        $trace = \class_exists(\Recoil\Dev\Instrumentation\Trace::class) ? yield \Recoil\Dev\Instrumentation\Trace::install() : null;
        $e = new Exception();
        $trace->updateStackTrace($e);
        return $e->getTrace();
    }

Can't see how to get the trace

I'm trying to use this for a Recoil application I'm debugging. It looks super useful! It's just really hard to see where to start. In particular, the "examples" folder is I think out of date, now that the Autoloader gets automatically loaded.

So from what I can see, I'm getting the instrumentation loaded and run (the Autoloader is being called for each application class that is loaded), but I don't know how to get the instrumented stack trace. I'm still getting the default PHP stack trace on an exception.

Any tips how to use this package? A quickstart in the README would be amazing. Happy to write it once I've worked it out myself!

Kahlan integration.

@ezzatron has been promoting Kahlan as an alternative to Peridot due to it's wider adoption and likelyhood that it's capable of being extended to run tests as coroutines in much the same way as Peridot.

This doesn't necessitate porting the recoil/dev's own test suite to Kahlan, but that might also be desirable.

Deadlock protection.

In development mode, it would be useful if strands had some kind of deadlock protection. Some primitives might be:

  • strands that are waiting for each other
  • nested calls to Kernel::wait()

unit test example for coroutines?

I'm trying to write PHPUnit tests for classes that contain coroutines, and I'm having trouble getting the coroutines to return the value of the full method instead of the just nested yielded function. I've tried calling current() on the results, or just putting it in a foreach loop, but I'm only getting the value of the yielded line inside the method, not the result of the method itself. Are there any examples of how to run unit tests on coroutines without spinning up the Recoil kernel? If I'm not being clear enough let me know and I can post an example.

Meaningful stack traces.

It might be possible to get a meaningful stack trace using some combination of PHP 7 assert, debug_backtrace and __destruct. Assert would remove the trace in production code, eliminating the overhead. It's not pretty but it's better than nothing.

Some pseudocode:

function trace()
{
    $frame = debug_backtrace()[$this_frame - 1];
    $strand = yield Recoil::strand();

   return new class ($strand)
   {
        function __construct($strand, $frame) { $strand->pushTrace($frame); }
        function __destruct() { $this->strand->popTrace(); }
   }
}

Then, in the coroutines you want to trace:

function someCoroutine() : Generator
{
    assert($trace = yield trace());

    // do work ....
}

Instrument code at install-time.

For dependencies, there's no reason to instrument code while auto-loading. It could be done at install time instead. The benefits of caching without having to deal with invalidation.

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.