bare-performance 1.2.1 → 1.3.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.
package/CMakeLists.txt CHANGED
@@ -1,9 +1,27 @@
1
- cmake_minimum_required(VERSION 3.25)
1
+ cmake_minimum_required(VERSION 4.0)
2
2
 
3
3
  find_package(cmake-bare REQUIRED PATHS node_modules/cmake-bare)
4
+ find_package(cmake-fetch REQUIRED PATHS node_modules/cmake-fetch)
4
5
 
5
6
  project(bare_performance C)
6
7
 
8
+ fetch_package(
9
+ "github:madler/zlib@1.3.1"
10
+ SOURCE_DIR zlib_SOURCE_DIR
11
+ BINARY_DIR zlib_BINARY_DIR
12
+ )
13
+
14
+ set(ZLIB_INCLUDE_DIR ${zlib_SOURCE_DIR} ${zlib_BINARY_DIR})
15
+ set(ZLIB_LIBRARY $<TARGET_FILE:zlibstatic>)
16
+
17
+ add_library(ZLIB::ZLIB ALIAS zlibstatic)
18
+
19
+ option(HDR_HISTOGRAM_BUILD_PROGRAMS OFF)
20
+ option(HDR_HISTOGRAM_INSTALL_SHARED OFF)
21
+ option(HDR_HISTOGRAM_INSTALL_STATIC OFF)
22
+
23
+ fetch_package("github:HdrHistogram/HdrHistogram_c#0.11.9")
24
+
7
25
  add_bare_module(bare_performance)
8
26
 
