Jump to content

Tracy Debugger


adrian

Recommended Posts

30 minutes ago, adrian said:

The thing is that I am not sure that I would always want it to auto-clear.

Yes, that's the hard part :) My vote goes also for the checkbox, though currently I'm fine with the auto-auto-clear.

  • Like 1
Link to comment
Share on other sites

@adrian I'm not saying I can keep up with the pace of the module's development, but trying to... I skipped a few versions, but now I'm checking out the latest (2.7.2 - in sync with PW master, eh? :) ) and have two issues with the Template Resources panel:

#1 issue: when file compiling is on, I get:

Spoiler

Error: TemplateResourcesPanel
exception 'ErrorException' with message 'file_get_contents(.../mydomain/views/home_view.php): failed to open stream: No such file or directory' in .../mydomain/site/assets/cache/FileCompiler/site/modules/TracyDebugger/TemplateResourcesPanel.inc:96
Stack trace:
#0 [internal function]: Tracy\Bar->Tracy\{closure}(2, 'file_get_conten...', '/Users/guru/Doc...', 96, Array)
#1 .../mydomain/site/assets/cache/FileCompiler/site/modules/TracyDebugger/TemplateResourcesPanel.inc(96): file_get_contents('/Users/guru/Doc...')
#2 .../mydomain/site/assets/cache/FileCompiler/site/modules/TracyDebugger/TemplateResourcesPanel.inc(184): TemplateResourcesPanel->get_defined_functions_in_file('/Users/guru/Doc...')
#3 .../mydomain/site/assets/cache/FileCompiler/site/modules/TracyDebugger/tracy-master/src/Tracy/Bar.php(127): TemplateResourcesPanel->getPanel()
#4 .../mydomain/site/assets/cache/FileCompiler/site/modules/TracyDebugger/tracy-master/src/Tracy/Bar.php(81): Tracy\Bar->renderPanels()
#5 .../mydomain/site/assets/cache/FileCompiler/site/modules/TracyDebugger/tracy-master/src/Tracy/Debugger.php(266): Tracy\Bar->render()
#6 [internal function]: Tracy\Debugger::shutdownHandler()
#7 {main}

#2 issue: I have the following list of Included Files:

Spoiler

/site/templates/_init.php
/site/templates/helpers/helpers.php
/site/templates/helpers/excerpt.php
/site/templates/helpers/background_cover.php
/site/templates/helpers/pagination_options.php
/site/templates/home.php
/site/templates/views/home_view.php
/site/templates/_init.php
/site/templates/helpers/helpers.php
/site/templates/helpers/excerpt.php
/site/templates/helpers/background_cover.php
/site/templates/helpers/pagination_options.php
/site/templates/home.php
/site/templates/views/home_view.php
/site/templates/_main.php
/site/templates/partials/navigation.php
/site/templates/_init.php
/site/templates/helpers/helpers.php
/site/templates/helpers/excerpt.php
/site/templates/helpers/background_cover.php
/site/templates/helpers/pagination_options.php
/site/templates/home.php
/site/templates/views/home_view.php
/site/templates/_main.php
/site/templates/partials/navigation.php
/site/templates/partials/header_bag/facebook_og.php
/site/templates/_init.php
/site/templates/helpers/helpers.php
/site/templates/helpers/excerpt.php
/site/templates/helpers/background_cover.php
/site/templates/helpers/pagination_options.php
/site/templates/home.php
/site/templates/views/home_view.php
/site/templates/_main.php
/site/templates/partials/navigation.php
/site/templates/partials/header_bag/facebook_og.php
/site/templates/partials/header_bag/twitter_card.php
/site/templates/_init.php
/site/templates/helpers/helpers.php
/site/templates/helpers/excerpt.php
/site/templates/helpers/background_cover.php
/site/templates/helpers/pagination_options.php
/site/templates/home.php
/site/templates/views/home_view.php
/site/templates/_main.php
/site/templates/partials/navigation.php
/site/templates/partials/header_bag/facebook_og.php
/site/templates/partials/header_bag/twitter_card.php
/site/templates/partials/header_bag/ld_json.php
/site/templates/_init.php
/site/templates/helpers/helpers.php
/site/templates/helpers/excerpt.php
/site/templates/helpers/background_cover.php
/site/templates/helpers/pagination_options.php
/site/templates/home.php
/site/templates/views/home_view.php
/site/templates/_main.php
/site/templates/partials/navigation.php
/site/templates/partials/header_bag/facebook_og.php
/site/templates/partials/header_bag/twitter_card.php
/site/templates/partials/header_bag/ld_json.php
/site/templates/views/default_view.php
/site/templates/partials/scripts.php
/site/templates/_init.php
/site/templates/helpers/helpers.php
/site/templates/helpers/excerpt.php
/site/templates/helpers/background_cover.php
/site/templates/helpers/pagination_options.php
/site/templates/home.php
/site/templates/views/home_view.php
/site/templates/_main.php
/site/templates/partials/navigation.php
/site/templates/partials/header_bag/facebook_og.php
/site/templates/partials/header_bag/twitter_card.php
/site/templates/partials/header_bag/ld_json.php
/site/templates/views/default_view.php
/site/templates/partials/scripts.php
/site/templates/_init.php
/site/templates/helpers/helpers.php
/site/templates/helpers/excerpt.php
/site/templates/helpers/background_cover.php
/site/templates/helpers/pagination_options.php
/site/templates/home.php
/site/templates/views/home_view.php
/site/templates/_main.php
/site/templates/partials/navigation.php
/site/templates/partials/header_bag/facebook_og.php
/site/templates/partials/header_bag/twitter_card.php
/site/templates/partials/header_bag/ld_json.php
/site/templates/views/default_view.php
/site/templates/partials/scripts.php

As you can see, files are listed more than once, a lot of them 8 times, but at least 3 times if I'm not mistaken. I use wireRenderFile() to render partials of the page but simple include_once is used too.

  • Like 1
Link to comment
Share on other sites

22 hours ago, tpr said:

Auto-clearing of the Dumps Recorder could be achieved on client-side on each page load:


    $(window).on('unload', function () {
        if ($('a[rel="tracy-debug-panel-DumpsRecorderPanel"]').length && window.Tracy && Tracy.Debug.panels['tracy-debug-panel-DumpsRecorderPanel']) {
            var BRPanel = Tracy.Debug.panels['tracy-debug-panel-DumpsRecorderPanel'];
            // init only if it's not initialized
            if (!$('#tracyDumpEntries').length) {
                BRPanel.init();
            }
            if (window.clearDumps) {
                clearDumps();
            }
        }
    });

Note that I haven't tested this thoroughly but I guess it's safe to use. Maybe there's also a more efficient/nicer way to do this.

Edit: if you use 'beforeunload' event instead 'unload' then you can also see the panel clearing.

Edit2: fixed the code above: init only if required

Hey @tpr - just looking at this in more detail now. I hadn't thought of triggering this client-side, but I think it might make sense - is your thought that it's probably the easiest way to prevent a clear from being called during a PHP redirect or AJAX call? This way it has to be due to a page change or reload?

I think that makes sense, but a couple of problems I have noticed:

  1. It actually only works reliably for me using beforeunload - I think Chrome doesn't accept unload
  2. It uses jQuery, but I want to make Tracy vanilla js only because we can't be sure that jQuery is loaded on the frontend

Nice work of figuring out the need to init the panel if it wasn't ever opened, but I think I have a much easier solution all around which is as simple as:

window.onbeforeunload = function() {
      document.cookie = "tracyClearDumpItems=true;expires=0;path=/";
};

Setting that cookie is actually the key part of the clearDumps() function - with that set, the dumps are removed from the session variable. There is no need to call the entire clearDumps() function because we don't need to remove the dump content from the DOM of the panel instantly - we can rely on the PHP code to do it on the next page load.

Does that make sense to you?

Link to comment
Share on other sites

Ok, thanks to some testing and tweaks from @tpr, the Dumps Recorder now has a "Preserve Dumps" checkbox. When checked, dumps will be preserved until the session is closed. With it unchecked, they will be automatically cleared on page unload. This means it will store all consecutive ajax called dumps, and any dumps during php page redirects (which would be lost with the normal core Tracy dumps panel), but not burden the panel with lots of data unless you specify. The "Clear Dumps" button is there if you want to have a clear slate while testing ajax calls without needing to reload the page to clear.

Let me know if you find any problems or have suggestions for improvements and don't forget to like @tpr's original post suggesting this option.  

Screen Shot 2016-08-24 at 8.26.00 AM.png

  • Like 3
Link to comment
Share on other sites

Curious what you guys think of making the Dumps Recorder panel enabled by default when installing Tracy?

I don't think there are any real disadvantages and it overcomes an issue where users may wonder why the core dumps panel doesn't show their bd() calls (multiple ajax requests, php redirects etc).

Any thoughts?

Actually on this topic, are there any strong feelings in general about the default list of panels?

Link to comment
Share on other sites

Hi @adrian

The Template Resources panel has started to grow fast, so I thought just before it outgrows my notebook's screen, I present a couple of suggestions:

  1. Returns and Class columns can be merged. After all, the info "Object" is redundant.
  2. Long string like a body's HTML code takes up a lot of space in the Value Column. Can you introduce AJAX only loading of such values? Or it can be made collapsable just like arrays/objects. That way initially the column would be narrow when arrays and objects are not expanded. 
  3. It would be nice to have a "collapse/expand all toggle" for arrays/objects.
  4. What if columns can be turned on/off? At least the "Files/Lines" column. It could initially be in its closed state. This is what is used the least, I suppose.
  5. BTW, how about highlighting variables used in one template only and only once? It can help us spot variables no longer used or the developer might want to eliminate such variables by using expressions instead.
  6. How about jump links at the top to sections of the panel (to variables, constants, functions, included files)?
  7. The first two lines could be merged into one paragraph (These are all the... If you are looking...) to save some more space.
  8. "Panel generated in 183.67 ms Panel content size: 1.1 MB" could also be merged into one line and could be placed at the top, so no need to scroll down...

Hope you find these suggestions useful.

The following is just a screenshot to show what it currently looks like on my machine.

template resources screenshot 2016-08-24.png

Edited by szabesz
typo
  • Like 1
Link to comment
Share on other sites

Thanks @szabesz for your input on this - definitely some good ideas.

A couple of quick comments/questions:

  • Could you PM me the html from that panel - I'd like to see why it is so large. I can already see that I am not getting the array of ML titles - it is still returning an object, but based on the size, I am guessing there are some other objects also in the Value column.
  • Rather than jumplinks to sections, would you be ok with collapsed sections, like the PW Info panel?
  • I like the idea of highlighting variables only used once - it was something I had also been thinking about. Looking at your $authors variable - is that actually one of those things that should be highlighted - is it really just defined there and never actually used, or is it used twice on that line, or there a problem with my detection of it only being used on that one line?
  • "It would be nice to have a "collapse/expand all toggle" for arrays/objects" - what arrays/objects don't have this already? I thought it should be all.
  • Not sure about making strings collapsible - this is a core Tracy feature I am using to make arrays/objects collapsible. You can set the length of the string in the config settings though (default is 150) - does that help?
  • Also not sure about turning columns on/off - does the width of the panel matter that much, or is it more the height that important?

Also curious what others think of the recent additions to this panel - is it getting to be too complicated? I haven't tested with complex pages with lots of template defined vars, so maybe it does need some refining - seeing your 1.1MB is not a good sign, but I think that can be dealt with so long as I convert all objects to arrays of the relevant properties/values rather than the full object.

  • Like 1
Link to comment
Share on other sites

@adrian

  • "Could you PM me the html from that panel": I can, however, how about installing https://github.com/NinjasCL/pw-ghost by @clsource ? This is what I'm refactoring to my needs currently. My version is still very similar to his, so you can use it for testing.
  • "collapsed sections": fiddling with collapsing is slow, I think simple links are more efficient.
  • "$authors" is never used (it is in the original profile too, I have not yet removed it) I do not know if the detection fails or not sometimes, I have not yet spent too much time checking the results of it.
  • "collapse/expand all toggle": sorry for my confusing words. I was talking about one toggle button to collapse/expand all at once. Initially all of them are closed, right? I do not seem to remember... :)
  • "You can set the length of the string in the config settings though (default is 150) - does that help?": more or less. It is informative to see 150. I will experiment with it. I'm just trying to save space somehow :)
  • "...turning columns on/off - does the width of the panel matter that much...": the width. We have nearly reached the width of my Air's screen/viewport (1440px). By turning on/off I actually meant hide/unhide.
Link to comment
Share on other sites

1 hour ago, adrian said:

users may wonder why the core dumps panel doesn't show their bd() calls (multiple ajax requests, php redirects etc).

If you enable it by default, you might want to remove the the core version altogether, so there will be no confusion at all. We have something more advanced, no need for the plain version, I suppose.

Link to comment
Share on other sites

38 minutes ago, szabesz said:

config settings though (default is 150) - does that help?": more or less. It is informative to see 150. I will experiment with it. I'm just trying to save space somehow :)

I have changed it, and it does not make a difference. I mean I always get 150 characters, even if I set it to something else.

Another issue it the column content of the string. On this page it gets really wide (last colum can hardly be seen):

template resources screenshot 2016-08-24-B.png

And thanks to Apple's decision to hide scrollbars by default, I often do not even notice that a window's content can be scrolled. That is my own grief, however, I just wanted to mention that on a Mac it can be even more confusing when the table is cut off right before the last column.

Edited by szabesz
typo
  • Like 1
Link to comment
Share on other sites

6 minutes ago, szabesz said:

I have changed it, and it does not make a difference. I mean I always get 150 characters, even if I set it to something else.

Thanks - looks like I forgot to pass the length and depth settings to the dump method. I'll sort that out in the next version. The depth should actually make a huge difference to the size of the panel.

7 minutes ago, szabesz said:

Another issue it the column content of the string. On this page it gets really wide (last colum can hardly be seen):

I'll see what I can do about that - looks like I need to force it to wrap.

 

8 minutes ago, szabesz said:

And thanks to Apple's decision to hide scrollbars by default

Tell me about it - sometimes they try to simplify to the point of losing functionality!

  • Like 1
Link to comment
Share on other sites

7 minutes ago, adrian said:
16 minutes ago, szabesz said:

And thanks to Apple's decision to hide scrollbars by default

Tell me about it - sometimes they try to simplify to the point of losing functionality!

I have just turned this default behavior off. I do not know why I haven't done so earlier.

As for the other issues: thanks for striving for perfection. We are in the same boat :P

Edited by szabesz
"I do not know why I haven't done so earlier." Now I know! The UI looks quite ugly this way :(
  • Like 1
Link to comment
Share on other sites

On 8/23/2016 at 1:52 AM, bernhard said:

hey adrian,

what do you think of a panel to switch off certain modules. like the panel selector but not for panels but modules. so you could switch off modules during development to make sure it is not related to that module...

no idea how hard that would be - just wanted to share the idea and hear your thoughts :)

This panel has been added to the latest version!

Just like the core module disable option, it is only available in PW's advanced mode and only for autoload modules.

