stats: use CLOCK_THREAD_CPUTIME_ID for cpu statistics

Use CLOCK_THREAD_CPUTIME_ID instead of getting the clock
with pthread_getcpuclockid.
This avoids to call red_worker_get_clockid. This function returns
uninitialized value at the time DisplayChannel is built resulting in setting
statistics to CLOCK_REALTIME (which is 0) instead to cpu time as expected.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
This commit is contained in:
Frediano Ziglio 2015-12-16 09:41:13 +00:00
parent 1b6af4779a
commit 26c7e33de3
3 changed files with 3 additions and 16 deletions

View File

@ -2041,7 +2041,7 @@ DisplayChannel* display_channel_new(RedWorker *worker, int migrate, int stream_v
&cbs, dcc_handle_message);
spice_return_val_if_fail(display, NULL);
clockid_t stat_clock = red_worker_get_clockid(worker);
clockid_t stat_clock = CLOCK_THREAD_CPUTIME_ID;
stat_init(&display->add_stat, "add", stat_clock);
stat_init(&display->exclude_stat, "exclude", stat_clock);
stat_init(&display->__exclude_stat, "__exclude", stat_clock);

View File

@ -67,7 +67,6 @@ struct SpiceWatch {
struct RedWorker {
pthread_t thread;
clockid_t clockid;
QXLInstance *qxl;
RedDispatcher *red_dispatcher;
int running;
@ -256,7 +255,7 @@ static int red_process_display(RedWorker *worker, uint32_t max_pipe_size, int *r
if (worker->record_fd)
red_record_qxl_command(worker->record_fd, &worker->mem_slots, ext_cmd,
stat_now(worker->clockid));
stat_now(CLOCK_THREAD_CPUTIME_ID));
stat_inc_counter(worker->command_counter, 1);
worker->display_poll_tries = 0;
@ -1348,7 +1347,7 @@ static void worker_dispatcher_record(void *opaque, uint32_t message_type, void *
{
RedWorker *worker = opaque;
red_record_event(worker->record_fd, 1, message_type, stat_now(worker->clockid));
red_record_event(worker->record_fd, 1, message_type, stat_now(CLOCK_THREAD_CPUTIME_ID));
}
static void register_callbacks(Dispatcher *dispatcher)
@ -1619,10 +1618,6 @@ SPICE_GNUC_NORETURN static void *red_worker_main(void *arg)
spice_error("failed to create timer queue");
}
if (pthread_getcpuclockid(pthread_self(), &worker->clockid)) {
spice_warning("getcpuclockid failed");
}
RED_CHANNEL(worker->cursor_channel)->thread_id = pthread_self();
RED_CHANNEL(worker->display_channel)->thread_id = pthread_self();
@ -1723,10 +1718,3 @@ RedChannel* red_worker_get_display_channel(RedWorker *worker)
return RED_CHANNEL(worker->display_channel);
}
clockid_t red_worker_get_clockid(RedWorker *worker)
{
spice_return_val_if_fail(worker, 0);
return worker->clockid;
}

View File

@ -97,7 +97,6 @@ bool red_worker_run(RedWorker *worker);
QXLInstance* red_worker_get_qxl(RedWorker *worker);
RedChannel* red_worker_get_cursor_channel(RedWorker *worker);
RedChannel* red_worker_get_display_channel(RedWorker *worker);
clockid_t red_worker_get_clockid(RedWorker *worker);
RedMemSlotInfo* red_worker_get_memslot(RedWorker *worker);
void red_drawable_unref(RedWorker *worker, RedDrawable *red_drawable,