public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Denys Zagorui <dzagorui@cisco.com>
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org,
	mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com,
	alexander.shishkin@linux.intel.com, namhyung@kernel.org
Subject: Re: [PATCH v5 1/3] perf report: compile tips.txt in perf binary
Date: Wed, 19 May 2021 15:24:49 +0200	[thread overview]
Message-ID: <YKURoStYXwQ3FnxI@krava> (raw)
In-Reply-To: <20210517084604.2895-1-dzagorui@cisco.com>

On Mon, May 17, 2021 at 01:46:02AM -0700, Denys Zagorui wrote:

SNIP

>  	return hist_browser(rep->session->evlist, help, NULL, rep->min_percent);
>  }
>  
> +#define MAX_TIPS        60
> +
> +static const char *perf_tip(void)
> +{
> +	char *str[MAX_TIPS];
> +	int i = 0;
> +
> +	_binary_Documentation_tips_txt_start[_binary_Documentation_tips_txt_end -
> +		_binary_Documentation_tips_txt_start - 1] = 0;
> +
> +	str[i] = strtok(_binary_Documentation_tips_txt_start, "\n");
> +	if (!str[i])
> +		return "Tips cannot be found!";
> +
> +	i++;
> +
> +	while (i < MAX_TIPS) {
> +		str[i] = strtok(NULL, "\n");
> +		if (!str[i])
> +			break;
> +		i++;
> +	}
> +
> +	return str[random() % i];

that still does not solve that we set MAX_TIPS and have
no way of checking that's still valid

how about something like below (completely untested):


static const char *perf_tip(void)
{
       char *start = _binary_Documentation_tips_txt_start;
       char *tok, *tmp, *prev;
       int pick, size;

       size = _binary_Documentation_tips_txt_end - start;
       pick = random() % size;

       _binary_Documentation_tips_txt_start[size - 1] = 0;

       for (tok = strtok_r(start, "\n", &tmp); tok;
            tok = strtok_r(NULL, "\n", &tmp)) {
               if (pick < (tok - start))
                       return prev;
               prev = tok;
       }

       return prev;
}

this way you wouldn't need array with MAX_TIPS defined

jirka


  parent reply	other threads:[~2021-05-19 13:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-17  8:46 [PATCH v5 1/3] perf report: compile tips.txt in perf binary Denys Zagorui
2021-05-17  8:46 ` [PATCH v5 2/3] perf tests: avoid storing an absolute path " Denys Zagorui
2021-05-21  6:59   ` Namhyung Kim
2021-05-17  8:46 ` [PATCH v5 3/3] perf parse-events: add bison --file-prefix-map option Denys Zagorui
2021-05-19 13:24 ` Jiri Olsa [this message]
2021-05-21 10:24   ` [PATCH v5 1/3] perf report: compile tips.txt in perf binary Denys Zagorui -X (dzagorui - GLOBALLOGIC INC at Cisco)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YKURoStYXwQ3FnxI@krava \
    --to=jolsa@redhat.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=dzagorui@cisco.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox