Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question : Turn on Profiler #6

Closed
harikt opened this issue Mar 12, 2016 · 4 comments
Closed

Question : Turn on Profiler #6

harikt opened this issue Mar 12, 2016 · 4 comments

Comments

@harikt
Copy link
Contributor

harikt commented Mar 12, 2016

Hi Paul,

Thank you for your good work.

I was wondering is there a way to turn on the profiler of ExtendedPdo . From the AtlasContainer it looks the ExtendedPdo is instantiated there.

Is there a way to view the query executed some how other than via the ExtendedPdo profiler ?

Thank you.

@pmjones
Copy link
Contributor

pmjones commented Mar 12, 2016

Good question, and something I had not considered. It can be done but it's ugly. You have to go through the Mapper to the Table to get the underlying connection. E.g.:

$conn = $atlas->getMapper(Mapper::CLASS)->getTable()->getReadConnection();
$conn->setProfiler(...);
$conn->getProfiler()->setActive(true);
// ...
$conn->getProfiler()->setActive(false);

That should probably be made easier. :-/

@harikt
Copy link
Contributor Author

harikt commented Mar 12, 2016

I found another way. But still not satisfied.

This piece of code is written on AtlasContainer and probably we can add a function turnOnProfiler() which can set the profiler and make the connection active . Some constraints apply here for the correct functionality though.

    protected function setConnectionLocator(array $args)
    {
        $this->connectionLocator = new ConnectionLocator();
        $this->connectionLocator->setDefault(function () use ($args) {
            $pdo = new ExtendedPdo(...$args);
            $pdo->setProfiler($this->getProfiler());
            $pdo->getProfiler()->setActive(true);
            return $pdo;
        });
    }

    public function getProfiler()
    {
        if (! $this->profiler) {
            $this->profiler = new Profiler();
        }
        return $this->profiler;
    }

Update :

It looks don't need to hack on this, it can be added via calling getConnectionLocator() and getDefault() connection on Locator and then setting the profiler and turning on.

@pmjones
Copy link
Contributor

pmjones commented Feb 24, 2017

It looks don't need to hack on this, it can be added via calling getConnectionLocator() and getDefault() connection on Locator and then setting the profiler and turning on.

I'm taking this to mean that the issue can be closed; let me know if I'm wrong about that. :-)

@pmjones pmjones closed this as completed Feb 24, 2017
@harikt
Copy link
Contributor Author

harikt commented Feb 25, 2017

I wished if there is an easy way to turn on / off profiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants