rack-mini-profiler 0.1.31 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rack-mini-profiler might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +149 -0
- data/README.md +285 -0
- data/{Ruby/lib → lib}/html/includes.css +15 -4
- data/{Ruby/lib → lib}/html/includes.js +95 -59
- data/{Ruby/lib → lib}/html/includes.less +21 -5
- data/{Ruby/lib → lib}/html/includes.tmpl +50 -50
- data/{Ruby/lib → lib}/html/jquery.1.7.1.js +0 -0
- data/{Ruby/lib → lib}/html/jquery.tmpl.js +0 -0
- data/{Ruby/lib → lib}/html/list.css +2 -2
- data/{Ruby/lib → lib}/html/list.js +1 -1
- data/lib/html/list.tmpl +34 -0
- data/lib/html/profile_handler.js +1 -0
- data/{Ruby/lib → lib}/html/share.html +2 -2
- data/lib/mini_profiler/asset_version.rb +5 -0
- data/{Ruby/lib → lib}/mini_profiler/client_settings.rb +3 -3
- data/lib/mini_profiler/config.rb +65 -0
- data/{Ruby/lib → lib}/mini_profiler/context.rb +0 -0
- data/lib/mini_profiler/gc_profiler.rb +181 -0
- data/{Ruby/lib → lib}/mini_profiler/profiler.rb +120 -96
- data/{Ruby/lib → lib}/mini_profiler/profiling_methods.rb +15 -17
- data/{Ruby/lib → lib}/mini_profiler/storage/abstract_store.rb +0 -0
- data/{Ruby/lib → lib}/mini_profiler/storage/file_store.rb +30 -8
- data/{Ruby/lib → lib}/mini_profiler/storage/memcache_store.rb +5 -7
- data/lib/mini_profiler/storage/memory_store.rb +115 -0
- data/{Ruby/lib → lib}/mini_profiler/storage/redis_store.rb +19 -11
- data/lib/mini_profiler/timer_struct/base.rb +33 -0
- data/lib/mini_profiler/timer_struct/client.rb +89 -0
- data/lib/mini_profiler/timer_struct/custom.rb +22 -0
- data/lib/mini_profiler/timer_struct/page.rb +62 -0
- data/lib/mini_profiler/timer_struct/request.rb +126 -0
- data/lib/mini_profiler/timer_struct/sql.rb +59 -0
- data/lib/mini_profiler/version.rb +5 -0
- data/{Ruby/lib → lib}/mini_profiler_rails/railtie.rb +23 -6
- data/lib/patches/db/activerecord.rb +42 -0
- data/lib/patches/db/moped.rb +12 -0
- data/lib/patches/db/mysql2.rb +30 -0
- data/lib/patches/db/pg.rb +104 -0
- data/lib/patches/db/plucky.rb +47 -0
- data/lib/patches/db/rsolr.rb +24 -0
- data/lib/patches/db/sequel.rb +10 -0
- data/{Ruby/lib → lib}/patches/net_patches.rb +0 -0
- data/lib/patches/sql_patches.rb +46 -0
- data/lib/rack-mini-profiler.rb +35 -0
- data/rack-mini-profiler.gemspec +28 -16
- metadata +171 -52
- data/Ruby/CHANGELOG +0 -161
- data/Ruby/README.md +0 -172
- data/Ruby/lib/html/list.tmpl +0 -34
- data/Ruby/lib/html/profile_handler.js +0 -1
- data/Ruby/lib/mini_profiler/client_timer_struct.rb +0 -78
- data/Ruby/lib/mini_profiler/config.rb +0 -58
- data/Ruby/lib/mini_profiler/custom_timer_struct.rb +0 -22
- data/Ruby/lib/mini_profiler/gc_profiler.rb +0 -107
- data/Ruby/lib/mini_profiler/gc_profiler_ruby_head.rb +0 -40
- data/Ruby/lib/mini_profiler/page_timer_struct.rb +0 -58
- data/Ruby/lib/mini_profiler/request_timer_struct.rb +0 -115
- data/Ruby/lib/mini_profiler/sql_timer_struct.rb +0 -58
- data/Ruby/lib/mini_profiler/storage/memory_store.rb +0 -65
- data/Ruby/lib/mini_profiler/timer_struct.rb +0 -33
- data/Ruby/lib/mini_profiler/version.rb +0 -5
- data/Ruby/lib/patches/sql_patches.rb +0 -277
- data/Ruby/lib/rack-mini-profiler.rb +0 -7
data/Ruby/CHANGELOG
DELETED
@@ -1,161 +0,0 @@
|
|
1
|
-
28-June-2012 - Sam
|
2
|
-
|
3
|
-
* Started change log
|
4
|
-
* Corrected profiler so it properly captures POST requests (was supressing non 200s)
|
5
|
-
* Amended Rack.MiniProfiler.config[:user_provider] to use ip addres for identity
|
6
|
-
* Fixed bug where unviewed missing ids never got cleared
|
7
|
-
* Supress all '/assets/' in the rails tie (makes debugging easier)
|
8
|
-
* record_sql was mega buggy
|
9
|
-
* added MemcacheStore
|
10
|
-
|
11
|
-
9-July-2012 - Sam
|
12
|
-
|
13
|
-
* Cleaned up mechanism for profiling in production, all you need to do now
|
14
|
-
is call Rack::MiniProfiler.authorize_request to get profiling working in
|
15
|
-
production
|
16
|
-
* Added option to display full backtraces pp=full-backtrace
|
17
|
-
* Cleaned up railties, got rid of the post authorize callback
|
18
|
-
* Version 0.1.3
|
19
|
-
|
20
|
-
12-July-2012 - Sam
|
21
|
-
|
22
|
-
* Fixed incorrect profiling steps (was not indenting or measuring start time right
|
23
|
-
* Implemented native PG and MySql2 interceptors, this gives way more accurate times
|
24
|
-
* Refactored context so its a proper class and not a hash
|
25
|
-
* Added some more client probing built in to rails
|
26
|
-
* More tests
|
27
|
-
|
28
|
-
18-July-2012 - Sam
|
29
|
-
|
30
|
-
* Added First Paint time for chrome
|
31
|
-
* Bug fix to ensure non Rails installs have mini profiler
|
32
|
-
* Version 0.1.7
|
33
|
-
|
34
|
-
30-July-2012 - Sam
|
35
|
-
|
36
|
-
* Made compliant with ancient versions of Rack (including Rack used by Rails2)
|
37
|
-
* Fixed broken share link
|
38
|
-
* Fixed crashes on startup (in MemoryStore and FileStore)
|
39
|
-
* Version 0.1.8
|
40
|
-
* Unicode fix
|
41
|
-
* Version 0.1.9
|
42
|
-
|
43
|
-
7-August-2012 - Sam
|
44
|
-
|
45
|
-
* Added option to disable profiler for the current session (pp=disable / pp=enable)
|
46
|
-
* yajl compatability contributed by Sven Riedel
|
47
|
-
|
48
|
-
10-August-2012 - Sam
|
49
|
-
|
50
|
-
* Added basic prepared statement profiling for postgres
|
51
|
-
|
52
|
-
20-August-2012 - Sam
|
53
|
-
|
54
|
-
* 1.12.pre
|
55
|
-
* Cap X-MiniProfiler-Ids at 10, otherwise the header can get killed
|
56
|
-
|
57
|
-
3-September-2012 - Sam
|
58
|
-
|
59
|
-
* 1.13.pre
|
60
|
-
* pg gem prepared statements were not being logged correctly
|
61
|
-
* added setting config.backtrace_ignores = [] - an array of regexes that match on caller lines that get ignored
|
62
|
-
* added setting config.backtrace_includes = [] - an array of regexes that get included in the trace by default
|
63
|
-
* cleaned up the way client settings are stored
|
64
|
-
* made pp=full-backtrace "sticky"
|
65
|
-
* added pp=normal-backtrace to clear the "sticky" state
|
66
|
-
* change "pp=sample" to work with "caller" no need for stack trace gem
|
67
|
-
|
68
|
-
4-September-2012 - Sam
|
69
|
-
|
70
|
-
* 1.15.pre
|
71
|
-
* fixed annoying bug where client settings were not sticking
|
72
|
-
* fixed long standing issue with Rack::ConditionalGet stopping MiniProfiler from working properly
|
73
|
-
|
74
|
-
5-September-2012 - Sam
|
75
|
-
|
76
|
-
* 1.16
|
77
|
-
* fixed long standing problem specs (issue with memory store)
|
78
|
-
* fixed issue where profiler would be dumped when you got a 404 in production (and any time rails is bypassed)
|
79
|
-
* implemented stacktrace properly
|
80
|
-
|
81
|
-
9-September-2012 - Sam
|
82
|
-
|
83
|
-
* 1.17
|
84
|
-
* pp=sample was bust unless stacktrace was installed
|
85
|
-
|
86
|
-
10-September-2012 - Sam
|
87
|
-
|
88
|
-
* 1.19
|
89
|
-
* fix compat issue with 1.8.7
|
90
|
-
|
91
|
-
12-September-2012 - Sam
|
92
|
-
|
93
|
-
* 1.20
|
94
|
-
* Added pp=profile-gc , it allows you to profile the GC in Ruby 1.9.3
|
95
|
-
|
96
|
-
17-September-2012
|
97
|
-
* 1.21
|
98
|
-
* New MemchacedStore
|
99
|
-
* Rails 4 support
|
100
|
-
|
101
|
-
17-September-2012
|
102
|
-
* Allow rack-mini-profiler to be sourced from github
|
103
|
-
* Extracted the pp=profile-gc-time out, the object space profiler needs to disable gc
|
104
|
-
|
105
|
-
20-September-2012
|
106
|
-
* 1.22
|
107
|
-
* Fix permission issue in the gem
|
108
|
-
|
109
|
-
8-April-2013
|
110
|
-
* 1.24
|
111
|
-
* Flame Graph Support see: http://samsaffron.com/archive/2013/03/19/flame-graphs-in-ruby-miniprofiler
|
112
|
-
* Fix file retention leak in file_store
|
113
|
-
* New toggle_shortcut and start_hidden options
|
114
|
-
* Fix for AngularJS support and MooTools
|
115
|
-
* More robust gc profiling
|
116
|
-
* Mongoid support
|
117
|
-
* Fix for html5 implicit body tags
|
118
|
-
* script tag initialized via data-attributes
|
119
|
-
* new - Rack::MiniProfiler.counter counter_name {}
|
120
|
-
* Allow usage of existing jQuery if its already loaded
|
121
|
-
* Fix pp=enable
|
122
|
-
* 1.8.7 support ... grrr
|
123
|
-
* Net:HTTP profiling
|
124
|
-
* pre authorize to run in all non development? and production? modes
|
125
|
-
|
126
|
-
8-April-2013
|
127
|
-
* 1.25
|
128
|
-
* Missed flamegraph.html from build
|
129
|
-
|
130
|
-
11-April-2013
|
131
|
-
* 1.26
|
132
|
-
* (minor) allow Rack::MiniProfilerRails.initialize!(Rails.application), for post config intialization
|
133
|
-
|
134
|
-
26-June-2013
|
135
|
-
* 1.27
|
136
|
-
* Disable global ajax handlers on MP requests @JP
|
137
|
-
* Add Rack::MiniProfiler.config.backtrace_threshold_ms
|
138
|
-
* jQuery 2.0 support
|
139
|
-
|
140
|
-
18-July-2013
|
141
|
-
* 1.28
|
142
|
-
* diagnostics in abstract storage was raising not implemented killing
|
143
|
-
?pp=env and others
|
144
|
-
* SOLR xml unescaped by mistake
|
145
|
-
|
146
|
-
20-August-2013
|
147
|
-
* 1.29
|
148
|
-
* Bugfix: SOLR patching had an incorrect monkey patch
|
149
|
-
* Implemented exception tracing using TracePoint see pp=trace-exceptions
|
150
|
-
|
151
|
-
30-August-2013
|
152
|
-
|
153
|
-
* 1.30
|
154
|
-
* Feature: Added Rack::MiniProfiler.counter_method(klass,name) for injecting counters
|
155
|
-
* Bug: Counters were not shifting the table correctly
|
156
|
-
|
157
|
-
3-September-2013
|
158
|
-
|
159
|
-
* Ripped out flamegraph so it can be isolated into a gem
|
160
|
-
* Flamegraph now has much increased fidelity
|
161
|
-
* Ripped out pp=sample it just was never really used
|
data/Ruby/README.md
DELETED
@@ -1,172 +0,0 @@
|
|
1
|
-
# rack-mini-profiler
|
2
|
-
|
3
|
-
Middleware that displays speed badge for every html page. Designed to work both in production and in development.
|
4
|
-
|
5
|
-
## Using rack-mini-profiler in your app
|
6
|
-
|
7
|
-
Install/add to Gemfile
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'rack-mini-profiler'
|
11
|
-
```
|
12
|
-
Using Rails:
|
13
|
-
|
14
|
-
All you have to do is include the Gem and you're good to go in development.
|
15
|
-
|
16
|
-
rack-mini-profiler is designed with production profiling in mind. To enable that just run `Rack::MiniProfiler.authorize_request` once you know a request is allowed to profile.
|
17
|
-
|
18
|
-
Using Rails:
|
19
|
-
|
20
|
-
```ruby
|
21
|
-
# A hook in your ApplicationController
|
22
|
-
def authorize
|
23
|
-
if current_user.is_admin?
|
24
|
-
Rack::MiniProfiler.authorize_request
|
25
|
-
end
|
26
|
-
end
|
27
|
-
````
|
28
|
-
|
29
|
-
|
30
|
-
Using Builder:
|
31
|
-
|
32
|
-
```ruby
|
33
|
-
require 'rack-mini-profiler'
|
34
|
-
builder = Rack::Builder.new do
|
35
|
-
use Rack::MiniProfiler
|
36
|
-
|
37
|
-
map('/') { run get }
|
38
|
-
end
|
39
|
-
```
|
40
|
-
|
41
|
-
Using Sinatra:
|
42
|
-
|
43
|
-
```ruby
|
44
|
-
require 'rack-mini-profiler'
|
45
|
-
class MyApp < Sinatra::Base
|
46
|
-
use Rack::MiniProfiler
|
47
|
-
end
|
48
|
-
```
|
49
|
-
|
50
|
-
## Database profiling
|
51
|
-
|
52
|
-
Currently supports Mysql2, Postgres, and Mongoid3 (with fallback support to ActiveRecord)
|
53
|
-
|
54
|
-
## Storage
|
55
|
-
|
56
|
-
rack-mini-profiler stores it's results so they can be shared later and aren't lost at the end of the request.
|
57
|
-
|
58
|
-
There are 4 storage options: `MemoryStore`, `RedisStore`, `MemcacheStore`, and `FileStore`.
|
59
|
-
|
60
|
-
`FileStore` is the default in Rails environments and will write files to `tmp/miniprofiler/*`. `MemoryStore` is the default otherwise.
|
61
|
-
|
62
|
-
To change the default you can create a file in `config/initializers/mini_profiler.rb`
|
63
|
-
|
64
|
-
```ruby
|
65
|
-
# set MemoryStore
|
66
|
-
Rack::MiniProfiler.config.storage = Rack::MiniProfiler::MemoryStore
|
67
|
-
|
68
|
-
# set RedisStore
|
69
|
-
if Rails.env.production?
|
70
|
-
uri = URI.parse(ENV["REDIS_SERVER_URL"])
|
71
|
-
Rack::MiniProfiler.config.storage_options = { :host => uri.host, :port => uri.port, :password => uri.password }
|
72
|
-
Rack::MiniProfiler.config.storage = Rack::MiniProfiler::RedisStore
|
73
|
-
end
|
74
|
-
```
|
75
|
-
|
76
|
-
MemoryStore stores results in a processes heap - something that does not work well in a multi process environment.
|
77
|
-
FileStore stores results in the file system - something that may not work well in a multi machine environment.
|
78
|
-
RedisStore/MemcacheStore work in multi process and multi machine environments (RedisStore only saves results for up to 24 hours so it won't continue to fill up Redis).
|
79
|
-
|
80
|
-
Additionally you may implement an AbstractStore for your own provider.
|
81
|
-
|
82
|
-
## User result segregation
|
83
|
-
|
84
|
-
MiniProfiler will attempt to keep all user results isolated, out-of-the-box the user provider uses the ip address:
|
85
|
-
|
86
|
-
```ruby
|
87
|
-
Rack::MiniProfiler.config.user_provider = Proc.new{|env| Rack::Request.new(env).ip}
|
88
|
-
```
|
89
|
-
|
90
|
-
You can override (something that is very important in a multi-machine production setup):
|
91
|
-
|
92
|
-
```ruby
|
93
|
-
Rack::MiniProfiler.config.user_provider = Proc.new{ |env| CurrentUser.get(env) }
|
94
|
-
```
|
95
|
-
|
96
|
-
The string this function returns should be unique for each user on the system (for anonymous you may need to fall back to ip address)
|
97
|
-
|
98
|
-
## Running the Specs
|
99
|
-
|
100
|
-
```
|
101
|
-
$ rake build
|
102
|
-
$ rake spec
|
103
|
-
```
|
104
|
-
|
105
|
-
Additionally you can also run `autotest` if you like.
|
106
|
-
|
107
|
-
## Configuration Options
|
108
|
-
|
109
|
-
You can set configuration options using the configuration accessor on Rack::MiniProfiler:
|
110
|
-
|
111
|
-
```
|
112
|
-
# Have Mini Profiler show up on the right
|
113
|
-
Rack::MiniProfiler.config.position = 'right'
|
114
|
-
# Have Mini Profiler start in hidden mode - display with short cut (defaulted to 'Alt+P')
|
115
|
-
Rack::MiniProfiler.config.start_hidden = true
|
116
|
-
# Don't collect backtraces on SQL queries that take less than 5 ms to execute
|
117
|
-
# (necessary on Rubies earlier than 2.0)
|
118
|
-
Rack::MiniProfiler.config.backtrace_threshold_ms = 5
|
119
|
-
```
|
120
|
-
|
121
|
-
|
122
|
-
In a Rails app, this can be done conveniently in an initializer such as config/initializers/mini_profiler.rb.
|
123
|
-
|
124
|
-
## Rails 2.X support
|
125
|
-
|
126
|
-
To get MiniProfiler working with Rails 2.3.X you need to do the initialization manually as well as monkey patch away an incompatibility between activesupport and json_pure.
|
127
|
-
|
128
|
-
Add the following code to your environment.rb (or just in a specific environment such as development.rb) for initialization and configuration of MiniProfiler.
|
129
|
-
|
130
|
-
```ruby
|
131
|
-
# configure and initialize MiniProfiler
|
132
|
-
require 'rack-mini-profiler'
|
133
|
-
c = ::Rack::MiniProfiler.config
|
134
|
-
c.pre_authorize_cb = lambda { |env|
|
135
|
-
Rails.env.development? || Rails.env.production?
|
136
|
-
}
|
137
|
-
tmp = Rails.root.to_s + "/tmp/miniprofiler"
|
138
|
-
FileUtils.mkdir_p(tmp) unless File.exists?(tmp)
|
139
|
-
c.storage_options = {:path => tmp}
|
140
|
-
c.storage = ::Rack::MiniProfiler::FileStore
|
141
|
-
config.middleware.use(::Rack::MiniProfiler)
|
142
|
-
::Rack::MiniProfiler.profile_method(ActionController::Base, :process) {|action| "Executing action: #{action}"}
|
143
|
-
::Rack::MiniProfiler.profile_method(ActionView::Template, :render) {|x,y| "Rendering: #{@virtual_path}"}
|
144
|
-
|
145
|
-
# monkey patch away an activesupport and json_pure incompatability
|
146
|
-
# http://pivotallabs.com/users/alex/blog/articles/1332-monkey-patch-of-the-day-activesupport-vs-json-pure-vs-ruby-1-8
|
147
|
-
if JSON.const_defined?(:Pure)
|
148
|
-
class JSON::Pure::Generator::State
|
149
|
-
include ActiveSupport::CoreExtensions::Hash::Except
|
150
|
-
end
|
151
|
-
end
|
152
|
-
```
|
153
|
-
|
154
|
-
## Notes
|
155
|
-
|
156
|
-
- Be sure to require rack_mini_profiler last in your Gemfile, when it is required it will monkey patch pg and mysql gems to insert instrumentation. If included too early no SQL will show up.
|
157
|
-
|
158
|
-
## Available Options
|
159
|
-
|
160
|
-
* pre_authorize_cb - A lambda callback you can set to determine whether or not mini_profiler should be visible on a given request. Default in a Rails environment is only on in development mode. If in a Rack app, the default is always on.
|
161
|
-
* position - Can either be 'right' or 'left'. Default is 'left'.
|
162
|
-
* skip_schema_queries - Whether or not you want to log the queries about the schema of your tables. Default is 'false', 'true' in rails development.
|
163
|
-
* auto_inject (default true) - when false the miniprofiler script is not injected in the page
|
164
|
-
* backtrace_filter - a regex you can use to filter out unwanted lines from the backtraces
|
165
|
-
* toggle_shortcut (default Alt+P) - a jquery.hotkeys.js-style keyboard shortcut, used to toggle the mini_profiler's visibility. See http://code.google.com/p/js-hotkeys/ for more info.
|
166
|
-
* start_hidden (default false) - Whether or not you want the mini_profiler to be visible when loading a page
|
167
|
-
* backtrace_threshold_ms (default zero) - Minimum SQL query elapsed time before a backtrace is recorded. Backtrace recording can take a couple of milliseconds on rubies earlier than 2.0, impacting performance for very small queries.
|
168
|
-
|
169
|
-
## Special query strings
|
170
|
-
|
171
|
-
If you include the query string `pp=help` at the end of your request you will see the various options available. You can use these options to extend or contract the amount of diagnostics rack-mini-profiler gathers.
|
172
|
-
|
data/Ruby/lib/html/list.tmpl
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
<script id="tableTemplate" type="text/x-jquery-tmpl">
|
2
|
-
<table>
|
3
|
-
<thead>
|
4
|
-
<tr>
|
5
|
-
<th>Name</th>
|
6
|
-
<th>Started</th>
|
7
|
-
<th>Sql Duration</th>
|
8
|
-
<th>Total Duration</th>
|
9
|
-
<th>Request Start</th>
|
10
|
-
<th>Response Start</th>
|
11
|
-
<th>Dom Complete</th>
|
12
|
-
</tr>
|
13
|
-
</thead>
|
14
|
-
<tbody>
|
15
|
-
|
16
|
-
</tbody>
|
17
|
-
</table>
|
18
|
-
</script>
|
19
|
-
<script id="rowTemplate" type="text/x-jquery-tmpl">
|
20
|
-
<tr>
|
21
|
-
<td>
|
22
|
-
<a href="${MiniProfiler.path}results?id=${Id}">${Name}</a></td>
|
23
|
-
<td class="date">${MiniProfiler.renderDate(Started)}</td>
|
24
|
-
<td class="time">${DurationMillisecondsInSql}</td>
|
25
|
-
<td class="time">${DurationMilliseconds}</td>
|
26
|
-
{{if ClientTimings}}
|
27
|
-
<td class="time">${MiniProfiler.getClientTimingByName(ClientTimings,"Request").Start}</td>
|
28
|
-
<td class="time">${MiniProfiler.getClientTimingByName(ClientTimings,"Response").Start}</td>
|
29
|
-
<td class="time">${MiniProfiler.getClientTimingByName(ClientTimings,"Dom Complete").Start}</td>
|
30
|
-
{{else}}
|
31
|
-
<td colspan="3"></td>
|
32
|
-
{{/if}}
|
33
|
-
</tr>
|
34
|
-
</script>
|
@@ -1 +0,0 @@
|
|
1
|
-
<script async type="text/javascript" id="mini-profiler" src="{path}includes.js?v={version}" data-version="{version}" data-path="{path}" data-current-id="{currentId}" data-ids="{ids}" data-position="{position}" data-trivial="{showTrivial}" data-children="{showChildren}" data-max-traces="{maxTracesToShow}" data-controls="{showControls}" data-authorized="{authorized}" data-toggle-shortcut="{toggleShortcut}" data-start-hidden="{startHidden}"></script>
|
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'mini_profiler/timer_struct'
|
2
|
-
|
3
|
-
module Rack
|
4
|
-
class MiniProfiler
|
5
|
-
|
6
|
-
# This class holds the client timings
|
7
|
-
class ClientTimerStruct < TimerStruct
|
8
|
-
|
9
|
-
def self.init_instrumentation
|
10
|
-
"<script type=\"text/javascript\">mPt=function(){var t=[];return{t:t,probe:function(n){t.push({d:new Date(),n:n})}}}()</script>"
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.instrument(name,orig)
|
14
|
-
probe = "<script>mPt.probe('#{name}')</script>"
|
15
|
-
wrapped = probe
|
16
|
-
wrapped << orig
|
17
|
-
wrapped << probe
|
18
|
-
wrapped
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
def initialize(env={})
|
23
|
-
super
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.init_from_form_data(env, page_struct)
|
27
|
-
timings = []
|
28
|
-
clientTimes, clientPerf, baseTime = nil
|
29
|
-
form = env['rack.request.form_hash']
|
30
|
-
|
31
|
-
clientPerf = form['clientPerformance'] if form
|
32
|
-
clientTimes = clientPerf['timing'] if clientPerf
|
33
|
-
|
34
|
-
baseTime = clientTimes['navigationStart'].to_i if clientTimes
|
35
|
-
return unless clientTimes && baseTime
|
36
|
-
|
37
|
-
probes = form['clientProbes']
|
38
|
-
translated = {}
|
39
|
-
if probes && !["null", ""].include?(probes)
|
40
|
-
probes.each do |id, val|
|
41
|
-
name = val["n"]
|
42
|
-
translated[name] ||= {}
|
43
|
-
if translated[name][:start]
|
44
|
-
translated[name][:finish] = val["d"]
|
45
|
-
else
|
46
|
-
translated[name][:start] = val["d"]
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
translated.each do |name, data|
|
52
|
-
h = {"Name" => name, "Start" => data[:start].to_i - baseTime}
|
53
|
-
h["Duration"] = data[:finish].to_i - data[:start].to_i if data[:finish]
|
54
|
-
timings.push(h)
|
55
|
-
end
|
56
|
-
|
57
|
-
clientTimes.keys.find_all{|k| k =~ /Start$/ }.each do |k|
|
58
|
-
start = clientTimes[k].to_i - baseTime
|
59
|
-
finish = clientTimes[k.sub(/Start$/, "End")].to_i - baseTime
|
60
|
-
duration = 0
|
61
|
-
duration = finish - start if finish > start
|
62
|
-
name = k.sub(/Start$/, "").split(/(?=[A-Z])/).map{|s| s.capitalize}.join(' ')
|
63
|
-
timings.push({"Name" => name, "Start" => start, "Duration" => duration}) if start >= 0
|
64
|
-
end
|
65
|
-
|
66
|
-
clientTimes.keys.find_all{|k| !(k =~ /(End|Start)$/)}.each do |k|
|
67
|
-
timings.push("Name" => k, "Start" => clientTimes[k].to_i - baseTime, "Duration" => -1)
|
68
|
-
end
|
69
|
-
|
70
|
-
rval = self.new
|
71
|
-
rval['RedirectCount'] = env['rack.request.form_hash']['clientPerformance']['navigation']['redirectCount']
|
72
|
-
rval['Timings'] = timings
|
73
|
-
rval
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
end
|