Skip to content

Commit f8b6d38

Browse files
committed
feat: adding profiler to the core
1 parent 24a0cec commit f8b6d38

File tree

6 files changed

+93
-4
lines changed

6 files changed

+93
-4
lines changed

adonis-typings/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
/// <reference path="./http-context.ts" />
2020
/// <reference path="./logger.ts" />
2121
/// <reference path="./middleware-store.ts" />
22+
/// <reference path="./profiler.ts" />
2223
/// <reference path="./request-logger.ts" />
2324
/// <reference path="./request.ts" />
2425
/// <reference path="./response.ts" />

adonis-typings/profiler.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* @adonisjs/core
3+
*
4+
* (c) Harminder Virk <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
/**
11+
* The binding for the given module is defined inside `providers/AppProvider.ts`
12+
* file.
13+
*/
14+
declare module '@ioc:Adonis/Core/Profiler' {
15+
import { ProfilerContract as BaseContract, ProfilerConfig } from '@poppinss/profiler'
16+
17+
const Profiler: ProfilerContract
18+
19+
/**
20+
* Module exports
21+
*/
22+
export interface ProfilerContract extends BaseContract {}
23+
export { ProfilerConfig as ProfilerConfigContract }
24+
export default Profiler
25+
}

config/app.txt

+40
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { LoggerConfigContract } from '@ioc:Adonis/Core/Logger'
1111
import { RequestConfigContract } from '@ioc:Adonis/Core/Request'
1212
import { ResponseConfigContract } from '@ioc:Adonis/Core/Response'
1313
import { RequestLoggerConfigContract } from '@ioc:Adonis/Core/RequestLogger'
14+
import { ProfilerConfigContract } from '@ioc:Adonis/Core/Profiler'
1415

1516
type HttpOptions = RequestConfigContract & ResponseConfigContract & RequestLoggerConfigContract
1617

@@ -193,3 +194,42 @@ export const logger: LoggerConfigContract = {
193194
*/
194195
prettyPrint: Env.get('NODE_ENV') === 'development',
195196
}
197+
198+
/*
199+
|--------------------------------------------------------------------------
200+
| Profiler
201+
|--------------------------------------------------------------------------
202+
*/
203+
export const profiler: ProfilerConfigContract = {
204+
/*
205+
|--------------------------------------------------------------------------
206+
| Toggle profiler
207+
|--------------------------------------------------------------------------
208+
|
209+
| Enable or disable profiler
210+
|
211+
*/
212+
enabled: true,
213+
214+
/*
215+
|--------------------------------------------------------------------------
216+
| Blacklist actions/row labels
217+
|--------------------------------------------------------------------------
218+
|
219+
| Define an array of actions or row labels that you want to disable from
220+
| getting profiled.
221+
|
222+
*/
223+
blacklist: [],
224+
225+
/*
226+
|--------------------------------------------------------------------------
227+
| Whitelist actions/row labels
228+
|--------------------------------------------------------------------------
229+
|
230+
| Define an array of actions or row labels that you want to whitelist for
231+
| the profiler. When whitelist is defined, then `blacklist` is ignored.
232+
|
233+
*/
234+
whitelist: [],
235+
}

package-lock.json

+12-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@
8686
"@poppinss/env": "^1.0.5",
8787
"@poppinss/events": "^1.0.1",
8888
"@poppinss/hash": "^1.0.3",
89-
"@poppinss/http-server": "^1.2.0",
89+
"@poppinss/http-server": "^1.2.1",
9090
"@poppinss/logger": "^1.1.2",
91+
"@poppinss/profiler": "^1.0.0",
9192
"@poppinss/utils": "^1.0.4",
9293
"find-package-json": "^1.2.0",
9394
"ms": "^2.1.2",

providers/AppProvider.ts

+13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { requireAll } from '@poppinss/utils'
1717
import { IocContract } from '@adonisjs/fold'
1818
import { Response } from '@poppinss/response'
1919
import { ApplicationContract } from '@poppinss/application'
20+
import { Profiler } from '@poppinss/profiler'
2021
import { Server, HttpContext, MiddlewareStore, Router, routePreProcessor } from '@poppinss/http-server'
2122

2223
import { envLoader } from '../src/envLoader'
@@ -63,6 +64,16 @@ export default class AppProvider {
6364
})
6465
}
6566

67+
/**
68+
* Register profiler under `Adonis/Core/Profiler` namespace
69+
*/
70+
protected $registerProfiler () {
71+
this.$container.singleton('Adonis/Core/Profiler', () => {
72+
const Config = this.$container.use('Adonis/Core/Config')
73+
return new Profiler(Config.get('app.profiler', {}))
74+
})
75+
}
76+
6677
/**
6778
* Registering the env binding to the container. We also parse the
6879
* contents of the `.env` and `.env.testing` files.
@@ -112,6 +123,7 @@ export default class AppProvider {
112123
this.$container.use('Adonis/Core/Route'),
113124
this.$container.use('Adonis/Core/MiddlewareStore'),
114125
this.$container.use('Adonis/Core/Logger'),
126+
this.$container.use('Adonis/Core/Profiler'),
115127
Object.assign({ secret }, httpConfig),
116128
)
117129
})
@@ -179,6 +191,7 @@ export default class AppProvider {
179191
this.$registerEnv()
180192
this.$registerConfigProvider()
181193
this.$registerLogger()
194+
this.$registerProfiler()
182195
this.$registerRequestResponse()
183196
this.$registerRouter()
184197
this.$registerMiddlewareStore()

0 commit comments

Comments
 (0)