@searchspring/snap-profiler 0.70.1 → 0.72.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +28 -77
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,132 +1,83 @@
1
1
  # Snap Profiler
2
2
 
3
- <a href="https://www.npmjs.com/package/@searchspring/snap-profiler"><img alt="NPM Status" src="https://img.shields.io/npm/v/@searchspring/snap-profiler.svg?style=flat"></a>
4
3
 
5
- A utility for recording how long something takes to complete. `Profiler` is used in finding API response, component rendering and Middleware execution times.
4
+ Snap Profiler is a utility available on each controller via `controller.profiler` for recording how long something takes to complete. `Profiler` is used in finding API response, component rendering and Middleware execution times.
6
5
 
7
6
 
8
- ## Dependency
7
+ ## `setNamespace` method
8
+ Programmatically set the namespace after construction.
9
9
 
10
- Snap Profiler is a dependency of [@searchspring/snap-controller](https://github.com/searchspring/snap/tree/main/packages/snap-controller) <a href="https://www.npmjs.com/package/@searchspring/snap-controller"><img alt="NPM Status" src="https://img.shields.io/npm/v/@searchspring/snap-controller.svg?style=flat"></a>
11
-
12
- ## Installation
13
-
14
- ```bash
15
- npm install --save @searchspring/snap-profiler
16
- ```
17
-
18
- ## Import
19
- ```typescript
20
- import { Profiler } from '@searchspring/snap-profiler';
21
- ```
22
-
23
-
24
- <h2 id="Profiler">Profiler</h2>
25
- An optional `namespace` can be passed to the Profiler constructor for profile organization.
26
-
27
- ```typescript
28
- import { Profiler } from '@searchspring/snap-profiler';
29
-
30
- const profiler = new Profiler('namespace');
31
- ```
32
-
33
- ### `setNamespace` method
34
- Programatically set the namespace after construction.
35
-
36
- ```typescript
37
- import { Profiler } from '@searchspring/snap-profiler';
38
-
39
- const profiler = new Profiler();
40
-
41
- profiler.setNamespace('namespace');
10
+ ```js
11
+ controller.profiler.setNamespace('namespace');
42
12
  ```
43
13
 
44
- ### `create` method
14
+ ## `create` method
45
15
  Create a new profile.
46
16
 
47
- ```typescript
48
- import { Profiler } from '@searchspring/snap-profiler';
49
-
50
- const profiler = new Profiler();
51
-
52
- const searchProfile = profiler.create({
17
+ ```js
18
+ const searchProfile = controller.profiler.create({
53
19
  type: 'event',
54
20
  name: 'search',
55
- context: params
56
- }: ProfileDetails);
21
+ context: params // any additional context
22
+ });
57
23
  ```
58
24
 
59
- ```typescript
60
- type ProfileDetails<T> = {
61
- type: string;
62
- name: string;
63
- context: T;
64
- }
65
- ```
66
-
67
- Returns an instance of `Profile`.
68
-
69
-
70
- <h2 id="Profile">Profile</h2>
71
-
72
- `Profile` is not an exported member of the Snap Profiler package. It is only returned in the Profiler `create` method.
73
-
74
- ### `start` method
25
+ ## `start` method
75
26
 
76
27
  This will start the profiler timer.
77
28
 
78
- ```typescript
29
+ ```js
79
30
  searchProfile.start();
80
31
  ```
81
32
 
82
- ### `stop` method
33
+ ## `stop` method
83
34
  This will stop the profiler timer.
84
35
 
85
- ```typescript
36
+ ```js
86
37
  searchProfile.stop();
87
38
  ```
88
39
 
89
- ### `namespace` property
40
+ ## `namespace` property
90
41
  Profile namespace that was set using the `Profiler` constructor or the `setNamespace` method.
91
42
 
92
- ```typescript
43
+ ```js
93
44
  console.log(`namespace: ${searchProfile.namespace}`);
94
45
  ```
95
46
 
96
- ### `type` property
47
+ ## `type` property
97
48
  Profile type that was set in the `create` method `ProfileDetails` parameters.
98
49
 
99
- ```typescript
50
+ ```js
100
51
  console.log(`type: ${searchProfile.type}`);
101
52
  ```
102
53
 
103
- ### `name` property
54
+ ## `name` property
104
55
  Profile name that was set in the `create` method `ProfileDetails` parameters.
105
56
 
106
- ```typescript
57
+ ```js
107
58
  console.log(`name: ${searchProfile.name}`);
108
59
  ```
109
60
 
110
- ### `context` property
111
- Profile context that was set in the `create` method `ProfileDetails` parameters. The context is used to provide additional details regarding the profile. A search profile would likely contain the request parameters amoung other things.
61
+ ## `context` property
62
+ Profile context that was set in the `create` method `ProfileDetails` parameters. The context is used to provide additional details regarding the profile. A search profile would likely contain the request parameters among other things.
112
63
 
113
- ```typescript
64
+ ```js
114
65
  console.log(`context: ${searchProfile.context}`);
115
66
  ```
116
67
 
117
- ### `status` property
68
+ ## `status` property
118
69
  Profile status. The default value is `pending`.
119
70
 
120
71
  The value will change to `started` when the `start` method is invoked and to `finished` when the `stop` method is invoked.
121
72
 
122
- ```typescript
73
+ ```js
123
74
  console.log(`context: ${searchProfile.status}`);
124
75
  ```
125
76
 
126
- ### `time` property
77
+ ## `time` property
127
78
  Profile time object is of type `ProfileTime`:
128
79
 
129
- ```typescript
80
+ ```js
130
81
  type ProfileTime = {
131
82
  date: number;
132
83
  begin: number;
@@ -145,4 +96,4 @@ type ProfileTime = {
145
96
 
146
97
 
147
98
  ## Logging profiles
148
- It is recommended to using the Snap Logger's `profile` method to log Snap Profiles as it provides a clean output for easy parsing.
99
+ It is recommended to use the [Snap Logger's `profile`](https://searchspring.github.io/snap/reference-logger#profile-method) method to log Snap Profiles as it provides a clean output for easy parsing.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@searchspring/snap-profiler",
3
- "version": "0.70.1",
3
+ "version": "0.72.0",
4
4
  "description": "Snap Profiler",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -23,5 +23,5 @@
23
23
  "files": [
24
24
  "dist/**/*"
25
25
  ],
26
- "gitHead": "91ca0ec407be1edb997da1256242d167aa7da79f"
26
+ "gitHead": "737d4bd308ebbb852fe3f09b2b90f4af87bbe264"
27
27
  }