Luca Lusso
• Senior Drupal Developer @ Wellnet - Italy
• Acquia developer and backend developer certification
• Twitter: @lussoluca
• drupal.org/IRC: lussoluca
• Not so fluent in english… sorry
Symfony has a great profiler tool
symfony.com/doc/current/cookbook/profiler
Symfony profiler
• Performance monitoring
• Huge amount of high-level data about application’s internals (database query, rendered forms, errors, http request and response headers, routing, events, services, …)
• Useful in functional testing (more on this later)
But wait… the Symfony profiler classes are declared in the HttpKernel component, here:
core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Profiler
And the HttpKernel IS in Drupal 8, so what is missing?
Glue code is in FrameworkBundle
and WebProfilerBundle
But Symfony bundles doesn't works in Drupal 8 :-(
Two options:
1. make Symfony bundles works in Drupal 8 (www.drupal.org/node/1880196 -> won't fix)
2. move the bundle code to a Drupal module
We choose the Drupal way™
Drupal Webprofiler Module
www.drupal.org/project/webprofilergithub.com/lussoluca/webprofiler
Implemented DataCollectors
PHP ConfigRequest
Timeline FrontendDatabase
UserViews
Block
Http
Extensions
EventsState
ConfigAssets
CacheRouting
ServiceForms
Every widget shows data about a metric measured by a data collector on the current rendered page
How does it work
Instrumented(collect data and
store profile)
Request Response
<div id="webprofilerefa2f1"></div> <script> Webprofiler = (function () { […] } </script>
Response
• Add HTTP header -> X-Debug-Token: efa2f1
• Inject some javascript in the page:
How does it work
Profiling turned off
Ajax Request Response
/profiler/efa2f1Returns only the
toolbar DOM (with embedded
javascript, css and icons)
Integration with XHProf/UProfiler
Drupal 8 version of XHProf module is compatibile with Webprofiler (www.drupal.org/project/xhprof)
admin/config/development/profiler/configureadmin/config/development/xhprof
Integration with Drupal Console project
• Leverages the Symfony Console Component to provide a powerful CLI
• Started as scaffolding generator now expose an increasing number of commands to interact with a Drupal 8 installation
• Modules can contribute implementing new commands
drupalconsole.com
Implemented commands
• webprofiler:list -> list stored profiles
• webprofiler:export -> export stored profiles
• webprofiler:benchmark -> benchmark an URL running a huge number of requests and compute statistics
• webprofiler:analyze -> analyze all stored profiles for a specific route and compute statistics (not yet available on drupal.org)
Benchmark an URL
• Anonymous userconsole webprofiler:benchmark http://d8 —runs=10
• Logged-in userconsole webprofiler:benchmark http://admin:admin@d8/admin/people —runs=10
• Rebuild cache before benchmark console webprofiler:benchmark http://d8 --runs=10 —cache-rebuild
• Store results in a file console webprofiler:benchmark http://d8 --runs=10 --file=/Users/lussoluca/Desktop/benchmark.yml
Analyze a route
• Default front pageconsole webprofiler:analyze view.frontpage.page_1 GET average
• User profile page console webprofiler:analyze entity.user.canonical GET average
Write a new datacollector
Contrib modules can provides new data collectors
• find a service to instrument
• write a new class to wrap/replace the original service
• alter the container to instrument the service
• write a new data collector class
• write a new template class
Functional testing
• We can mock the plugin.manager.mail service or the http_client service, for example, but if we want to write a functional test with a real integration?
• Maybe we want to test how much time is spent or how much memory is consumed
We can use data profiled by Webprofiler in our assertions
symfony.com/doc/current/cookbook/testing/profiling.html
Contributors
• Daniel Wehner (dawehner) - co-mantainer
• Eric Sod (esod)
• willzyx
• Francesco Caspani (fcaspani)
• Jesus Manuel Olivas (jmolivas)
We need a huge help on
• UX
• Javascript (Backbone) - www.drupal.org/node/2468007
• Statistical analysis
• Documentation
So please contact us!