9
27
  target_sources(
@@ -11,3 +29,9 @@ target_sources(
11
29
  PRIVATE
12
30
  binding.c
13
31
  )
32
+
33
+ target_link_libraries(
34
+ ${bare_performance}
35
+ PRIVATE
36
+ hdr_histogram_static
37
+ )
package/LICENSE CHANGED
@@ -1,201 +1,201 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/binding.c CHANGED
@@ -1,15 +1,22 @@
1
1
  #include <assert.h>
2
2
  #include <bare.h>
3
+ #include <hdr/hdr_histogram.h>
3
4
  #include <js.h>
4
5
  #include <stdlib.h>
5
6
  #include <uv.h>
6
7
 
8
+ typedef struct {
9
+ js_ref_t *ctx;
10
+
11
+ struct hdr_histogram *histogram;
12
+ } bare_performance_histogram_t;
13
+
7
14
  static js_value_t *
8
15
  bare_performance_now(js_env_t *env, js_callback_info_t *info) {
9
16
  int err;
10
17
 
11
18
  js_value_t *result;
12
- err = js_create_double(env, uv_hrtime() / 1e6, &result);
19
+ err = js_create_double(env, uv_hrtime(), &result);
13
20
  assert(err == 0);
14
21
 
15
22
  return result;
@@ -17,7 +24,7 @@ bare_performance_now(js_env_t *env, js_callback_info_t *info) {
17
24
 
18
25
  static double
19
26
  bare_performance_now_typed(js_value_t *receiver, js_typed_callback_info_t *info) {
20
- return uv_hrtime() / 1e6;
27
+ return uv_hrtime();
21
28
  }
22
29
 
23
30
  static js_value_t *
@@ -83,6 +90,287 @@ bare_performance_metrics_info(js_env_t *env, js_callback_info_t *info) {
83
90
  return result;
84
91
  }
85
92
 
93
+ static js_value_t *
94
+ bare_performance_histogram_init(js_env_t *env, js_callback_info_t *info) {
95
+ int err;
96
+
97
+ size_t argc = 4;
98
+ js_value_t *argv[4];
99
+
100
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
101
+ assert(err == 0);
102
+
103
+ assert(argc == 4);
104
+
105
+ js_value_t *handle;
106
+
107
+ bare_performance_histogram_t *histogram;
108
+ err = js_create_arraybuffer(env, sizeof(bare_performance_histogram_t), (void **) &histogram, &handle);
109
+
110
+ err = js_create_reference(env, argv[0], 1, &histogram->ctx);
111
+ assert(err == 0);
112
+
113
+ int64_t lowest;
114
+ err = js_get_value_int64(env, argv[1], &lowest);
115
+ assert(err == 0);
116
+
117
+ int64_t highest;
118
+ err = js_get_value_int64(env, argv[2], &highest);
119
+ assert(err == 0);
120
+
121
+ int64_t figures;
122
+ err = js_get_value_int64(env, argv[3], &figures);
123
+ assert(err == 0);
124
+
125
+ err = hdr_init(lowest, highest, figures, &histogram->histogram);
126
+ assert(err == 0);
127
+
128
+ return handle;
129
+ }
130
+
131
+ static js_value_t *
132
+ bare_performance_histogram_percentiles(js_env_t *env, js_callback_info_t *info) {
133
+ int err;
134
+
135
+ size_t argc = 1;
136
+ js_value_t *argv[1];
137
+
138
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
139
+ assert(err == 0);
140
+
141
+ assert(argc == 1);
142
+
143
+ bare_performance_histogram_t *histogram;
144
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &histogram, NULL);
145
+ assert(err == 0);
146
+
147
+ struct hdr_iter iter;
148
+ hdr_iter_percentile_init(&iter, histogram->histogram, 1.0);
149
+
150
+ js_value_t *result;
151
+ err = js_create_array(env, &result);
152
+ assert(err == 0);
153
+
154
+ uint32_t i = 0;
155
+
156
+ while (hdr_iter_next(&iter)) {
157
+ js_value_t *pair;
158
+ err = js_create_array_with_length(env, 2, &pair);
159
+ assert(err == 0);
160
+
161
+ js_value_t *key;
162
+ err = js_create_double(env, iter.specifics.percentiles.percentile, &key);
163
+ assert(err == 0);
164
+
165
+ err = js_set_element(env, pair, 0, key);
166
+ assert(err == 0);
167
+
168
+ js_value_t *value;
169
+ err = js_create_double(env, iter.value, &value);
170
+ assert(err == 0);
171
+
172
+ err = js_set_element(env, pair, 1, value);
173
+ assert(err == 0);
174
+
175
+ err = js_set_element(env, result, i++, pair);
176
+ assert(err == 0);
177
+ }
178
+
179
+ return result;
180
+ }
181
+
182
+ static js_value_t *
183
+ bare_performance_histogram_percentile(js_env_t *env, js_callback_info_t *info) {
184
+ int err;
185
+
186
+ size_t argc = 2;
187
+ js_value_t *argv[2];
188
+
189
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
190
+ assert(err == 0);
191
+
192
+ assert(argc == 2);
193
+
194
+ bare_performance_histogram_t *histogram;
195
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &histogram, NULL);
196
+ assert(err == 0);
197
+
198
+ double percentile;
199
+ err = js_get_value_double(env, argv[1], &percentile);
200
+ assert(err == 0);
201
+
202
+ js_value_t *result;
203
+ err = js_create_int64(env, hdr_value_at_percentile(histogram->histogram, percentile), &result);
204
+ assert(err == 0);
205
+
206
+ return result;
207
+ }
208
+
209
+ static js_value_t *
210
+ bare_performance_histogram_min(js_env_t *env, js_callback_info_t *info) {
211
+ int err;
212
+
213
+ size_t argc = 1;
214
+ js_value_t *argv[1];
215
+
216
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
217
+ assert(err == 0);
218
+
219
+ assert(argc == 1);
220
+
221
+ bare_performance_histogram_t *histogram;
222
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &histogram, NULL);
223
+ assert(err == 0);
224
+
225
+ js_value_t *result;
226
+ err = js_create_int64(env, hdr_min(histogram->histogram), &result);
227
+ assert(err == 0);
228
+
229
+ return result;
230
+ }
231
+
232
+ static js_value_t *
233
+ bare_performance_histogram_max(js_env_t *env, js_callback_info_t *info) {
234
+ int err;
235
+
236
+ size_t argc = 1;
237
+ js_value_t *argv[1];
238
+
239
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
240
+ assert(err == 0);
241
+
242
+ assert(argc == 1);
243
+
244
+ bare_performance_histogram_t *histogram;
245
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &histogram, NULL);
246
+ assert(err == 0);
247
+
248
+ js_value_t *result;
249
+ err = js_create_int64(env, hdr_max(histogram->histogram), &result);
250
+ assert(err == 0);
251
+
252
+ return result;
253
+ }
254
+
255
+ static js_value_t *
256
+ bare_performance_histogram_mean(js_env_t *env, js_callback_info_t *info) {
257
+ int err;
258
+
259
+ size_t argc = 1;
260
+ js_value_t *argv[1];
261
+
262
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
263
+ assert(err == 0);
264
+
265
+ assert(argc == 1);
266
+
267
+ bare_performance_histogram_t *histogram;
268
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &histogram, NULL);
269
+ assert(err == 0);
270
+
271
+ js_value_t *result;
272
+ err = js_create_double(env, hdr_mean(histogram->histogram), &result);
273
+ assert(err == 0);
274
+
275
+ return result;
276
+ }
277
+
278
+ static js_value_t *
279
+ bare_performance_histogram_stddev(js_env_t *env, js_callback_info_t *info) {
280
+ int err;
281
+
282
+ size_t argc = 1;
283
+ js_value_t *argv[1];
284
+
285
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
286
+ assert(err == 0);
287
+
288
+ assert(argc == 1);
289
+
290
+ bare_performance_histogram_t *histogram;
291
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &histogram, NULL);
292
+ assert(err == 0);
293
+
294
+ js_value_t *result;
295
+ err = js_create_double(env, hdr_stddev(histogram->histogram), &result);
296
+ assert(err == 0);
297
+
298
+ return result;
299
+ }
300
+
301
+ static js_value_t *
302
+ bare_performance_histogram_record(js_env_t *env, js_callback_info_t *info) {
303
+ int err;
304
+
305
+ size_t argc = 2;
306
+ js_value_t *argv[2];
307
+
308
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
309
+ assert(err == 0);
310
+
311
+ assert(argc == 2);
312
+
313
+ bare_performance_histogram_t *histogram;
314
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &histogram, NULL);
315
+ assert(err == 0);
316
+
317
+ int64_t value;
318
+ err = js_get_value_int64(env, argv[1], &value);
319
+ assert(err == 0);
320
+
321
+ js_value_t *result;
322
+ err = js_get_boolean(env, hdr_record_value(histogram->histogram, value), &result);
323
+ assert(err == 0);
324
+
325
+ return result;
326
+ }
327
+
328
+ static js_value_t *
329
+ bare_performance_histogram_add(js_env_t *env, js_callback_info_t *info) {
330
+ int err;
331
+
332
+ size_t argc = 2;
333
+ js_value_t *argv[2];
334
+
335
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
336
+ assert(err == 0);
337
+
338
+ assert(argc == 2);
339
+
340
+ bare_performance_histogram_t *histogram;
341
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &histogram, NULL);
342
+ assert(err == 0);
343
+
344
+ bare_performance_histogram_t *from;
345
+ err = js_get_arraybuffer_info(env, argv[1], (void **) &from, NULL);
346
+ assert(err == 0);
347
+
348
+ hdr_add(histogram->histogram, from->histogram);
349
+
350
+ return NULL;
351
+ }
352
+
353
+ static js_value_t *
354
+ bare_performance_histogram_reset(js_env_t *env, js_callback_info_t *info) {
355
+ int err;
356
+
357
+ size_t argc = 1;
358
+ js_value_t *argv[1];
359
+
360
+ err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
361
+ assert(err == 0);
362
+
363
+ assert(argc == 1);
364
+
365
+ bare_performance_histogram_t *histogram;
366
+ err = js_get_arraybuffer_info(env, argv[0], (void **) &histogram, NULL);
367
+ assert(err == 0);
368
+
369
+ hdr_reset(histogram->histogram);
370
+
371
+ return NULL;
372
+ }
373
+
86
374
  static js_value_t *
