commit 88945ebafa173ba7f8cf4983068733b4031e9412 Author: Rarst Date: Mon Apr 22 23:19:36 2013 +0300 Initial commit diff --git a/.hgignore b/.hgignore new file mode 100644 index 0000000..88e99d5 --- /dev/null +++ b/.hgignore @@ -0,0 +1,2 @@ +vendor +composer.lock \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..50f47a9 --- /dev/null +++ b/composer.json @@ -0,0 +1,27 @@ +{ + "name" : "rarst/laps", + "description": "Light WordPress profiler.", + "keywords" : ["wordpress", "performance"], + "type" : "wordpress-plugin", + "homepage" : "https://bitbucket.org/Rarst/laps", + "license" : "MIT", + "authors" : [ + { + "name" : "Andrey Savchenko", + "email" : "contact@rarst.net", + "homepage": "http://www.Rarst.net/" + } + ], + "support" : { + "issues": "https://bitbucket.org/Rarst/laps/issues", + "source": "https://bitbucket.org/Rarst/laps/src" + }, + "autoload" : { + "classmap": ["src/"] + }, + "require" : { + "composer/installers": "~1.0", + "symfony/stopwatch" : "~2.2.0", + "mustache/mustache" : "~2.3.0" + } +} diff --git a/css/hint.css b/css/hint.css new file mode 100644 index 0000000..7290998 --- /dev/null +++ b/css/hint.css @@ -0,0 +1,265 @@ +/*! Hint.css - v1.2.1 - 2013-03-24 +* http://kushagragour.in/lab/hint/ +* Copyright (c) 2013 Kushagra Gour; Licensed MIT */ + +/*-------------------------------------*\ + HINT.css - A CSS tooltip library +\*-------------------------------------*/ +/** + * HINT.css is a tooltip library made in pure CSS. + * + * Source: https://github.com/chinchang/hint.css + * Demo: http://kushagragour.in/labs/hint/ + * + * Release under The MIT License + * + */ +/** + * source: hint-core.scss + * + * Defines the basic styling for the tooltip. + * Each tooltip is made of 2 parts: + * 1) body (:after) + * 2) arrow (:before) + * + * Classes added: + * 1) hint + */ +.hint, [data-hint] { + position: relative; + display: inline-block; + /** + * tooltip arrow + */ + /** + * tooltip body + */ } + .hint:before, .hint:after, [data-hint]:before, [data-hint]:after { + position: absolute; + visibility: hidden; + opacity: 0; + z-index: 1000000; + pointer-events: none; + -webkit-transition: 0.3s ease; + -moz-transition: 0.3s ease; + transition: 0.3s ease; } + .hint:hover:before, .hint:hover:after, [data-hint]:hover:before, [data-hint]:hover:after { + visibility: visible; + opacity: 1; } + .hint:before, [data-hint]:before { + content: ''; + position: absolute; + background: transparent; + border: 6px solid transparent; + z-index: 1000001; } + .hint:after, [data-hint]:after { + content: attr(data-hint); + background: #383838; + color: white; + text-shadow: 0 -1px 0px black; + padding: 8px 10px; + font-size: 12px; + line-height: 12px; + white-space: nowrap; + box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.3); } + +/** + * source: hint-position.scss + * + * Defines the positoning logic for the tooltips. + * + * Classes added: + * 1) hint--top + * 2) hint--bottom + * 3) hint--left + * 4) hint--right + */ +/** + * set default color for tooltip arrows + */ +.hint--top:before { + border-top-color: #383838; } + +.hint--bottom:before { + border-bottom-color: #383838; } + +.hint--left:before { + border-left-color: #383838; } + +.hint--right:before { + border-right-color: #383838; } + +/** + * top tooltip + */ +.hint--top:before { + margin-bottom: -12px; } +.hint--top:after { + margin-left: -18px; } +.hint--top:before, .hint--top:after { + bottom: 100%; + left: 50%; } +.hint--top:hover:before, .hint--top:hover:after { + -webkit-transform: translateY(-8px); + -moz-transform: translateY(-8px); + transform: translateY(-8px); } + +/** + * bottom tooltip + */ +.hint--bottom:before { + margin-top: -12px; } +.hint--bottom:after { + margin-left: -18px; } +.hint--bottom:before, .hint--bottom:after { + top: 100%; + left: 50%; } +.hint--bottom:hover:before, .hint--bottom:hover:after { + -webkit-transform: translateY(8px); + -moz-transform: translateY(8px); + transform: translateY(8px); } + +/** + * right tooltip + */ +.hint--right:before { + margin-left: -12px; + margin-bottom: -6px; } +.hint--right:after { + margin-bottom: -14px; } +.hint--right:before, .hint--right:after { + left: 100%; + bottom: 50%; } +.hint--right:hover:before, .hint--right:hover:after { + -webkit-transform: translateX(8px); + -moz-transform: translateX(8px); + transform: translateX(8px); } + +/** + * left tooltip + */ +.hint--left:before { + margin-right: -12px; + margin-bottom: -6px; } +.hint--left:after { + margin-bottom: -14px; } +.hint--left:before, .hint--left:after { + right: 100%; + bottom: 50%; } +.hint--left:hover:before, .hint--left:hover:after { + -webkit-transform: translateX(-8px); + -moz-transform: translateX(-8px); + transform: translateX(-8px); } + +/** + * source: hint-color-types.scss + * + * Contains tooltips of various types based on color differences. + * + * Classes added: + * 1) hint--error + * 2) hint--warning + * 3) hint--info + * 4) hint--success + * + */ +/** + * Error + */ +.hint--error:after { + background-color: #b34e4d; + text-shadow: 0 -1px 0px #5a2626; } +.hint--error.hint--top:before { + border-top-color: #b34e4d; } +.hint--error.hint--bottom:before { + border-bottom-color: #b34e4d; } +.hint--error.hint--left:before { + border-left-color: #b34e4d; } +.hint--error.hint--right:before { + border-right-color: #b34e4d; } + +/** + * Warning + */ +.hint--warning:after { + background-color: #c09854; + text-shadow: 0 -1px 0px #6d5228; } +.hint--warning.hint--top:before { + border-top-color: #c09854; } +.hint--warning.hint--bottom:before { + border-bottom-color: #c09854; } +.hint--warning.hint--left:before { + border-left-color: #c09854; } +.hint--warning.hint--right:before { + border-right-color: #c09854; } + +/** + * Info + */ +.hint--info:after { + background-color: #3986ac; + text-shadow: 0 -1px 0px #193c4c; } +.hint--info.hint--top:before { + border-top-color: #3986ac; } +.hint--info.hint--bottom:before { + border-bottom-color: #3986ac; } +.hint--info.hint--left:before { + border-left-color: #3986ac; } +.hint--info.hint--right:before { + border-right-color: #3986ac; } + +/** + * Success + */ +.hint--success:after { + background-color: #458746; + text-shadow: 0 -1px 0px #1a331a; } +.hint--success.hint--top:before { + border-top-color: #458746; } +.hint--success.hint--bottom:before { + border-bottom-color: #458746; } +.hint--success.hint--left:before { + border-left-color: #458746; } +.hint--success.hint--right:before { + border-right-color: #458746; } + +/** + * source: hint-always.scss + * + * Defines a persisted tooltip which shows always. + * + * Classes added: + * 1) hint--always + * + */ +.hint--always:after, .hint--always:before { + opacity: 1; + visibility: visible; } +.hint--always.hint--top:after, .hint--always.hint--top:before { + -webkit-transform: translateY(-8px); + -moz-transform: translateY(-8px); + transform: translateY(-8px); } +.hint--always.hint--bottom:after, .hint--always.hint--bottom:before { + -webkit-transform: translateY(8px); + -moz-transform: translateY(8px); + transform: translateY(8px); } +.hint--always.hint--left:after, .hint--always.hint--left:before { + -webkit-transform: translateX(-8px); + -moz-transform: translateX(-8px); + transform: translateX(-8px); } +.hint--always.hint--right:after, .hint--always.hint--right:before { + -webkit-transform: translateX(8px); + -moz-transform: translateX(8px); + transform: translateX(8px); } + +/** + * source: hint-rounded.scss + * + * Defines rounded corner tooltips. + * + * Classes added: + * 1) hint--rounded + * + */ +.hint--rounded:after { + border-radius: 4px; } diff --git a/css/laps.css b/css/laps.css new file mode 100644 index 0000000..29a357c --- /dev/null +++ b/css/laps.css @@ -0,0 +1,104 @@ +#wpadminbar #wp-admin-bar-laps .ab-sub-wrapper { + min-width: 90%; + width: 90%; + position: fixed; + left: 5%; +} +#wpadminbar #wp-admin-bar-laps_output { + padding: 0 10px; +} +#wpadminbar #wp-admin-bar-laps_output:hover { + background-color: transparent; +} +#wpadminbar #wp-admin-bar-laps_output .ab-empty-item { + display: none; +} +#wpadminbar .laps-timeline { + overflow: hidden; + height: 20px; + background-color: #f7f7f7; + background-image: -moz-linear-gradient(top, #f5f5f5, #f9f9f9); + background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#f5f5f5), to(#f9f9f9)); + background-image: -webkit-linear-gradient(top, #f5f5f5, #f9f9f9); + background-image: -o-linear-gradient(top, #f5f5f5, #f9f9f9); + background-image: linear-gradient(to bottom, #f5f5f5, #f9f9f9); + background-repeat: repeat-x; + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff5f5f5', endColorstr='#fff9f9f9', GradientType=0); + -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1); + -moz-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1); + box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1); + -webkit-border-radius: 4px; + -moz-border-radius: 4px; + border-radius: 4px; +} +#wpadminbar .laps-timeline .event { + width: 0%; + height: 20px; + color: #fff; + float: left; + font-size: 12px; + text-align: center; + text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25); + background-color: #dd514c; + background-image: -moz-linear-gradient(top, #ee5f5b, #c43c35); + background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ee5f5b), to(#c43c35)); + background-image: -webkit-linear-gradient(top, #ee5f5b, #c43c35); + background-image: -o-linear-gradient(top, #ee5f5b, #c43c35); + background-image: linear-gradient(to bottom, #ee5f5b, #c43c35); + background-repeat: repeat-x; + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffee5f5b', endColorstr='#ffc43c35', GradientType=0); + -webkit-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15); + -moz-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15); + box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15); + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + -webkit-transition: width 0.6s ease; + -moz-transition: width 0.6s ease; + -o-transition: width 0.6s ease; + transition: width 0.6s ease; + position: absolute; +} +#wpadminbar .laps-timeline .event + .event { + -webkit-box-shadow: inset 1px 0 0 rgba(0,0,0,.15), inset 0 -1px 0 rgba(0,0,0,.15); + -moz-box-shadow: inset 1px 0 0 rgba(0,0,0,.15), inset 0 -1px 0 rgba(0,0,0,.15); + box-shadow: inset 1px 0 0 rgba(0,0,0,.15), inset 0 -1px 0 rgba(0,0,0,.15); +} +#wpadminbar .laps-timeline .event-theme { + background-color: #5eb95e; + background-image: -moz-linear-gradient(top, #62c462, #57a957); + background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#62c462), to(#57a957)); + background-image: -webkit-linear-gradient(top, #62c462, #57a957); + background-image: -o-linear-gradient(top, #62c462, #57a957); + background-image: linear-gradient(to bottom, #62c462, #57a957); + background-repeat: repeat-x; + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff62c462', endColorstr='#ff57a957', GradientType=0); +} +#wpadminbar .laps-timeline .event-plugin { + background-color: #4bb1cf; + background-image: -moz-linear-gradient(top, #5bc0de, #339bb9); + background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#5bc0de), to(#339bb9)); + background-image: -webkit-linear-gradient(top, #5bc0de, #339bb9); + background-image: -o-linear-gradient(top, #5bc0de, #339bb9); + background-image: linear-gradient(to bottom, #5bc0de, #339bb9); + background-repeat: repeat-x; + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5bc0de', endColorstr='#ff339bb9', GradientType=0); +} +#wpadminbar .laps-timeline .event-core { + background-color: #faa732; + background-image: -moz-linear-gradient(top, #fbb450, #f89406); + background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#fbb450), to(#f89406)); + background-image: -webkit-linear-gradient(top, #fbb450, #f89406); + background-image: -o-linear-gradient(top, #fbb450, #f89406); + background-image: linear-gradient(to bottom, #fbb450, #f89406); + background-repeat: repeat-x; + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffbb450', endColorstr='#fff89406', GradientType=0); +} +#wpadminbar [data-hint]:after { + font-size: 13px; + background-color: #464646; + text-shadow: none; +} +#wpadminbar .hint--bottom:before { + border-bottom-color: #464646; +} diff --git a/css/laps.less b/css/laps.less new file mode 100644 index 0000000..1308e78 --- /dev/null +++ b/css/laps.less @@ -0,0 +1,77 @@ +@import "mixins.less"; + +#wpadminbar { + + #wp-admin-bar-laps .ab-sub-wrapper { +// display: block !important; + min-width: 90%; + width: 90%; + position: fixed; + left: 5%; + } + + #wp-admin-bar-laps_output { + + padding: 0 10px; + + &:hover { + background-color: transparent; + } + + .ab-empty-item { + display: none; + } + + } + + .laps-timeline { + overflow: hidden; + height: 20px; + #gradient > .vertical(#f5f5f5, #f9f9f9); + .box-shadow(inset 0 1px 2px rgba(0,0,0,.1)); + .border-radius(4px); + } + + .laps-timeline .event { + width: 0%; + height: 20px; + color: #fff; + float: left; + font-size: 12px; + text-align: center; + text-shadow: 0 -1px 0 rgba(0, 0, 0, .25); + #gradient > .vertical(#ee5f5b, #c43c35); + .box-shadow(inset 0 -1px 0 rgba(0,0,0,.15)); + .box-sizing(border-box); + .transition(width .6s ease); + + position: absolute; + } + + .laps-timeline .event + .event { + .box-shadow(~"inset 1px 0 0 rgba(0,0,0,.15), inset 0 -1px 0 rgba(0,0,0,.15)"); + } + + .laps-timeline .event-theme { + #gradient > .vertical(#62c462, #57a957); + } + + .laps-timeline .event-plugin { + #gradient > .vertical(#5bc0de, #339bb9); + } + + .laps-timeline .event-core { + #gradient > .vertical(lighten(#f89406, 15%), #f89406); + } + + [data-hint]:after { + font-size: 13px; + background-color: #464646; + text-shadow: none; + } + + .hint--bottom:before { + border-bottom-color: #464646; + } +} + diff --git a/css/mixins.less b/css/mixins.less new file mode 100644 index 0000000..4e0dbf1 --- /dev/null +++ b/css/mixins.less @@ -0,0 +1,38 @@ +.transition(@transition) { + -webkit-transition: @transition; + -moz-transition: @transition; + -o-transition: @transition; + transition: @transition; +} + +.box-sizing(@boxmodel) { + -webkit-box-sizing: @boxmodel; + -moz-box-sizing: @boxmodel; + box-sizing: @boxmodel; +} + +.border-radius(@radius) { + -webkit-border-radius: @radius; + -moz-border-radius: @radius; + border-radius: @radius; +} + +.box-shadow(@shadow) { + -webkit-box-shadow: @shadow; + -moz-box-shadow: @shadow; + box-shadow: @shadow; +} + +#gradient { + + .vertical(@startColor: #555, @endColor: #333) { + background-color: mix(@startColor, @endColor, 60%); + background-image: -moz-linear-gradient(top, @startColor, @endColor); // FF 3.6+ + background-image: -webkit-gradient(linear, 0 0, 0 100%, from(@startColor), to(@endColor)); // Safari 4+, Chrome 2+ + background-image: -webkit-linear-gradient(top, @startColor, @endColor); // Safari 5.1+, Chrome 10+ + background-image: -o-linear-gradient(top, @startColor, @endColor); // Opera 11.10 + background-image: linear-gradient(to bottom, @startColor, @endColor); // Standard, IE10 + background-repeat: repeat-x; + filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=0)",argb(@startColor), argb(@endColor))); // IE9 and down + } +} \ No newline at end of file diff --git a/laps.php b/laps.php new file mode 100644 index 0000000..39cd824 --- /dev/null +++ b/laps.php @@ -0,0 +1,35 @@ + 'stop', + 'event' => 'Plugins Load', + 'category' => 'plugin', + ); + + $stops['setup_theme'][0] = array( + 'event' => 'Themes Load', + 'category' => 'theme', + ); + + $stops['after_setup_theme'][20] = array( + 'action' => 'stop', + 'event' => 'Themes Load', + 'category' => 'theme', + ); + + $stops['init'][- 1] = array( + 'event' => 'Core Init', + 'category' => 'core', + ); + + $stops['wp_loaded'][20] = array( + 'action' => 'stop', + 'event' => 'Core Init', + 'category' => 'core', + ); + + $stops['loop_start'][10] = array( + 'event' => 'Main Loop', + 'category' => 'theme', + ); + + $stops['loop_end'][10] = array( + 'action' => 'stop', + 'event' => 'Main Loop', + 'category' => 'theme', + ); + + return $stops; + } +} \ No newline at end of file diff --git a/src/class-events.php b/src/class-events.php new file mode 100644 index 0000000..77fbe9a --- /dev/null +++ b/src/class-events.php @@ -0,0 +1,30 @@ +is_applicable() ) + return $this->get_events(); + + return array(); + } + + /** + * @return array() + */ + abstract protected function get_events(); +} \ No newline at end of file diff --git a/src/class-genesis-events.php b/src/class-genesis-events.php new file mode 100644 index 0000000..8cab03d --- /dev/null +++ b/src/class-genesis-events.php @@ -0,0 +1,51 @@ + 'Header', + 'category' => 'theme', + ); + + $events['genesis_after_header'][10] = array( + 'action' => 'stop', + 'event' => 'Header', + 'category' => 'theme', + ); + + $events['genesis_before_sidebar_widget_area'][10] = array( + 'event' => 'Sidebar', + 'category' => 'theme', + ); + + $events['genesis_after_sidebar_widget_area'][10] = array( + 'action' => 'stop', + 'event' => 'Sidebar', + 'category' => 'theme', + ); + + $events['genesis_before_sidebar_alt_widget_area'][10] = array( + 'event' => 'Sidebar (alternate)', + 'category' => 'theme', + ); + + $events['genesis_after_sidebar_alt_widget_area'][10] = array( + 'action' => 'stop', + 'event' => 'Sidebar (alternate)', + 'category' => 'theme', + ); + + return $events; + } +} \ No newline at end of file diff --git a/src/class-hybrid-events.php b/src/class-hybrid-events.php new file mode 100644 index 0000000..d81b1d7 --- /dev/null +++ b/src/class-hybrid-events.php @@ -0,0 +1,47 @@ + 'Header', + 'category' => 'theme', + ); + + $events["{$prefix}_after_header"][10] = array( + 'action' => 'stop', + 'event' => 'Header', + 'category' => 'theme', + ); + + $sidebars = get_theme_support( 'hybrid-core-sidebars' ); + + if ( ! empty( $sidebars[0] ) ) + foreach ( $sidebars[0] as $sidebar ) { + + $events["{$prefix}_before_{$sidebar}"][10] = array( + 'event' => "Sidebar ({$sidebar})", + 'category' => 'theme', + ); + + $events["{$prefix}_after_{$sidebar}"][10] = array( + 'action' => 'stop', + 'event' => "Sidebar ({$sidebar})", + 'category' => 'theme', + ); + } + + return $events; + } +} \ No newline at end of file diff --git a/src/class-laps.php b/src/class-laps.php new file mode 100644 index 0000000..918a6cd --- /dev/null +++ b/src/class-laps.php @@ -0,0 +1,175 @@ +start( 'Plugins Load', 'plugin' ); + $events = new Core_Events(); + self::add_events( $events->get() ); + + add_action( 'pre_update_option_active_plugins', array( __CLASS__, 'pre_update_option_active_plugins' ) ); + add_action( 'pre_update_site_option_active_sitewide_plugins', array( __CLASS__, 'pre_update_option_active_plugins' ) ); + add_action( 'after_setup_theme', array( __CLASS__, 'after_setup_theme' ), 15 ); + add_action( 'init', array( __CLASS__, 'init' ) ); + } + + /** + * Hook events by name and priority from array. + * + * @param array $stops + */ + static function add_events( $stops ) { + + self::$events = array_merge( self::$events, $stops ); + + foreach ( $stops as $hook_name => $data ) { + + foreach ( array_keys( $data ) as $priority ) { + + add_action( $hook_name, array( __CLASS__, 'tick' ), $priority ); + } + } + } + + /** + * Reorder active plugins so Laps is first and starts timing load early. + * + * @param array $plugins + * + * @return array + */ + static function pre_update_option_active_plugins( $plugins ) { + + $plugin = plugin_basename( dirname( __DIR__ ) . '/laps.php' ); + $key = array_search( $plugin, $plugins ); + + if ( false !== $key && $key > 0 ) { + + unset( $plugins[$key] ); + array_unshift( $plugins, $plugin ); + $plugins = array_values( $plugins ); + } + + return $plugins; + } + + /** + * Mark action for the event on Stopwatch. + * + * @param mixed $input pass through if added to filter + * + * @return mixed + */ + static function tick( $input = null ) { + + global $wp_filter; + + $filter = current_filter(); + $priority = key( $wp_filter[$filter] ); + + $event = wp_parse_args( self::$events[$filter][$priority], array( + 'action' => 'start', + 'category' => null, + ) ); + + self::$stopwatch->$event['action']( $event['event'], $event['category'] ); + + return $input; + } + + /** + * When theme is done possibly add theme-specific events. + */ + static function after_setup_theme() { + + foreach ( array( 'THA', 'Hybrid', 'Genesis', 'Thematic' ) as $theme ) { + + $class = "Rarst\\Laps\\{$theme}_Events"; + /** @var Laps_Events $events */ + $events = new $class; + self::add_events( $events->get() ); + } + } + + static function init() { + + add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) ); + add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) ); + add_action( 'admin_bar_menu', array( __CLASS__, 'admin_bar_menu' ), 100 ); + } + + static function enqueue_scripts() { + + wp_register_style( 'laps-hint', plugins_url( 'css/hint.css', __DIR__ ), array(), '1.2.1' ); + wp_register_style( 'laps', plugins_url( 'css/laps.css', __DIR__ ), array( 'laps-hint' ) ); + + if ( is_admin_bar_showing() ) + wp_enqueue_style( 'laps' ); + } + + /** + * Render interface and add to the toolbar. + * + * @param \WP_Admin_Bar $wp_admin_bar + */ + static function admin_bar_menu( $wp_admin_bar ) { + + if ( ! apply_filters( 'laps_can_see', current_user_can( 'manage_options' ) ) ) + return; + + global $timestart; + + $mustache = new \Mustache_Engine( array( + 'loader' => new \Mustache_Loader_FilesystemLoader( dirname( __DIR__ ) . '/views' ), + ) ); + + $events = self::$stopwatch->getSectionEvents( '__root__' ); + $start = $timestart * 1000; + $end = microtime( true ) * 1000; + $total = $end - $start; + $event_data = array(); + + foreach ( $events as $name => $event ) { + + $offset = round( ( $event->getOrigin() - $start ) / $total * 100, 2 ); + $duration = $event->getDuration(); + $width = round( $duration / $total * 100, 2 ); + $category = $event->getCategory(); + $memory = $event->getMemory() / 1024 / 1024; + + $event_data[] = compact( 'name', 'offset', 'duration', 'width', 'category', 'memory' ); + } + + $html = $mustache->render( 'laps', array( 'events' => $event_data ) ); + + $wp_admin_bar->add_node( array( + 'id' => 'laps', + 'title' => sprintf( 'Lap: %ss', round( $total / 1000, 3 ) ), + ) ); + + $wp_admin_bar->add_node( array( + 'id' => 'laps_output', + 'parent' => 'laps', + 'meta' => array( 'html' => $html ), + ) ); + } +} \ No newline at end of file diff --git a/src/class-tha-events.php b/src/class-tha-events.php new file mode 100644 index 0000000..e85ffac --- /dev/null +++ b/src/class-tha-events.php @@ -0,0 +1,40 @@ + 'Header', + 'category' => 'theme', + ); + + $events['tha_header_after'][10] = array( + 'action' => 'stop', + 'event' => 'Header', + 'category' => 'theme', + ); + + $events['tha_sidebars_before'][10] = array( + 'event' => 'Sidebars', + 'category' => 'theme', + ); + + $events['tha_sidebars_after'][10] = array( + 'action' => 'stop', + 'event' => 'Sidebars', + 'category' => 'theme', + ); + + return $events; + } +} \ No newline at end of file diff --git a/src/class-thematic-events.php b/src/class-thematic-events.php new file mode 100644 index 0000000..869bbca --- /dev/null +++ b/src/class-thematic-events.php @@ -0,0 +1,51 @@ + 'Header', + 'category' => 'theme', + ); + + $events['thematic_belowheader'][10] = array( + 'action' => 'stop', + 'event' => 'Header', + 'category' => 'theme', + ); + + $events['widget_area_primary_aside'][10] = array( + 'event' => 'Sidebar (primary aside)', + 'category' => 'theme', + ); + + $events['thematic_betweenmainasides'][10] = array( + 'action' => 'stop', + 'event' => 'Sidebar (primary aside)', + 'category' => 'theme', + ); + + $events['widget_area_secondary_aside'][10] = array( + 'event' => 'Sidebar (secondary aside)', + 'category' => 'theme', + ); + + $events['thematic_belowmainasides'][10] = array( + 'action' => 'stop', + 'event' => 'Sidebar (secondary aside)', + 'category' => 'theme', + ); + + return $events; + } +} \ No newline at end of file diff --git a/views/laps.mustache b/views/laps.mustache new file mode 100644 index 0000000..3e83bd3 --- /dev/null +++ b/views/laps.mustache @@ -0,0 +1,5 @@ +
+ {{#events}} +
+ {{/events}} +
\ No newline at end of file