perf probe: Rewrite find_lazy_match_lines() by using getline(3)
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: lkml <linux-kernel@vger.kernel.org> LKML-Reference: <m3d3o185u1.fsf@gmail.com> Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
ef4d001d79
commit
f50c2169bd
|
@ -1234,51 +1234,38 @@ static int find_probe_point_by_line(struct probe_finder *pf)
|
||||||
static int find_lazy_match_lines(struct list_head *head,
|
static int find_lazy_match_lines(struct list_head *head,
|
||||||
const char *fname, const char *pat)
|
const char *fname, const char *pat)
|
||||||
{
|
{
|
||||||
char *fbuf, *p1, *p2;
|
FILE *fp;
|
||||||
int fd, line, nlines = -1;
|
char *line = NULL;
|
||||||
struct stat st;
|
size_t line_len;
|
||||||
|
ssize_t len;
|
||||||
|
int count = 0, linenum = 1;
|
||||||
|
|
||||||
fd = open(fname, O_RDONLY);
|
fp = fopen(fname, "r");
|
||||||
if (fd < 0) {
|
if (!fp) {
|
||||||
pr_warning("Failed to open %s: %s\n", fname, strerror(-fd));
|
pr_warning("Failed to open %s: %s\n", fname, strerror(errno));
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fstat(fd, &st) < 0) {
|
while ((len = getline(&line, &line_len, fp)) > 0) {
|
||||||
pr_warning("Failed to get the size of %s: %s\n",
|
|
||||||
fname, strerror(errno));
|
if (line[len - 1] == '\n')
|
||||||
nlines = -errno;
|
line[len - 1] = '\0';
|
||||||
goto out_close;
|
|
||||||
|
if (strlazymatch(line, pat)) {
|
||||||
|
line_list__add_line(head, linenum);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
linenum++;
|
||||||
}
|
}
|
||||||
|
|
||||||
nlines = -ENOMEM;
|
if (ferror(fp))
|
||||||
fbuf = malloc(st.st_size + 2);
|
count = -errno;
|
||||||
if (fbuf == NULL)
|
free(line);
|
||||||
goto out_close;
|
fclose(fp);
|
||||||
if (read(fd, fbuf, st.st_size) < 0) {
|
|
||||||
pr_warning("Failed to read %s: %s\n", fname, strerror(errno));
|
if (count == 0)
|
||||||
nlines = -errno;
|
pr_debug("No matched lines found in %s.\n", fname);
|
||||||
goto out_free_fbuf;
|
return count;
|
||||||
}
|
|
||||||
fbuf[st.st_size] = '\n'; /* Dummy line */
|
|
||||||
fbuf[st.st_size + 1] = '\0';
|
|
||||||
p1 = fbuf;
|
|
||||||
line = 1;
|
|
||||||
nlines = 0;
|
|
||||||
while ((p2 = strchr(p1, '\n')) != NULL) {
|
|
||||||
*p2 = '\0';
|
|
||||||
if (strlazymatch(p1, pat)) {
|
|
||||||
line_list__add_line(head, line);
|
|
||||||
nlines++;
|
|
||||||
}
|
|
||||||
line++;
|
|
||||||
p1 = p2 + 1;
|
|
||||||
}
|
|
||||||
out_free_fbuf:
|
|
||||||
free(fbuf);
|
|
||||||
out_close:
|
|
||||||
close(fd);
|
|
||||||
return nlines;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int probe_point_lazy_walker(const char *fname, int lineno,
|
static int probe_point_lazy_walker(const char *fname, int lineno,
|
||||||
|
@ -1312,10 +1299,7 @@ static int find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf)
|
||||||
/* Matching lazy line pattern */
|
/* Matching lazy line pattern */
|
||||||
ret = find_lazy_match_lines(&pf->lcache, pf->fname,
|
ret = find_lazy_match_lines(&pf->lcache, pf->fname,
|
||||||
pf->pev->point.lazy_line);
|
pf->pev->point.lazy_line);
|
||||||
if (ret == 0) {
|
if (ret <= 0)
|
||||||
pr_debug("No matched lines found in %s.\n", pf->fname);
|
|
||||||
return 0;
|
|
||||||
} else if (ret < 0)
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue