Debugging, Monitoring andProfilingFabrizio Brancafabrizio (dot) branca (at) aoemedia (dot) deTwitter: @fbrnc
This talk is…   •   sharing some best practices   •   sharing some tools with you   •   an (incomplete) checklist   •   a ...
What is this all about?   • Make your website run smoothly!        • during development…        • and when the site is onl...
This talk is about   How to…   • avoid errors   • detect errors   • deal with errors   • notify yourself when errors have ...
It„s all about bugsFabrizio Branca
It„s all about bugs   Everybody creates bugs. Nobody is perfect.   A high percentage of coding time goes into   • searchin...
Automating   • Automatize error recognition        • Use proper tools   • Automatize error reporting        • Route detail...
Bugs   • Avoid bugs        • through programming style   • Spot bugs fast        • “Safety nets”: Unit tests, Assertions  ...
Avoid bugs• Use a proper IDE  • Syntax checks  • Code Completion
Coding style   •   Cover all cases: No if without else!   •   Use type hints wherever possible   •   Stick to patterns   •...
What does PHP offer?   • log_errors   • display_errors   • error_log   Set values in   • php.ini   • .htaccess / vhost con...
What does TYPO3 offer?   •   devLog, sysLog, Tslog   •   devIpMask   •   Deprecation log   •   Page not found / Page unava...
Deal with exceptions (I)   How to react when an exception has     occurred?   • Don„t display any details to the user!   •...
Page not foundFabrizio Branca
Page unavailableFabrizio Branca
Deal with exceptions (II)   Handle exceptions within your controllers.   Notify yourself:   • write a message to devLog   ...
Exception HandlerFabrizio Branca
Bug detection   • Bugs are harder to fix the later they are     detected   • Bugs become harder to diagnose the     furthe...
Bug detection with assertions   • Make sure that variables contain what you     expect at any time (e.g. after calling a f...
Bug detection with assertions   • Assertions are easy to use.   • Don„t assume anything, check it!        • Example: ini_s...
Bug detection with assertions   See       EXT:pt_tools/res/staticlib/class.tx_pttools_assert.php   or       build your own...
t3lib_div::devLog()Fabrizio Branca
t3lib_div::sysLog()   Decides by configuration how to handle     syslog messages   • send mail   • write to log file   • w...
Custom SysLog Handler   See       EXT:tcaobjects/res/class.tx_tcaobjects_syslog.phpFabrizio Branca
SysLog notification mailmsg: Assertion "isValidUid" failed!extKey: pt_toolsseverity: 3exceptionClass: tx_pttools_exception...
$TYPO3_DB-   >debug_check_recordset()   • Check all database queries   • Debug_check_recordset takes care of     writing l...
TSlogFabrizio Branca
$TT->push() / ->pull()   Use the timetrack object to keep track of    what happens in your code.Fabrizio Branca
Reports moduleFabrizio Branca
Reports module   Write your own reports   Examples:   • Table size   • Outdated extensions (extension manager)   • TCA Int...
Define a strong api   • Provide interfaces for hooks.   • Allow alternatives (pagerStrategy,     viewClass,…)Fabrizio Branca
Keep an eye on the logs…   • Webserver        • Apache error log        • PHP error log   • TYPO3        • Log module (Cor...
Keep an eye on the logs…   • External tools        • Google Webmaster Tools        • Wget        • Piwik   • MySQL        ...
Log ModuleFabrizio Branca
Google Webmaster ToolsFabrizio Branca
Let tools do the analysis   •   PHP   •   TSFE   •   TypoScript   •   jQuery code   •   HTML   •   CSS   •   RSSFabrizio B...
Visualizing xdebug profiling
Visualizing xdebug profiling
Visualizing pdepend xml
jQuery Lint   „Runtime Reporter“   http://james.padolsey.com/javascript/jquery-lint/Fabrizio Branca
TypoScript Check (lint)   Proof of concept!   Xclassing tslib_content:   function stdWrap($content,$conf) {          $this...
Tick
TickFabrizio Branca
Tick
Use validators   Use validators for validating   • HTML   • CSS   • RSS   Keep an eye on editor„s contentFabrizio Branca
Spot performance killers   • Use USER_INTs only if really needed.   • Create links with cHashes   • Avoid putting USER_INT...
Monitoring   • Configure your TYPO3 instances to notify     you when errors occur.   • Use Monitoring tools (e.g. Nagios, ...
Pingdom
Maintainance   • Delete old temp files       find ../htdocs/typo3temp -type f -mtime +28 -delete   • Delete deleted record...
Debugging, Monitoring and Profiling in TYPO3
Debugging, Monitoring and Profiling in TYPO3
Upcoming SlideShare
Loading in...5
×

Debugging, Monitoring and Profiling in TYPO3

6,194

Published on

Slides of Fabrizio Branca's talk on the TYPO3 Developer Days 2010 (T3DD10)

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,194
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
22
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Debugging, Monitoring and Profiling in TYPO3

  1. 1. Debugging, Monitoring andProfilingFabrizio Brancafabrizio (dot) branca (at) aoemedia (dot) deTwitter: @fbrnc
  2. 2. This talk is… • sharing some best practices • sharing some tools with you • an (incomplete) checklist • a reminder (hopefully)Fabrizio Branca
  3. 3. What is this all about? • Make your website run smoothly! • during development… • and when the site is online • “Smoothly” is • No bugs (unexpected behaviour) • Stability • PerformanceFabrizio Branca
  4. 4. This talk is about How to… • avoid errors • detect errors • deal with errors • notify yourself when errors have occurredFabrizio Branca
  5. 5. It„s all about bugsFabrizio Branca
  6. 6. It„s all about bugs Everybody creates bugs. Nobody is perfect. A high percentage of coding time goes into • searching for bugs • fixing bugs Increase your productivity by reducing this time!Fabrizio Branca
  7. 7. Automating • Automatize error recognition • Use proper tools • Automatize error reporting • Route detailed error reports into your mailboxFabrizio Branca
  8. 8. Bugs • Avoid bugs • through programming style • Spot bugs fast • “Safety nets”: Unit tests, Assertions • Detect them before the customer and/or the website user finds themFabrizio Branca
  9. 9. Avoid bugs• Use a proper IDE • Syntax checks • Code Completion
  10. 10. Coding style • Cover all cases: No if without else! • Use type hints wherever possible • Stick to patterns • Increase crearity • Convention over configuration • KISS • Use object collections • Make it easier for team members to find and fix bugs (increase the truck factor) by sticking to coding guidelines and patternsFabrizio Branca
  11. 11. What does PHP offer? • log_errors • display_errors • error_log Set values in • php.ini • .htaccess / vhost configurationFabrizio Branca
  12. 12. What does TYPO3 offer? • devLog, sysLog, Tslog • devIpMask • Deprecation log • Page not found / Page unavailable • Exception handling • Error handling • Debug Console in the BEFabrizio Branca
  13. 13. Deal with exceptions (I) How to react when an exception has occurred? • Don„t display any details to the user! • Send a correct HTTP status code (for search engines and log files) $GLOBALS[TSFE]->pageNotFoundAndExit($errorHandlerMessage); $GLOBALS[TSFE]->pageUnavailableAndExit($errorHandlerMessage);Fabrizio Branca
  14. 14. Page not foundFabrizio Branca
  15. 15. Page unavailableFabrizio Branca
  16. 16. Deal with exceptions (II) Handle exceptions within your controllers. Notify yourself: • write a message to devLog • write a message to sysLog • write a message to TSLogFabrizio Branca
  17. 17. Exception HandlerFabrizio Branca
  18. 18. Bug detection • Bugs are harder to fix the later they are detected • Bugs become harder to diagnose the further the symptom is removed from the causeFabrizio Branca
  19. 19. Bug detection with assertions • Make sure that variables contain what you expect at any time (e.g. after calling a function) • E.g.: Check incoming parameters for correct type • Simple one line call: tx_pttools_assert::isValidUid($this->params[uid]); • Throws an exception if assertion is not true • http://articles.sitepoint.com/article/bug-detection-php-assertions http://debuggable.com/posts/assert-the-yummyness-of-your-cake:480f4dd6- 7fe0-4113-9776-458acbdd56cbFabrizio Branca
  20. 20. Bug detection with assertions • Assertions are easy to use. • Don„t assume anything, check it! • Example: ini_set() • No substitute for unit tests!Fabrizio Branca
  21. 21. Bug detection with assertions See EXT:pt_tools/res/staticlib/class.tx_pttools_assert.php or build your own assert class Some examples: • tx_pttools_assert::isValidUid(); • tx_pttools_assert::isNotEmptyString();Fabrizio Branca
  22. 22. t3lib_div::devLog()Fabrizio Branca
  23. 23. t3lib_div::sysLog() Decides by configuration how to handle syslog messages • send mail • write to log file • write to OS syslogFabrizio Branca
  24. 24. Custom SysLog Handler See EXT:tcaobjects/res/class.tx_tcaobjects_syslog.phpFabrizio Branca
  25. 25. SysLog notification mailmsg: Assertion "isValidUid" failed!extKey: pt_toolsseverity: 3exceptionClass: tx_pttools_exceptionAssertiondebugMsg: file: /var/www/burghalle/integration/htdocs/typo3conf/ext/aoe_burg/controller/class.tx_aoeburg_controller_extranet.php line: 78 function: tx_aoeburg_controller_extranet::init assertType: isValidUid val: expected: 1Server: TYPO3_REQUEST_URL: http://www.integration.burghalle.aoe-works.de/xtranet/uebersicht/artikel- bearbeiten/e/typo3conf/ext/burghalle_template/i/white-75.png HTTP_REFERER: http://www.integration.burghalle.aoe-works.de/xtranet/uebersicht/artikel-bearbeiten/e/saveContent.html POST: -- none -- COOKIE: condensed: 0 fe_typo_user: 6b7ccec749891321cb6e7e2fc4c685a4 PHPSESSID: 4b8712f5a4c845029da1f2332cf9132bClient: HTTP_USER_AGENT: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4 ( .NET CLR 3.5.30729; .NET4.0C) Spider: No REMOTE_HOST: [null] REMOTE_ADDR: 217.19.187.106User: FE_User: aoe BE_User: -- no user --Trace: [...]
  26. 26. $TYPO3_DB- >debug_check_recordset() • Check all database queries • Debug_check_recordset takes care of writing log messagesFabrizio Branca
  27. 27. TSlogFabrizio Branca
  28. 28. $TT->push() / ->pull() Use the timetrack object to keep track of what happens in your code.Fabrizio Branca
  29. 29. Reports moduleFabrizio Branca
  30. 30. Reports module Write your own reports Examples: • Table size • Outdated extensions (extension manager) • TCA Integrity • TCA/database integrity (Like Compare tool) • Extension integrity (dependencies, conflicts) • Free disk space • Server loadFabrizio Branca
  31. 31. Define a strong api • Provide interfaces for hooks. • Allow alternatives (pagerStrategy, viewClass,…)Fabrizio Branca
  32. 32. Keep an eye on the logs… • Webserver • Apache error log • PHP error log • TYPO3 • Log module (Core error handler…) • Admin Panel • RealUrl • error log • are all paramters encoded? • Deprecation log • Reports moduleFabrizio Branca
  33. 33. Keep an eye on the logs… • External tools • Google Webmaster Tools • Wget • Piwik • MySQL • Slow query log • OS (*nix) • SyslogFabrizio Branca
  34. 34. Log ModuleFabrizio Branca
  35. 35. Google Webmaster ToolsFabrizio Branca
  36. 36. Let tools do the analysis • PHP • TSFE • TypoScript • jQuery code • HTML • CSS • RSSFabrizio Branca
  37. 37. Visualizing xdebug profiling
  38. 38. Visualizing xdebug profiling
  39. 39. Visualizing pdepend xml
  40. 40. jQuery Lint „Runtime Reporter“ http://james.padolsey.com/javascript/jquery-lint/Fabrizio Branca
  41. 41. TypoScript Check (lint) Proof of concept! Xclassing tslib_content: function stdWrap($content,$conf) { $this->getLinkChecker()->check($conf, stdWrap); return parent::stdWrap($content, $conf); }Fabrizio Branca
  42. 42. Tick
  43. 43. TickFabrizio Branca
  44. 44. Tick
  45. 45. Use validators Use validators for validating • HTML • CSS • RSS Keep an eye on editor„s contentFabrizio Branca
  46. 46. Spot performance killers • Use USER_INTs only if really needed. • Create links with cHashes • Avoid putting USER_INTs on all pages (load them via ajax) • Cache headers • Static publishingFabrizio Branca
  47. 47. Monitoring • Configure your TYPO3 instances to notify you when errors occur. • Use Monitoring tools (e.g. Nagios, Caretaker?)Fabrizio Branca
  48. 48. Pingdom
  49. 49. Maintainance • Delete old temp files find ../htdocs/typo3temp -type f -mtime +28 -delete • Delete deleted records • Delete unreferenced files • Cleanup/check databaseFabrizio Branca
  1. ¿Le ha llamado la atención una diapositiva en particular?

    Recortar diapositivas es una manera útil de recopilar información importante para consultarla más tarde.

×