Please don't use this on a live site - it's not a problem with this panel, but rather the core module disable flag. It can break your site quite easily with some modules. For example, disabling the ProcessWireUpgradeCheck module results in a fatal error and the only way to fix is to manually remove the disable flag in the database. I am not sure whether Ryan might be able to fix (https://github.com/ryancramerdesign/ProcessWire/issues/1990) this in the core, or in the ProcessWireUpgradeCheck module itself, but it's definitely a good indicator that you need to be careful and savvy to be able to fix things if they go wrong!

Still, hopefully you will find it useful - it is certainly a lot easier than going through all your modules in the admin and disabling them there.

Let me know how it works out for you.

Screen Shot 2016-08-25 at 3.40.15 PM.png

  • Like 3
Link to comment
Share on other sites

The latest version has several tweaks, and one potentially valuable new config setting. The debug mode panel has the option to NOT show the debug tools when debug mode is off. This might be nice on a production site where you have forced superuser into development mode - you still like having the reminder to confirm that debug mode is actually off, but you don't want all the tools displayed - it is potentially a big performance improvement on some servers. 

Screen Shot 2016-08-25 at 10.09.23 PM.png

  • Like 1
Link to comment
Share on other sites

I like the module disabler, thanks! In my module I implemented an enable/disable toggle, and I think it would be a nice thing if such feature would be in all modules (in pw core). This would allow toggling a module state easily, if the developer has implemented this feature. Currently one has to uninstall a module but doing so will remove module settings so if you reinstall later you have to configure again. WP has such feature and I often miss this from PW.

  • Like 2
Link to comment
Share on other sites

Thanks Adrian for the new panel!

8 hours ago, adrian said:

It can break your site quite easily with some modules. For example, disabling the ProcessWireUpgradeCheck module

This one sounds "scary". At least, a real pita situation can emerge out of the blue, so I was wondering if we could be somehow warned about potential issues. At least a general note, but in case of known issues (such as this ProcessWireUpgradeCheck) it should be somehow marked, or even removed from the list if it is no use disabling it.

One more thing I've been thinking of it recently but this new panel has reminded me to mention it: There are so many panels already that it would be nice to have some sort of short description of them in the module's Settings. Maybe the simple (asm)select is not the one that fits the bill anymore, but something else that supports accompanying labels/tooltips. This addition would be especially great for newcomers.

Edited by szabesz
First, I posted a half-a-reply by mistake somehow, maybe by pressing ENTER + something else? Arghh, how much I hate such features....
  • Like 1
Link to comment
Share on other sites

On 8/26/2016 at 0:07 AM, szabesz said:

This one sounds "scary". At least, a real pita situation can emerge out of the blue, so I was wondering if we could be somehow warned about potential issues. At least a general note, but in case of known issues (such as this ProcessWireUpgradeCheck) it should be somehow marked, or even removed from the list if it is no use disabling it.

Yeah, it can be a real PITA. I am not too worried at the moment as the functionality requires PW's advanced mode and I am hoping Ryan might have some solution to that issue I posted. This panel is not adding new functionality - it's really just making it easier to disable lots of modules at once / in the once place. If Ryan has no solution, then I might consider removing modules from the list that have know issues (like the ProcessWireUpgradeCheck one).

On 8/26/2016 at 0:07 AM, szabesz said:

One more thing I've been thinking of it recently but this new panel has reminded me to mention it: There are so many panels already that it would be nice to have some sort of short description of them in the module's Settings. Maybe the simple (asm)select is not the one that fits the bill anymore, but something else that supports accompanying labels/tooltips. This addition would be especially great for newcomers.

Agreed - I'll start thinking about this.

  • Like 2
Link to comment
Share on other sites

3 hours ago, adrian said:

I am not too worried at the moment as the functionality required PW's advanced mode and I am hoping Ryan might have some solution to that issue I posted. This panel is not adding new functionality - it's really just making it easier to disable lots of modules at once / in the once place. If Ryan has no solution, then I might consider removing modules from the list that have know issues (like the ProcessWireUpgradeCheck one).

I have just looked up the forum to learn more about Advanced Mode, which is recommended to be turned off, so for folks like me this new panel is not really something I might ever use if one can easily run into unwanted situations (which might easily happen without a deeper understanding of ProcessWire, at least that is what I have gathered).

Something like @tpr suggested above could be a lot more helpful, being a safer alternative to this current approach. I mean, I can see that this panel can be useful too sometimes, but for folks like me (who is not a hard core ProcessWire developer), it seems to be out of reach, so to speak.

Thanks for the panel anyway! Even if it's not for me, I have at least learnt a few things about ProcessWire's Advanced Mode :)

Link to comment
Share on other sites

Working on this module is starting to become a full time job!

 

2 hours ago, szabesz said:

Something like @tpr suggested above could be a lot more helpful, being a safer alternative to this current approach.

Unfortunately I don't think it's a simple as that for some modules - for example you can't simply disable a fieldtype without wreaking havoc. I still think this panel is useful - I am just hoping Ryan can sort out that issue which I think is related to just those modules using a separate config file (like ProcesswireUpgradeCheck).

 

On 8/24/2016 at 10:09 AM, szabesz said:

BTW, how about highlighting variables used in one template only and only once? It can help us spot variables no longer used or the developer might want to eliminate such variables by using expressions instead.

This has just been implemented in the latest version. This is Just a first attempt - any variable that is only used once is highlighted with the orange warning color.

Screen Shot 2016-08-26 at 10.40.19 AM.png

 

Other significant changes in the latest version.

  • Fixed a problem with the Validator plugin that was introduced 4 days ago by a new requirement (the user_agent needs to be supplied in the post request) from validator.nu (https://github.com/validator/validator/commit/a6afb4f34402bce421df5102de313ec76295a55f#diff-5f739a043bdc345584b06cb39a7679aaR259)
     
  • Make it easy to pass maxDepth and maxLength options to bd() calls. This can be very handy when you have a deep array or very long string that you need to see more of without changing the defaults of maxDepth:3 and MaxLength:150 which can cause problems with PW objects if you go too high.
    bd($myArr, 'My Array', array('maxDepth' => 7, 'maxLength' => 0));

    Note that setting to '0' means no limit.

 

I also I just wanted to note how useful the "Preserve Dumps" checkbox in the Dumps Recorder panel is - lots of times when doing module development in particular I found that bd() calls weren't showing up - I think it often has to do with the redirects or the call being made before the panel is ready or something. Now with this feature, even if it doesn't show initially, just reload the page and it will be there!

  • Like 3
Link to comment
Share on other sites

31 minutes ago, adrian said:

Unfortunately I don't think it's a simple as that for some modules - for example you can't simply disable a fieldtype without wreaking havoc. I still think this panel is useful - I am just hoping Ryan can sort out that issue which I think is related to just those modules using a separate config file (like ProcesswireUpgradeCheck).

Ok, thanks, I get it. I'm with you :) This topic is bit too advanced for me anyway, I was just trying to figure out how to handle this...

34 minutes ago, adrian said:

I also I just wanted to note how useful the "Preserve Dumps" checkbox in the Dumps Recorder panel is

So a big praise to @tpr for the idea, and to you too, of course :D

  • Like 1
Link to comment
Share on other sites

38 minutes ago, adrian said:

Working on this module is starting to become a full time job!

 

I was thinking of this too. It is incredible what you have achived so far. You might want to charge for the module in the future. How about a light and a pro version? But psst! It wasn't me who gave you the idea :P

  • Like 1
Link to comment
Share on other sites

  • adrian pinned and locked this topic
  • adrian unpinned and pinned this topic
Guest
This topic is now closed to further replies.
×
×
  • Create New...