bare-performance 1.0.0 → 1.1.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/README.md CHANGED
@@ -6,6 +6,15 @@ Performance monitoring for Bare.
6
6
  npm i bare-performance
7
7
  ```
8
8
 
9
+ ## API
10
+
11
+ Supported APIs:
12
+
13
+ - [`performance.now()`](https://nodejs.org/api/perf_hooks.html#performancenow)
14
+ - [`performance.eventLoopUtilization()`](https://nodejs.org/api/perf_hooks.html#performanceeventlooputilizationutilization1-utilization2)
15
+ - [`performance.nodeTiming`](https://nodejs.org/api/perf_hooks.html#performancenodetiming)
16
+ - [`performance.timeOrigin`](https://nodejs.org/api/perf_hooks.html#performancetimeorigin)
17
+
9
18
  ## License
10
19
 
11
20
  Apache-2.0
package/binding.c CHANGED
@@ -8,25 +8,18 @@ static js_value_t *
8
8
  bare_performance_now(js_env_t *env, js_callback_info_t *info) {
9
9
  int err;
10
10
 
11
- size_t argc = 1;
12
- js_value_t *argv[1];
13
-
14
- err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
15
- assert(err == 0);
16
-
17
- assert(argc == 1);
18
-
19
- double origin;
20
- err = js_get_value_double(env, argv[0], &origin);
21
- assert(err == 0);
22
-
23
11
  js_value_t *result;
24
- err = js_create_double(env, (uv_hrtime() / 1e6) - origin, &result);
12
+ err = js_create_double(env, uv_hrtime() / 1e6, &result);
25
13
  assert(err == 0);
26
14
 
27
15
  return result;
28
16
  }
29
17
 
18
+ static double
19
+ bare_performance_now_typed(js_value_t *receiver, js_typed_callback_info_t *info) {
20
+ return uv_hrtime() / 1e6;
21
+ }
22
+
30
23
  static js_value_t *
31
24
  bare_performance_idle_time(js_env_t *env, js_callback_info_t *info) {
32
25
  int err;
@@ -42,6 +35,21 @@ bare_performance_idle_time(js_env_t *env, js_callback_info_t *info) {
42
35
  return result;
43
36
  }
44
37
 
38
+ static double
39
+ bare_performance_idle_time_typed(js_value_t *receiver, js_typed_callback_info_t *info) {
40
+ int err;
41
+
42
+ js_env_t *env;
43
+ err = js_get_typed_callback_info(info, &env, NULL);
44
+ assert(err == 0);
45
+
46
+ uv_loop_t *loop;
47
+ err = js_get_env_loop(env, &loop);
48
+ assert(err == 0);
49
+
50
+ return uv_metrics_idle_time(loop) / 1e6;
51
+ }
52
+
45
53
  static js_value_t *
46
54
  bare_performance_metrics_info(js_env_t *env, js_callback_info_t *info) {
47
55
  int err;
@@ -93,18 +101,49 @@ bare_performance_exports(js_env_t *env, js_value_t *exports) {
93
101
  err = js_set_named_property(env, exports, "TIME_ORIGIN", time_origin);
94
102
  assert(err == 0);
95
103
 
96
- #define V(name, fn) \
104
+ #define V(name, untyped, signature, typed) \
97
105
  { \
98
106
  js_value_t *val; \
99
- err = js_create_function(env, name, -1, fn, NULL, &val); \
100
- assert(err == 0); \
107
+ if (signature) { \
108
+ err = js_create_typed_function(env, name, -1, untyped, signature, typed, NULL, &val); \
109
+ assert(err == 0); \
110
+ } else { \
111
+ err = js_create_function(env, name, -1, untyped, NULL, &val); \
112
+ assert(err == 0); \
113
+ } \
101
114
  err = js_set_named_property(env, exports, name, val); \
102
115
  assert(err == 0); \
103
116
  }
104
117
 
105
- V("now", bare_performance_now)
106
- V("idleTime", bare_performance_idle_time)
107
- V("metricsInfo", bare_performance_metrics_info)
118
+ V(
119
+ "now",
120
+ bare_performance_now,
121
+ &((js_callback_signature_t) {
122
+ .version = 0,
123
+ .result = js_float64,
124
+ .args_len = 1,
125
+ .args = (int[]) {
126
+ js_object,
127
+ },
128
+ }),
129
+ bare_performance_now_typed
130
+ );
131
+
132
+ V(
133
+ "idleTime",
134
+ bare_performance_idle_time,
135
+ &((js_callback_signature_t) {
136
+ .version = 0,
137
+ .result = js_float64,
138
+ .args_len = 1,
139
+ .args = (int[]) {
140
+ js_object,
141
+ },
142
+ }),
143
+ bare_performance_idle_time_typed
144
+ );
145
+
146
+ V("metricsInfo", bare_performance_metrics_info, NULL, NULL);
108
147
  #undef V
109
148
 
110
149
  return exports;
package/global.js ADDED
@@ -0,0 +1 @@
1
+ global.performance = require('.')
package/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  const binding = require('./binding')
2
2
 
3
+ const { TIME_ORIGIN } = binding
4
+
3
5
  exports.now = function now() {
4
- return binding.now(binding.TIME_ORIGIN)
6
+ return binding.now() - TIME_ORIGIN
5
7
  }
6
8
 
7
9
  exports.eventLoopUtilization = function eventLoopUtilization(
@@ -34,7 +36,7 @@ exports.metricsInfo = function metricsInfo() {
34
36
  return binding.metricsInfo()
35
37
  }
36
38
 
37
- exports.timeOrigin = binding.TIME_ORIGIN
39
+ exports.timeOrigin = TIME_ORIGIN
38
40
 
39
41
  // For Node.js compatibility
40
42
  exports.performance = exports
package/package.json CHANGED
@@ -1,16 +1,18 @@
1
1
  {
2
2
  "name": "bare-performance",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Performance monitoring for Bare",
5
5
  "exports": {
6
6
  "./package": "./package.json",
7
- ".": "./index.js"
7
+ ".": "./index.js",
8
+ "./global": "./global.js"
8
9
  },
9
10
  "files": [
10
11
  "index.js",
11
12
  "binding.c",
12
13
  "binding.js",
13
14
  "CMakeLists.txt",
15
+ "global.js",
14
16
  "prebuilds"
15
17
  ],
16
18
  "addon": true,