Trace libuv's idle time metric.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3772 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-01-17 01:29:35 +00:00
parent 1ddaa7deb0
commit e9e1a3e80d

View File

@ -94,7 +94,10 @@ typedef struct _tf_task_t
int _promise_count;
promiseid_t _nextPromise;
uv_loop_t _loop;
uv_timer_t trace_timer;
uint64_t last_hrtime;
uint64_t last_idle_time;
export_record_t** _exports;
int _export_count;
@ -1239,12 +1242,15 @@ static void _tf_task_promise_rejection_tracker(JSContext* context, JSValueConst
static void _tf_task_trace_timer(uv_timer_t* timer)
{
tf_task_t* task = timer->data;
uint64_t hrtime = uv_hrtime();
uint64_t idle_time = uv_metrics_idle_time(&task->_loop);
const char* k_names[] =
{
"child_tasks",
"imports",
"exports",
"promises",
"idle_percent",
};
int64_t values[] =
{
@ -1252,7 +1258,10 @@ static void _tf_task_trace_timer(uv_timer_t* timer)
task->_import_count,
task->_export_count,
task->_promise_count,
(hrtime - task->last_hrtime) ? 100LL * (idle_time - task->last_idle_time) / (hrtime - task->last_hrtime) : 0,
};
task->last_hrtime = hrtime;
task->last_idle_time = idle_time;
tf_trace_counter(task->_trace, "task", sizeof(k_names) / sizeof(*k_names), k_names, values);
}
@ -1278,6 +1287,7 @@ tf_task_t* tf_task_create()
JS_NewClass(task->_runtime, _import_class_id, &def);
task->_loadedFiles = JS_NewObject(task->_context);
uv_loop_init(&task->_loop);
uv_loop_configure(&task->_loop, UV_METRICS_IDLE_TIME);
task->_loop.data = task;
task->trace_timer.data = task;
uv_timer_init(&task->_loop, &task->trace_timer);