87
375
  bare_performance_exports(js_env_t *env, js_value_t *exports) {
88
376
  int err;
@@ -144,6 +432,17 @@ bare_performance_exports(js_env_t *env, js_value_t *exports) {
144
432
  );
145
433
 
146
434
  V("metricsInfo", bare_performance_metrics_info, NULL, NULL);
435
+
436
+ V("histogramInit", bare_performance_histogram_init, NULL, NULL);
437
+ V("histogramPercentiles", bare_performance_histogram_percentiles, NULL, NULL);
438
+ V("histogramPercentile", bare_performance_histogram_percentile, NULL, NULL);
439
+ V("histogramMin", bare_performance_histogram_min, NULL, NULL);
440
+ V("histogramMax", bare_performance_histogram_max, NULL, NULL);
441
+ V("histogramMean", bare_performance_histogram_mean, NULL, NULL);
442
+ V("histogramStddev", bare_performance_histogram_stddev, NULL, NULL);
443
+ V("histogramRecord", bare_performance_histogram_record, NULL, NULL);
444
+ V("histogramAdd", bare_performance_histogram_add, NULL, NULL);
445
+ V("histogramReset", bare_performance_histogram_reset, NULL, NULL);
147
446
  #undef V
148
447
 
149
448
  return exports;
package/index.js CHANGED
@@ -5,13 +5,10 @@ const binding = require('./binding')
5
5
  const { TIME_ORIGIN } = binding
6
6
 
7
7
  exports.now = function now() {
8
- return binding.now() - TIME_ORIGIN
8
+ return binding.now() / 1e6 - TIME_ORIGIN
9
9
  }
10
10
 
11
- exports.eventLoopUtilization = function eventLoopUtilization(
12
- prevUtil,
13
- secUtil
14
- ) {
11
+ exports.eventLoopUtilization = function eventLoopUtilization(prevUtil, secUtil) {
15
12
  if (secUtil) {
16
13
  const idle = prevUtil.idle - secUtil.idle
17
14
  const active = prevUtil.active - secUtil.active
@@ -163,9 +160,7 @@ class PerformanceObserver {
163
160
  (this._type === observerType.MULTIPLE && opts.type) ||
164
161
  (this._type === observerType.SINGLE && opts.entryTypes)
165
162
  ) {
166
- throw new InvalidModificationError(
167
- 'Cannot change the PerformanceObserver type'
168
- )
163
+ throw new InvalidModificationError('Cannot change the PerformanceObserver type')
169
164
  }
170
165
 
171
166
  if (this._type === observerType.UNDEFINED) {
@@ -185,9 +180,7 @@ class PerformanceObserver {
185
180
  this._entryTypes.add(opts.type)
186
181
 
187
182
  if (opts.buffered === true) {
188
- const bufferedEntries = globalBuffer.filter(
189
- (entry) => entry.entryType === opts.type
190
- )
183
+ const bufferedEntries = globalBuffer.filter((entry) => entry.entryType === opts.type)
191
184
 
192
185
  if (bufferedEntries.length > 0) {
193
186
  this._buffer.push(...bufferedEntries)
@@ -233,9 +226,7 @@ exports.mark = function mark(name, opts) {
233
226
 
234
227
  exports.clearMarks = function clearMarks(name) {
235
228
  if (name) {
236
- globalBuffer = globalBuffer.filter(
237
- (entry) => entry.name !== name && entry.entryType !== 'mark'
238
- )
229
+ globalBuffer = globalBuffer.filter((entry) => entry.name !== name && entry.entryType !== 'mark')
239
230
  } else {
240
231
  globalBuffer = globalBuffer.filter((entry) => entry.entryType !== 'mark')
241
232
  }
@@ -244,11 +235,7 @@ exports.clearMarks = function clearMarks(name) {
244
235
  exports.measure = function measure(name, start, end) {
245
236
  let opts = {}
246
237
 
247
- if (
248
- typeof start === 'object' &&
249
- start !== null &&
250
- Object.keys(start).length > 0
251
- ) {
238
+ if (typeof start === 'object' && start !== null && Object.keys(start).length > 0) {
252
239
  opts = start
253
240
 
254
241
  if (!opts.start && !opts.end) {
@@ -256,9 +243,7 @@ exports.measure = function measure(name, start, end) {
256
243
  }
257
244
 
258
245
  if (opts.name && opts.end && opts.duration) {
259
- throw new TypeError(
260
- 'One of opts.name, opts.end or opts.duration must not be specified'
261
- )
246
+ throw new TypeError('One of opts.name, opts.end or opts.duration must not be specified')
262
247
  }
263
248
 
264
249
  start = opts.start
@@ -342,10 +327,7 @@ function processPendingObservers() {
342
327
  globalPendingObservers.clear()
343
328
 
344
329
  for (const observer of observers) {
345
- observer._cb(
346
- new exports.PerformanceObserverEntryList(observer.takeRecords()),
347
- observer
348
- )
330
+ observer._cb(new exports.PerformanceObserverEntryList(observer.takeRecords()), observer)
349
331
  }
350
332
  })
351
333
  }
@@ -366,3 +348,134 @@ function toTimestamp(mark) {
366
348
  return mark
367
349
  }
368
350
  }
351
+
352
+ class Histogram {
353
+ constructor(opts = {}) {
354
+ const { lowest = 1, highest = Number.MAX_SAFE_INTEGER, figures = 3 } = opts
355
+
356
+ this._handle = binding.histogramInit(this, lowest, highest, figures)
357
+
358
+ this._count = 0
359
+ this._exceeds = 0
360
+ }
361
+
362
+ get max() {
363
+ return binding.histogramMax(this._handle)
364
+ }
365
+
366
+ get min() {
367
+ return binding.histogramMin(this._handle)
368
+ }
369
+
370
+ get mean() {
371
+ return binding.histogramMean(this._handle)
372
+ }
373
+
374
+ get percentiles() {
375
+ return new Map(binding.histogramPercentiles(this._handle))
376
+ }
377
+
378
+ get stddev() {
379
+ return binding.histogramStddev(this._handle)
380
+ }
381
+
382
+ get count() {
383
+ return this._count
384
+ }
385
+
386
+ get exceeds() {
387
+ return this._exceeds
388
+ }
389
+
390
+ percentile(percentile) {
391
+ return binding.histogramPercentile(this._handle, percentile)
392
+ }
393
+
394
+ reset() {
395
+ this._count = 0
396
+ this._exceeds = 0
397
+
398
+ binding.histogramReset(this._handle)
399
+ }
400
+ }
401
+
402
+ class RecordableHistogram extends Histogram {
403
+ add(other) {
404
+ this._count += other._count
405
+ this._exceeds += other._exceeds
406
+
407
+ binding.histogramAdd(this._handle, other._handle)
408
+ }
409
+
410
+ record(value) {
411
+ if (binding.histogramRecord(this._handle, value)) this._count++
412
+ else this._exceeds++
413
+ }
414
+ }
415
+
416
+ exports.createHistogram = function createHistogram(opts) {
417
+ return new RecordableHistogram(opts)
418
+ }
419
+
420
+ class IntervalHistogram extends Histogram {
421
+ constructor(opts = {}) {
422
+ const { resolution = 10 } = opts
423
+
424
+ super({
425
+ lowest: 1,
426
+ highest: 3_600_000_000_000 // One hour in nanoseconds
427
+ })
428
+
429
+ this._resolution = resolution
430
+ this._enabled = false
431
+
432
+ this._timerId = -1
433
+ this._timerStartTime = -1
434
+ }
435
+
436
+ enable() {
437
+ if (this._enabled === true) return false
438
+
439
+ this._timerStartTime = binding.now()
440
+ this._timerId = setInterval(this._oninterval.bind(this), this._resolution)
441
+
442
+ this._enabled = true
443
+
444
+ return true
445
+ }
446
+
447
+ disable() {
448
+ if (this._enabled === false) return false
449
+
450
+ clearInterval(this._timerId)
451
+
452
+ this._enabled = false
453
+
454
+ return true
455
+ }
456
+
457
+ _oninterval() {
458
+ const now = binding.now()
459
+ const actual = now - this._timerStartTime
460
+ const expected = this._resolution * 1e6
461
+
462
+ const hasDelay = actual > expected
463
+
464
+ if (hasDelay) {
465
+ const delay = actual - expected
466
+
467
+ if (binding.histogramRecord(this._handle, delay)) this._count++
468
+ else this._exceeds++
469
+ }
470
+
471
+ this._timerStartTime = now
472
+ }
473
+
474
+ [Symbol.dispose]() {
475
+ this.disable()
476
+ }
477
+ }
478
+
479
+ exports.monitorEventLoopDelay = function monitorEventLoopDelay(opts) {
480
+ return new IntervalHistogram(opts)
481
+ }
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ observerType: {
3
+ UNDEFINED: 1,
4
+ SINGLE: 2,
5
+ MULTIPLE: 3
6
+ }
7
+ }
package/lib/errors.js~ ADDED
@@ -0,0 +1,2 @@
1
+ exports.InvalidModificationError = class InvalidModificationError extends Error {
2
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-performance",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "Performance monitoring for Bare",
5
5
  "exports": {
6
6
  "./package": "./package.json",
@@ -33,7 +33,8 @@
33
33
  "devDependencies": {
34
34
  "brittle": "^3.13.1",
35
35
  "cmake-bare": "^1.5.4",
36
+ "cmake-fetch": "^1.4.7",
36
37
  "prettier": "^3.5.3",
37
- "prettier-config-standard": "^7.0.0"
38
+ "prettier-config-holepunch": "^2.0.0"
38
39
  }
39
40
  }