forked from cory/tildefriends
Calculate thread busyness as the current concurrent running threads vs. the max number of threads ever seen running concurrently.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4404 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
36
src/ssb.c
36
src/ssb.c
@ -232,8 +232,8 @@ typedef struct _tf_ssb_t
|
||||
|
||||
tf_ssb_debug_close_t debug_close[k_debug_close_connection_count];
|
||||
|
||||
tf_thread_work_time_t* thread_time;
|
||||
int thread_time_count;
|
||||
int32_t thread_busy_count;
|
||||
int32_t thread_busy_max;
|
||||
|
||||
void (*hitch_callback)(const char* name, uint64_t duration, void* user_data);
|
||||
void* hitch_user_data;
|
||||
@ -2377,7 +2377,6 @@ void tf_ssb_destroy(tf_ssb_t* ssb)
|
||||
uv_mutex_destroy(&ssb->db_readers_lock);
|
||||
uv_mutex_destroy(&ssb->db_writer_lock);
|
||||
tf_free((void*)ssb->db_path);
|
||||
tf_free(ssb->thread_time);
|
||||
tf_free(ssb);
|
||||
}
|
||||
|
||||
@ -3531,37 +3530,24 @@ JSValue tf_ssb_get_disconnection_debug(tf_ssb_t* ssb, JSContext* context)
|
||||
return result;
|
||||
}
|
||||
|
||||
void tf_ssb_record_thread_time(tf_ssb_t* ssb, int64_t thread_id, uint64_t hrtime)
|
||||
void tf_ssb_record_thread_busy(tf_ssb_t* ssb, bool busy)
|
||||
{
|
||||
for (int i = 0; i < ssb->thread_time_count; i++)
|
||||
int32_t busy_value = __atomic_add_fetch(&ssb->thread_busy_count, busy ? 1 : -1, __ATOMIC_RELAXED);
|
||||
int32_t current = ssb->thread_busy_max;
|
||||
while (busy_value > current && !__atomic_compare_exchange_n(&ssb->thread_busy_max, ¤t, busy_value, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED))
|
||||
{
|
||||
if (ssb->thread_time[i].thread_id == thread_id)
|
||||
{
|
||||
ssb->thread_time[i].hrtime += hrtime;
|
||||
return;
|
||||
}
|
||||
current = ssb->thread_busy_max;
|
||||
}
|
||||
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)
|
||||
float tf_ssb_get_average_thread_percent(tf_ssb_t* ssb)
|
||||
{
|
||||
if (!ssb)
|
||||
if (!ssb || !ssb->thread_busy_max)
|
||||
{
|
||||
return 0;
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
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;
|
||||
return 100.0f * ssb->thread_busy_count / ssb->thread_busy_max;
|
||||
}
|
||||
|
||||
void tf_ssb_set_hitch_callback(tf_ssb_t* ssb, void (*callback)(const char* name, uint64_t duration_ns, void* user_data), void* user_data)
|
||||
|
Reference in New Issue
Block a user