[sheepdog] [PATCH 5/5] logger: don't show a thread index for an ordered work queue

Yunkai Zhang yunkai.me at gmail.com
Tue Jul 3 03:29:01 CEST 2012


On Tue, Jul 3, 2012 at 2:32 AM, MORITA Kazutaka
<morita.kazutaka at lab.ntt.co.jp> wrote:
> Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
> ---
>  lib/logger.c |   10 ++++++++--
>  sheep/work.c |    2 +-
>  2 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/lib/logger.c b/lib/logger.c
> index c64aefc..c1dd160 100644
> --- a/lib/logger.c
> +++ b/lib/logger.c
> @@ -202,9 +202,12 @@ static notrace int log_enqueue(int prio, const char *func, int line, const char
>                 strftime(p, MAX_MSG_SIZE, "%b %2d %H:%M:%S", tmp);
>                 p += strlen(p);
>
> -               if (worker_name)
> +               if (worker_name && worker_idx)
>                         snprintf(p, MAX_MSG_SIZE - strlen(buff), " [%s %d] ",
>                                  worker_name, worker_idx);
> +               else if (worker_name)
> +                       snprintf(p, MAX_MSG_SIZE - strlen(buff), " [%s] ",
> +                                worker_name, worker_idx);
>                 else
>                         strncpy(p, " [main] ", MAX_MSG_SIZE - strlen(buff));
>
> @@ -323,9 +326,12 @@ static notrace void dolog(int prio, const char *func, int line,
>
>                 vsnprintf(p, MAX_MSG_SIZE, fmt, ap);
>
> -               if (worker_name)
> +               if (worker_name && worker_idx)
>                         fprintf(stderr, "[%s %d] %s(%d) %s", worker_name,
>                                 worker_idx, func, line, p);
> +               else if (worker_name)
> +                       fprintf(stderr, "[%s] %s(%d) %s", worker_name, func,
> +                               line, p);
>                 else
>                         fprintf(stderr, "[main] %s(%d) %s", func, line, p);
>
> diff --git a/sheep/work.c b/sheep/work.c
> index 9deac01..44aa180 100644
> --- a/sheep/work.c
> +++ b/sheep/work.c
> @@ -61,7 +61,7 @@ static void *run_short_thread(void * arg)
>  {
>         struct short_work *sw = arg;
>         eventfd_t value = 1;
> -       static uint64_t idx = 0;
> +       static uint64_t idx = 1;

Why initialize idx with 1?

>
>         uatomic_inc(&idx);

Here, idx will be increased again.

>         set_thread_name(sw->wi->name, idx);
> --
> 1.7.2.5
>
> --
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> http://lists.wpkg.org/mailman/listinfo/sheepdog



-- 
Yunkai Zhang
Work at Taobao



More information about the sheepdog mailing list