On Mon, Jan 17, 2022 at 02:23:52PM +0000, Klemens Nanni wrote:
> I keep doing `btrace -l | sort' to help myself searching for traces.
>
> Would it be worh making btrace sort the list of probes
> lexicographically in the first place or is there any value in seeing
> them sorted by id?
I believe you're ruining the party for dtpi_get_by_id(), which only
seems to care about the id.
/Alexander
>
> Index: btrace.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/btrace/btrace.c,v
> retrieving revision 1.61
> diff -u -p -r1.61 btrace.c
> --- btrace.c 7 Dec 2021 22:17:03 -0000 1.61
> +++ btrace.c 17 Jan 2022 14:13:27 -0000
> @@ -62,7 +62,7 @@ char *read_btfile(const char *,
> size_t
> */
> void dtpi_cache(int);
> void dtpi_print_list(void);
> -const char *dtpi_func(struct dtioc_probe_info *);
> +const char *dtpi_func(const struct dtioc_probe_info *);
> int dtpi_is_unit(const char *);
> struct dtioc_probe_info *dtpi_get_by_value(const char *, const char *,
> const char *);
> @@ -260,11 +260,26 @@ static int
> dtpi_cmp(const void *a, const void *b)
> {
> const struct dtioc_probe_info *ai = a, *bi = b;
> + int i;
>
> - if (ai->dtpi_pbn > bi->dtpi_pbn)
> + i = strcmp(ai->dtpi_prov, bi->dtpi_prov);
> + if (i > 0)
> return 1;
> - if (ai->dtpi_pbn < bi->dtpi_pbn)
> + if (i < 0)
> return -1;
> +
> + i = strcmp(dtpi_func(ai), dtpi_func(bi));
> + if (i > 0)
> + return 1;
> + if (i < 0)
> + return -1;
> +
> + i = strcmp(ai->dtpi_name, bi->dtpi_name);
> + if (i > 0)
> + return 1;
> + if (i < 0)
> + return -1;
> +
> return 0;
> }
>
> @@ -306,7 +321,7 @@ dtpi_print_list(void)
> }
>
> const char *
> -dtpi_func(struct dtioc_probe_info *dtpi)
> +dtpi_func(const struct dtioc_probe_info *dtpi)
> {
> char *sysnb, func[DTNAMESIZE];
> const char *errstr;
>