Linux Perf
strlist.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_STRLIST_H
3 #define __PERF_STRLIST_H
4 
5 #include <linux/rbtree.h>
6 #include <stdbool.h>
7 
8 #include "rblist.h"
9 
10 struct str_node {
11  struct rb_node rb_node;
12  const char *s;
13 };
14 
15 struct strlist {
16  struct rblist rblist;
17  bool dupstr;
18  bool file_only;
19 };
20 
21 /*
22  * @file_only: When dirname is present, only consider entries as filenames,
23  * that should not be added to the list if dirname/entry is not
24  * found
25  */
28  bool file_only;
29  const char *dirname;
30 };
31 
32 struct strlist *strlist__new(const char *slist, const struct strlist_config *config);
33 void strlist__delete(struct strlist *slist);
34 
35 void strlist__remove(struct strlist *slist, struct str_node *sn);
36 int strlist__load(struct strlist *slist, const char *filename);
37 int strlist__add(struct strlist *slist, const char *str);
38 
39 struct str_node *strlist__entry(const struct strlist *slist, unsigned int idx);
40 struct str_node *strlist__find(struct strlist *slist, const char *entry);
41 
42 static inline bool strlist__has_entry(struct strlist *slist, const char *entry)
43 {
44  return strlist__find(slist, entry) != NULL;
45 }
46 
47 static inline bool strlist__empty(const struct strlist *slist)
48 {
49  return rblist__empty(&slist->rblist);
50 }
51 
52 static inline unsigned int strlist__nr_entries(const struct strlist *slist)
53 {
54  return rblist__nr_entries(&slist->rblist);
55 }
56 
57 /* For strlist iteration */
58 static inline struct str_node *strlist__first(struct strlist *slist)
59 {
60  struct rb_node *rn = rb_first(&slist->rblist.entries);
61  return rn ? rb_entry(rn, struct str_node, rb_node) : NULL;
62 }
63 static inline struct str_node *strlist__next(struct str_node *sn)
64 {
65  struct rb_node *rn;
66  if (!sn)
67  return NULL;
68  rn = rb_next(&sn->rb_node);
69  return rn ? rb_entry(rn, struct str_node, rb_node) : NULL;
70 }
71 
77 #define strlist__for_each_entry(pos, slist) \
78  for (pos = strlist__first(slist); pos; pos = strlist__next(pos))
79 
87 #define strlist__for_each_entry_safe(pos, n, slist) \
88  for (pos = strlist__first(slist), n = strlist__next(pos); pos;\
89  pos = n, n = strlist__next(n))
90 #endif /* __PERF_STRLIST_H */
static bool rblist__empty(const struct rblist *rblist)
Definition: rblist.h:40
bool file_only
Definition: strlist.h:18
struct str_node * strlist__entry(const struct strlist *slist, unsigned int idx)
Definition: strlist.c:199
int strlist__add(struct strlist *slist, const char *str)
Definition: strlist.c:64
struct str_node * strlist__find(struct strlist *slist, const char *entry)
Definition: strlist.c:101
const char * filename
Definition: hists_common.c:26
#define config
Definition: rblist.h:22
static unsigned int strlist__nr_entries(const struct strlist *slist)
Definition: strlist.h:52
struct rb_root entries
Definition: rblist.h:23
bool dont_dupstr
Definition: strlist.h:27
bool dupstr
Definition: strlist.h:17
static int entry(u64 ip, struct unwind_info *ui)
Definition: unwind-libdw.c:71
static bool strlist__empty(const struct strlist *slist)
Definition: strlist.h:47
static unsigned int rblist__nr_entries(const struct rblist *rblist)
Definition: rblist.h:45
static int str(yyscan_t scanner, int token)
static struct str_node * strlist__first(struct strlist *slist)
Definition: strlist.h:58
struct rb_node rb_node
Definition: strlist.h:11
struct rblist rblist
Definition: strlist.h:16
static struct str_node * strlist__next(struct str_node *sn)
Definition: strlist.h:63
int strlist__load(struct strlist *slist, const char *filename)
Definition: strlist.c:69
const char * dirname
Definition: strlist.h:29
struct strlist * strlist__new(const char *slist, const struct strlist_config *config)
Definition: strlist.c:160
bool file_only
Definition: strlist.h:28
void strlist__remove(struct strlist *slist, struct str_node *sn)
Definition: strlist.c:96
const char * s
Definition: strlist.h:12
static bool strlist__has_entry(struct strlist *slist, const char *entry)
Definition: strlist.h:42
void strlist__delete(struct strlist *slist)
Definition: strlist.c:193