forked from cory/tildefriends
Attempt to track CPU usage of libuv worker threads.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4198 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
42
src/ssb.c
42
src/ssb.c
@ -160,6 +160,12 @@ typedef struct _tf_ssb_broadcasts_changed_callback_node_t
|
||||
tf_ssb_broadcasts_changed_callback_node_t* next;
|
||||
} tf_ssb_broadcasts_changed_callback_node_t;
|
||||
|
||||
typedef struct _tf_thread_work_time_t
|
||||
{
|
||||
int64_t thread_id;
|
||||
uint64_t hrtime;
|
||||
} tf_thread_work_time_t;
|
||||
|
||||
typedef struct _tf_ssb_t
|
||||
{
|
||||
bool own_context;
|
||||
@ -219,6 +225,9 @@ typedef struct _tf_ssb_t
|
||||
int broadcasts_changed_count;
|
||||
|
||||
tf_ssb_debug_close_t debug_close[k_debug_close_connection_count];
|
||||
|
||||
tf_thread_work_time_t* thread_time;
|
||||
int thread_time_count;
|
||||
} tf_ssb_t;
|
||||
|
||||
typedef struct _tf_ssb_connection_message_request_t
|
||||
@ -3418,3 +3427,36 @@ JSValue tf_ssb_get_disconnection_debug(tf_ssb_t* ssb, JSContext* context)
|
||||
JS_SetPropertyStr(context, result, "disconnections", disconnections);
|
||||
return result;
|
||||
}
|
||||
|
||||
void tf_ssb_record_thread_time(tf_ssb_t* ssb, int64_t thread_id, uint64_t hrtime)
|
||||
{
|
||||
for (int i = 0; i < ssb->thread_time_count; i++)
|
||||
{
|
||||
if (ssb->thread_time[i].thread_id == thread_id)
|
||||
{
|
||||
ssb->thread_time[i].hrtime += hrtime;
|
||||
return;
|
||||
}
|
||||
}
|
||||
ssb->thread_time = tf_resize_vec(ssb->thread_time, sizeof(tf_thread_work_time_t) * (ssb->thread_time_count + 1));
|
||||
ssb->thread_time[ssb->thread_time_count++] = (tf_thread_work_time_t)
|
||||
{
|
||||
.thread_id = thread_id,
|
||||
.hrtime = hrtime,
|
||||
};
|
||||
}
|
||||
|
||||
uint64_t tf_ssb_get_average_thread_time(tf_ssb_t* ssb)
|
||||
{
|
||||
if (!ssb)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t total = 0;
|
||||
for (int i = 0; i < ssb->thread_time_count; i++)
|
||||
{
|
||||
total += ssb->thread_time[i].hrtime;
|
||||
}
|
||||
return ssb->thread_time_count ? total / ssb->thread_time_count : 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user