wor-prof 0.1.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -2
- data/doc/user-guide_en.md +42 -24
- data/doc/user-guide_es.md +41 -20
- data/lib/generators/wprof_generator.rb +28 -25
- data/lib/wor-prof.rb +0 -1
- data/lib/wprof/conf_wprof.rb +29 -9
- data/lib/wprof/reporters/file_report.rb +2 -2
- data/lib/wprof/version.rb +1 -1
- data/lib/wprof/wprof_subscriptors.rb +14 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de3e3e10c82eb8a8c6f37d6d62162ca9dca2f4c5fcda89960529c9fc31f340b8
|
4
|
+
data.tar.gz: 5e727c6f6bd4a89bb930e8400f5574923294519dcb81264407096bed9fdcf953
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cac506875d9c9aff5d8e532e8ab1fb17edc39b04ac8ae2b4330cec0098f774f9dd5e55d06e6b48ea6a9689f32ea15ab9bae4f070f8a42df35b4aa93efa434f60
|
7
|
+
data.tar.gz: f147c3bbf6b1c9ca7d4f22d392d3663aca11caa7a4a2c382db39f01cb7cdc14fce17946b7934e83a5e221a9c61f77703f42ff2acb66160f91d67d54fbc684d87
|
data/README.md
CHANGED
@@ -16,10 +16,15 @@ Add the next line to the gemfile from your Rails application:
|
|
16
16
|
gem 'wor-prof'
|
17
17
|
```
|
18
18
|
|
19
|
-
|
19
|
+
execute:
|
20
20
|
```bash
|
21
21
|
$ bundle install
|
22
22
|
```
|
23
|
+
|
24
|
+
And then, execute:
|
25
|
+
```bash
|
26
|
+
$ rails generate wprof (or copy initializer by yourself)
|
27
|
+
```
|
23
28
|
**That's it!!** At server execution, WProf immediately begins to work with default settings, so you won't need to configure anything if it matches with your needs, otherwise you can check **Available Settings** [here!](https://github.com/Wolox/wor-prof/wiki/User-Guide#available-configurations)
|
24
29
|
|
25
30
|
## Complete User Guide!?? Where??
|
@@ -55,7 +60,7 @@ If you don't know anything about they, take a look in their repos!
|
|
55
60
|
**Maintainers:** [Maximiliano Colombo](https://github.com/mcolombo87).
|
56
61
|
|
57
62
|
**Contributors:** Waiting For You!!!
|
58
|
-
|
63
|
+
[Samir Tapiero](https://github.com/blacksam07)
|
59
64
|
|
60
65
|
![Wolox](https://raw.githubusercontent.com/Wolox/press-kit/master/logos/logo_banner.png)
|
61
66
|
|
data/doc/user-guide_en.md
CHANGED
@@ -18,12 +18,25 @@ Add the next line to the gemfile from your Rails application:
|
|
18
18
|
gem 'wor-prof'
|
19
19
|
```
|
20
20
|
|
21
|
-
|
21
|
+
execute:
|
22
22
|
```bash
|
23
23
|
$ bundle install
|
24
24
|
```
|
25
|
+
|
26
|
+
And then, execute:
|
27
|
+
```bash
|
28
|
+
$ rails generate wprof (or copy initializer by yourself)
|
29
|
+
```
|
25
30
|
**That's it!!** At server execution, WProf immediately begins to work with default settings, so you won't need to configure anything if it matches with your needs, otherwise you can check **Available Settings**.
|
26
31
|
|
32
|
+
`If you don't run wprof generator, you must be initialized Wprof. For do this, add the next line into any rails initializers`
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
WProf::Configuration.initiate_wprof
|
36
|
+
```
|
37
|
+
|
38
|
+
`We highest recommended execute "rails generate wprof"`
|
39
|
+
|
27
40
|
---
|
28
41
|
|
29
42
|
## Register Types and how they works.
|
@@ -69,9 +82,9 @@ Done, with this WProf will be registering the execution time of said method ever
|
|
69
82
|
WProf contains a list of default settings which can all be altered by others availables as user's preferences demands. In order to do that, create a file in 'config/initializers' (RailsApp.Root >> config >> initializers >> wprof.rb). Inside, you must define the following configuration:
|
70
83
|
|
71
84
|
```ruby
|
72
|
-
|
73
|
-
config.
|
74
|
-
config.
|
85
|
+
WProf::Configuration.configure do |config|
|
86
|
+
config.db_runtime = true
|
87
|
+
config.reporter_type = 'FILE'
|
75
88
|
end
|
76
89
|
```
|
77
90
|
> In case of not correctly configuring an option or just skip it, the value would be default.
|
@@ -80,71 +93,78 @@ To avoid this configuration manually using the **configuration generator** with
|
|
80
93
|
|
81
94
|
Following the complete list of available settings and their meaning.
|
82
95
|
|
83
|
-
### config.
|
96
|
+
### config.db_runtime
|
84
97
|
Sets whether it shows or not the data "db_runtime" inside the report.
|
85
98
|
|
86
99
|
> Possible values: true o false
|
87
100
|
|
88
101
|
> Default: true
|
89
102
|
|
90
|
-
### config.
|
103
|
+
### config.reporter_type
|
91
104
|
Sets report type, meaning, how to show the obtained data. There are currently 4 available types, see "Reports" section for more information.
|
92
105
|
|
93
106
|
> Possible values: LOGGER, FILE, DATABASE, EXTERNAL
|
94
107
|
|
95
108
|
> Default: LOGGER
|
96
109
|
|
97
|
-
### config.
|
110
|
+
### config.csv_type
|
98
111
|
When the report is defined as a CSV file there are two ways of generate it.
|
99
112
|
* **MIX:** generates one CSV file where every data captured by WProf is saved. This file only contains 2 columns: in the first one is the field and in the second one the data.
|
100
113
|
* **SPLIT:** Divides storage in three different files, one for each record type. This significantly improves reading since every field is held as the file's header and the data in rows is split by comma... As it should be, of course... Why mix then?, I don't know, it could be useful for someone!
|
101
114
|
> Possible values: MIX, SPLIT.
|
102
115
|
> Default: SPLIT
|
103
116
|
|
104
|
-
### config.
|
117
|
+
### config.async
|
105
118
|
Sets whether the report is being generated sinchronously or not. **Take note: asynchronous mode requires extra steps, see "asynchronism" section for more information.**
|
106
119
|
> Possible values: false, true
|
107
120
|
> Default: false
|
108
121
|
|
109
|
-
### config.
|
122
|
+
### config.httparty_methods_to_trace
|
110
123
|
HTTParty's method captured by WProf. By default, more common ones are set and it's recommended not to modify.
|
111
124
|
This being said, there's no problem in taking out some of the array, however take special care in adding HTTParty's methods which doesn't return an http request.
|
112
125
|
> Possible values: what you want and need, must be an **array of strings**.
|
113
126
|
> Default: ['get', 'put', 'delete', 'post']
|
114
127
|
|
115
|
-
### config.
|
128
|
+
### config.external_url
|
116
129
|
In case you configure reporter_type as External, you must indicate the URL which will receive the HTTP petition.
|
117
130
|
> Possible values: any string that corresponds to an URL. Example: 'http://example-url/reporter'
|
118
131
|
> Default: nil
|
119
132
|
|
120
|
-
### config.
|
133
|
+
### config.external_headers
|
121
134
|
To add a header to the http request ("external" report type), you must define it in this setting. This must be a **HASH of RUBY**, exactly as HTTParty expects (internally Wprof uses HTTParty to send a request). An example would be:
|
122
135
|
|
123
136
|
``` ruby
|
124
|
-
config.
|
137
|
+
config.external_headers = { headers: {'User-Agent' => 'Httparty'}}
|
125
138
|
```
|
126
139
|
> Possible : Any valid hash, must respect primary key as "headers" (check example below)
|
127
140
|
> Default: nil
|
128
141
|
|
129
|
-
### config.
|
142
|
+
### config.custom_methods
|
130
143
|
If you want to capture response times of an specific method inside a class, it's not enough including the module, you'll need to indicate WProf exactly which is the one it has to capture.
|
131
144
|
This list of methods must be contained in this option in a **array of Ruby** and it has to be strings.
|
132
145
|
Example:
|
133
146
|
``` ruby
|
134
|
-
config.
|
147
|
+
config.custom_methods = [ 'my_great_method' ]
|
135
148
|
```
|
136
149
|
> Possible values: any method's name in string format, within an array. Default: nil
|
137
150
|
|
138
|
-
### config.
|
151
|
+
### config.file_path
|
139
152
|
|
140
153
|
When "FILE" is used as an output, this option allows you to choose the files destination. This must be a valid route, as string, with reading permission for Rails and also be a folder.
|
141
154
|
Example:
|
142
155
|
``` ruby
|
143
|
-
config.
|
156
|
+
config.file_path = '/home/mcolombo/examplefolder'
|
144
157
|
```
|
145
158
|
> Possible values: any string that correctly represents a PATH to a directory.
|
146
159
|
> Default: Rails.root is used, so, root is Rails application.
|
147
160
|
|
161
|
+
### config.disable_wprof
|
162
|
+
|
163
|
+
Enable or Disable Wprof when this single line.
|
164
|
+
|
165
|
+
> Possible values: true or false.
|
166
|
+
> Default: false.
|
167
|
+
|
148
168
|
---
|
149
169
|
|
150
170
|
## Generators.
|
@@ -160,7 +180,7 @@ To begin to modify options from available settings, you must create a config fil
|
|
160
180
|
```
|
161
181
|
rails generate wprof
|
162
182
|
```
|
163
|
-
This generates a model of the configuration's file with all the available options seen in "available configurations" section.
|
183
|
+
This generates a model of the configuration's file with all the available options seen in "available configurations" section. It's necessary for initializer Wprof.
|
164
184
|
|
165
185
|
### Data Model Generator
|
166
186
|
|
@@ -194,11 +214,11 @@ Data captured and reported by WProf vary depending on which record they come, al
|
|
194
214
|
* **url:** Endpoint that received the petition.
|
195
215
|
* **db_runtime:** total time when it was absorbed by the database (included in total_time).
|
196
216
|
|
197
|
-
###
|
217
|
+
### Unique for the services (Httparty).
|
198
218
|
|
199
|
-
* **code:**
|
200
|
-
* **service_hostname:** Hostname
|
201
|
-
* **request_uri:** Uri
|
219
|
+
* **code:** Response code received (Status), eg. 200, 404, etc.
|
220
|
+
* **service_hostname:** Hostname of service.
|
221
|
+
* **request_uri:** Uri of endpoint.
|
202
222
|
|
203
223
|
### Unique for services (Httparty).
|
204
224
|
|
@@ -291,15 +311,13 @@ The options to be set are: external_url and external_headers. See Configurations
|
|
291
311
|
|
292
312
|
## Asynchronism.
|
293
313
|
|
294
|
-
WProf by default reports all the information **synchronous**, although it’s possible to configure the tool in order to do this process **asynchronous**. To achieve this, you must first activate the option through config field "config.
|
314
|
+
WProf by default reports all the information **synchronous**, although it’s possible to configure the tool in order to do this process **asynchronous**. To achieve this, you must first activate the option through config field "config.async = true", however this is not enough. For all of the report be made asynchronous, you must have functional and operational **Sidekiq**, since WProf uses it to that purpose. If you’re not familiar with the tool, you could give it a look to its [repository by clicking here!.](https://github.com/mperham/sidekiq).
|
295
315
|
|
296
316
|
---
|
297
317
|
|
298
318
|
## Handled errors.
|
299
319
|
|
300
320
|
Any error among the capture and report of the information **MUSTN’T** interrupt the normal functioning of your Rails application. If this is the case, please report it. During the execution, could show up two errors in application’s logger.
|
301
|
-
WProf ERROR when try parsing service response:
|
302
|
-
An error was raised when WProf tried to send data to reporter: This is the most common error and it will appear if the data sending to the selected destination (meaning Logger, Database, File o External) has failed.
|
303
321
|
|
304
322
|
```WProf ERROR when try parsing service response:``` This error may appear if HTTParty wouldn’t be able to capture some data.
|
305
323
|
|
data/doc/user-guide_es.md
CHANGED
@@ -8,19 +8,33 @@ Wor-prof (Wprof) es una gema para Ruby On Rails cuyo único objetivo es el medir
|
|
8
8
|
|
9
9
|
El primer paso es instalar la gema (por supuesto) y la forma es bien conocida, pero por si acaso acá están los pasos a seguir.
|
10
10
|
|
11
|
-
###
|
11
|
+
### Instalación
|
12
12
|
Agregar la siguiente línea en el gemfile de tu aplicación Rails:
|
13
13
|
|
14
14
|
```ruby
|
15
15
|
gem 'wor-prof'
|
16
16
|
```
|
17
17
|
|
18
|
-
|
18
|
+
ejecute:
|
19
19
|
```bash
|
20
20
|
$ bundle install
|
21
21
|
```
|
22
|
+
|
23
|
+
Por último, ejecute:
|
24
|
+
```bash
|
25
|
+
$ rails generate wprof (o cree/copie el initializer usted mismo)
|
26
|
+
```
|
27
|
+
|
22
28
|
**Eso es todo!!** Al correr el servidor Wprof comienza inmediatamente a trabajar con la configuración por defecto por lo que no hay que configurar nada si coincide con sus necesidades, pero si no es así puede consultar la sección de **Configuraciones Disponibles**.
|
23
29
|
|
30
|
+
`Si no corre el generador de Wprof, debe inicializar Wprof. Para hacer esto, agregue la siguiente linea en cualquier initializers`
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
WProf::Configuration.initiate_wprof
|
34
|
+
```
|
35
|
+
|
36
|
+
`Es altamente recomendable que ejecue "rails generate wprof"`
|
37
|
+
|
24
38
|
---
|
25
39
|
|
26
40
|
## Tipos de registros y cómo funciona.
|
@@ -61,78 +75,85 @@ Listo, con esto Wprof estará registrando el tiempo de ejecución de dicho méto
|
|
61
75
|
|
62
76
|
## Configuraciones disponibles.
|
63
77
|
|
64
|
-
Por defecto Wprof
|
78
|
+
Por defecto Wprof contiene una lista de configuraciones por defecto, pero todas estas pueden ser modificadas por otras disponibles de acuerdo a las preferencias del usuario. Para lograr esto se debe crear un archivo en 'config/initializers' (RailsApp.Root >> config >> initializers >> wprof.rb).
|
65
79
|
Dentro del mismo se debe definir la configuración de esta manera:
|
66
80
|
|
67
81
|
```ruby
|
68
|
-
|
69
|
-
config.
|
70
|
-
config.
|
82
|
+
WProf::Configuration.configure do |config|
|
83
|
+
config.db_runtime = true
|
84
|
+
config.reporter_type = 'FILE'
|
71
85
|
end
|
72
86
|
```
|
73
87
|
> En caso de no configurar correctamente una opción u omitirla, se tomarán los valores por defecto.
|
74
88
|
|
75
|
-
|
89
|
+
Puede evitar esta configuración manualmente utilizando el **Generador de Configuración** con el comando "rails generate wprof" (consulte la sección de generadores).
|
76
90
|
|
77
91
|
A continuación se ofrece la lista completa de configuraciones disponibles y sus significados.
|
78
92
|
|
79
|
-
### config.
|
93
|
+
### config.db_runtime
|
80
94
|
Define si se debe mostrar o no el dato "db_runtime" dentro del reporte.
|
81
95
|
> Valores Posibles: true o false
|
82
96
|
> Por defecto: true
|
83
97
|
|
84
|
-
### config.
|
98
|
+
### config.reporter_type
|
85
99
|
Establece el tipo de reporte, es decir, como exponen los datos obtenidos, existen cuatro tipo disponible actualmente, Ver sección "Reportes" para más información.
|
86
100
|
> Valores Posibles: LOGGER, FILE, DATABASE, EXTERNAL
|
87
101
|
> Por defecto: LOGGER
|
88
102
|
|
89
|
-
### config.
|
103
|
+
### config.csv_type
|
90
104
|
Cuando se define el reporte como un archivo CSV existen dos formas de generarlos.
|
91
105
|
* **MIX:** Genera un único archivo CSV donde se guardan los datos de **todo** lo que captura WProf. Este archivo solo tiene 2 columnas: En la primera se guarda el campo y en la segunda el dato.
|
92
106
|
* **SPLIT:** Divide el almacenamiento en tres archivos distintos, uno por cada tipo de registro. Esto mejora significamente la lectura ya que cada campo está como encabezado del archivo y los datos en la filas separados por coma... como debe ser claro... ¿Por que mix entonces?, no sé, a alguno le puede servir!
|
93
107
|
> Valores Posibles: MIX, SPLIT
|
94
108
|
> Por defecto: SPLIT
|
95
109
|
|
96
|
-
### config.
|
110
|
+
### config.async
|
97
111
|
Define si el reporte se gestará de forma Sincrónica o Asincronica. **Tome nota: la forma asincrónica requiere pasos adicionales, consulte la sección de "Asincronismo" para más información**
|
98
112
|
> Valores Posibles: false, true
|
99
113
|
> Por defecto: false
|
100
114
|
|
101
|
-
### config.
|
115
|
+
### config.httparty_methods_to_trace
|
102
116
|
Métodos de HTTParty que WProf va a capturar. Por defecto se colocan los más comunes y se recomienda no modificar. Dicho esto, no hay problema en quitar algunos del array, pero tenga especial cuidado en agregar métodos de HTTParty que no devuelvan un request HTTP).
|
103
117
|
> Valores Posibles: Los que quiera, debe si o si ser un **Array** de strings.
|
104
118
|
> Por defecto: ['get', 'put', 'delete', 'post']
|
105
119
|
|
106
|
-
### config.
|
120
|
+
### config.external_url
|
107
121
|
En caso de que se configure el reporter_type como External, se debe indicar la URL a la que se enviará la petición HTTP.
|
108
122
|
> Valores posibles: Cualquier cadena de texto que corresponda a una URL. Ejemplo: 'http://example-url/reporter'
|
109
123
|
> Por defecto: nil
|
110
124
|
|
111
|
-
### config.
|
125
|
+
### config.external_headers
|
112
126
|
Para agregar una cabecera al request HTTP (para el tipo de reporte "External"), debe definirlo en esta configuración. La misma debe ser un **HASH de RUBY** tal cual como espera HTTParty recibir (internamente Wprof utiliza HTTParty para enviar el request). Un ejemplo de esto sería:
|
113
127
|
``` ruby
|
114
|
-
config.
|
128
|
+
config.external_headers = { headers: {'User-Agent' => 'Httparty'}}
|
115
129
|
```
|
116
130
|
> Valores posibles: Cualquier hash válido, debe respetarse la primera clave como "headers" (ver ejemplo arriba)
|
117
131
|
> Por defecto: nil
|
118
132
|
|
119
|
-
### config.
|
133
|
+
### config.custom_methods
|
120
134
|
Si desea capturar los tiempos de respuesta de un método específico dentro de una clase, no basta con incluir el módulo, debe indicarle a Wprof cual es exactamente aquel que desea capturar. Esta lista de métodos debe estar contenida en está opción dentro de un **Array de Ruby** y deben ser strings. Ejemplo:
|
121
135
|
``` ruby
|
122
|
-
config.
|
136
|
+
config.custom_methods = [ 'my_great_method' ]
|
123
137
|
```
|
124
138
|
> Valores posibles: Cualquier nombre de método en formato string, contenido en un array.
|
125
139
|
> Por defecto: nil
|
126
140
|
|
127
|
-
### config.
|
141
|
+
### config.file_path
|
128
142
|
|
129
143
|
Cuando se utiliza "FILE" como salida de datos, esta opción permite elegir la ruta de destino de los archivos. Esta debe ser una ruta válida, en formato string, con permisos de escritura para la aplicación Rails y cuyo último valor debe ser una carpeta. Ejemplo:
|
130
144
|
``` ruby
|
131
|
-
config.
|
145
|
+
config.file_path = '/home/mcolombo/examplefolder'
|
132
146
|
```
|
133
147
|
> Valores posible: Cualquier string que represente correctamente un PATH hasta un directorio.
|
134
148
|
> Por defecto: Se utiliza 'Rails.root', es decir, la raíz de su aplicación Rails.
|
135
149
|
|
150
|
+
### config.disable_wprof
|
151
|
+
|
152
|
+
Activa o Desactiva Wprof con una simple línea
|
153
|
+
|
154
|
+
> Valores posibles: true or false.
|
155
|
+
> Por defecto: false.
|
156
|
+
|
136
157
|
---
|
137
158
|
|
138
159
|
## Generadores.
|
@@ -280,7 +301,7 @@ Las opciones a configurar son: external_url y external_headers. Consulte la secc
|
|
280
301
|
|
281
302
|
## Asincronismo.
|
282
303
|
|
283
|
-
WProf por defecto reporta toda la información de manera ***sincronica**, sin embargo es posible configurar la herramienta para que este proceso lo haga de forma **asincronica**. Para lograr esto se debe en primer lugar activar la opción mediante la configuración del campo "config.
|
304
|
+
WProf por defecto reporta toda la información de manera ***sincronica**, sin embargo es posible configurar la herramienta para que este proceso lo haga de forma **asincronica**. Para lograr esto se debe en primer lugar activar la opción mediante la configuración del campo "config.async = true", sin embargo esto no es suficiente.
|
284
305
|
Para que todo el reporte se efectúe Asincrónicamente, es necesario tener funcional y operativo **Sidekiq**, ya que WProf lo utiliza para tal fin. Si no está familiarizado con la herramienta, puede buscar más información en el [repositorio de la misma haciendo click aquí!](https://github.com/mperham/sidekiq).
|
285
306
|
|
286
307
|
---
|
@@ -11,31 +11,34 @@ class WprofGenerator < Rails::Generators::Base
|
|
11
11
|
# -----------------------------------------
|
12
12
|
# Uncomment and set for use custom options.
|
13
13
|
# -----------------------------------------
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
14
|
+
WProf::Configuration.configure do |config|
|
15
|
+
## Save DB Runtime?: Default: true
|
16
|
+
# config.db_runtime = true
|
17
|
+
## Reporter Type (¿When we will save our data?): 'LOGGER' by default.
|
18
|
+
## Another options: 'FILE' (For CSV), 'DATABASE' (For Rails DB), 'EXTERNAL' (For external API).
|
19
|
+
# config.reporter_type = 'LOGGER'
|
20
|
+
## CSV Type (One CSV file for each type of data or all together)
|
21
|
+
## 'SPLIT' by default, Options: 'MIX'
|
22
|
+
# config.csv_type = 'SPLIT'
|
23
|
+
## Reporter must be work async? Default: false
|
24
|
+
# config.async = false
|
25
|
+
## Httparty Methods to wrapper.
|
26
|
+
# config.httparty_methods_to_trace = ['get', 'put', 'delete', 'post']
|
27
|
+
## External URL for hit when Reporter Type is EXTERNAL
|
28
|
+
## DEFAULT: nil
|
29
|
+
# config.external_url = 'http://example-url/reporter'
|
30
|
+
## Define Headers for Reporter Type when is EXTERNAL.
|
31
|
+
## Must be a Hash (see HTTPARTY doc for more info)
|
32
|
+
## DEFAULT: nil
|
33
|
+
# config.external_headers = { headers: {'User-Agent' => 'Httparty'}}
|
34
|
+
## Define your Custom Methods here! (Must be an Array)
|
35
|
+
# config.custom_methods = [ 'my_great_method' ]
|
36
|
+
## Define your own path for save Files when Reporter Type is FILE
|
37
|
+
## By default Wor-Prof use Rails.root
|
38
|
+
# config.file_path = '/home/mcolombo/examplefolder'
|
39
|
+
## Enable/Disable Wprof
|
40
|
+
## Default: false
|
41
|
+
# config.disable_wprof = false
|
39
42
|
end
|
40
43
|
CONTENT
|
41
44
|
end
|
data/lib/wor-prof.rb
CHANGED
data/lib/wprof/conf_wprof.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
module WProf
|
2
|
-
|
2
|
+
module Configuration
|
3
|
+
def self.configure
|
4
|
+
yield Config
|
5
|
+
initiate_wprof
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.initiate_wprof
|
9
|
+
WprofSubscriptors.subscriptors unless WProf::Config.disable_wprof
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Config
|
3
14
|
DEFAULTS_CONFIGS = {
|
4
15
|
db_runtime: true,
|
5
16
|
reporter_type: 'LOGGER',
|
@@ -9,17 +20,26 @@ module WProf
|
|
9
20
|
external_url: nil,
|
10
21
|
external_headers: nil,
|
11
22
|
custom_methods: nil,
|
12
|
-
file_path: Rails.root.to_s
|
23
|
+
file_path: Rails.root.to_s,
|
24
|
+
disable_wprof: false
|
13
25
|
}.freeze
|
14
26
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
27
|
+
module_function
|
28
|
+
|
29
|
+
DEFAULTS_CONFIGS.each do |key, value|
|
30
|
+
define_method key do
|
31
|
+
instance_variable_get("@#{key}") || instance_variable_set("@#{key}", value)
|
32
|
+
end
|
33
|
+
|
34
|
+
define_method "#{key}=" do |v|
|
35
|
+
instance_variable_set("@#{key}", v)
|
22
36
|
end
|
23
37
|
end
|
38
|
+
|
39
|
+
def get_value(param)
|
40
|
+
value = send(param)
|
41
|
+
return value unless value.nil?
|
42
|
+
DEFAULTS_CONFIGS[param]
|
43
|
+
end
|
24
44
|
end
|
25
45
|
end
|
@@ -3,9 +3,9 @@ module Wprof
|
|
3
3
|
module FileReport
|
4
4
|
def generate_file_report
|
5
5
|
require 'csv'
|
6
|
-
csv_type = WProf::Config.get_value(:csv_type)
|
6
|
+
csv_type = WProf::Config.get_value(:csv_type)
|
7
7
|
path = WProf::Config.get_value(:file_path)
|
8
|
-
send(
|
8
|
+
send("write_#{csv_type.downcase}_file", path)
|
9
9
|
end
|
10
10
|
|
11
11
|
def write_mix_file(path)
|
data/lib/wprof/version.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
class WprofSubscriptors
|
2
|
+
def self.subscriptors
|
3
|
+
ActiveSupport::Notifications.subscribe 'process_action.action_controller' do |*args|
|
4
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
5
|
+
GenProf.new(event, :standard)
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
ActiveSupport::Notifications.subscribe 'wprof.service' do |*args|
|
9
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
10
|
+
GenProf.new(event, :service)
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
ActiveSupport::Notifications.subscribe 'wprof.custom' do |*args|
|
14
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
15
|
+
GenProf.new(event, :custom)
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|