aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/probe-finder.c
diff options
context:
space:
mode:
authorFranck Bui-Huu <fbuihuu@gmail.com>2011-01-13 05:18:30 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2011-02-07 06:12:42 -0500
commitf50c2169bd054984e976e67e8651d28f3caf6ba3 (patch)
treea604d2d613ffc1f91471a1fe6db66f8d08041ff1 /tools/perf/util/probe-finder.c
parentef4d001d79ac4bab6c2d81e9986a42059f877ec3 (diff)
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>
Diffstat (limited to 'tools/perf/util/probe-finder.c')
-rw-r--r--tools/perf/util/probe-finder.c72
1 files changed, 28 insertions, 44 deletions
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 69215bff17e9..46addfb3183e 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -1234,51 +1234,38 @@ static int find_probe_point_by_line(struct probe_finder *pf)
1234static int find_lazy_match_lines(struct list_head *head, 1234static int find_lazy_match_lines(struct list_head *head,
1235 const char *fname, const char *pat) 1235 const char *fname, const char *pat)
1236{ 1236{
1237 char *fbuf, *p1, *p2; 1237 FILE *fp;
1238 int fd, line, nlines = -1; 1238 char *line = NULL;
1239 struct stat st; 1239 size_t line_len;
1240 1240 ssize_t len;
1241 fd = open(fname, O_RDONLY); 1241 int count = 0, linenum = 1;
1242 if (fd < 0) { 1242
1243 pr_warning("Failed to open %s: %s\n", fname, strerror(-fd)); 1243 fp = fopen(fname, "r");
1244 if (!fp) {
1245 pr_warning("Failed to open %s: %s\n", fname, strerror(errno));
1244 return -errno; 1246 return -errno;
1245 } 1247 }
1246 1248
1247 if (fstat(fd, &st) < 0) { 1249 while ((len = getline(&line, &line_len, fp)) > 0) {
1248 pr_warning("Failed to get the size of %s: %s\n", 1250
1249 fname, strerror(errno)); 1251 if (line[len - 1] == '\n')
1250 nlines = -errno; 1252 line[len - 1] = '\0';
1251 goto out_close; 1253
1252 } 1254 if (strlazymatch(line, pat)) {
1253 1255 line_list__add_line(head, linenum);
1254 nlines = -ENOMEM; 1256 count++;
1255 fbuf = malloc(st.st_size + 2);
1256 if (fbuf == NULL)
1257 goto out_close;
1258 if (read(fd, fbuf, st.st_size) < 0) {
1259 pr_warning("Failed to read %s: %s\n", fname, strerror(errno));
1260 nlines = -errno;
1261 goto out_free_fbuf;
1262 }
1263 fbuf[st.st_size] = '\n'; /* Dummy line */
1264 fbuf[st.st_size + 1] = '\0';
1265 p1 = fbuf;
1266 line = 1;
1267 nlines = 0;
1268 while ((p2 = strchr(p1, '\n')) != NULL) {
1269 *p2 = '\0';
1270 if (strlazymatch(p1, pat)) {
1271 line_list__add_line(head, line);
1272 nlines++;
1273 } 1257 }
1274 line++; 1258 linenum++;
1275 p1 = p2 + 1;
1276 } 1259 }
1277out_free_fbuf: 1260
1278 free(fbuf); 1261 if (ferror(fp))
1279out_close: 1262 count = -errno;
1280 close(fd); 1263 free(line);
1281 return nlines; 1264 fclose(fp);
1265
1266 if (count == 0)
1267 pr_debug("No matched lines found in %s.\n", fname);
1268 return count;
1282} 1269}
1283 1270
1284static int probe_point_lazy_walker(const char *fname, int lineno, 1271static 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)
1312 /* Matching lazy line pattern */ 1299 /* Matching lazy line pattern */
1313 ret = find_lazy_match_lines(&pf->lcache, pf->fname, 1300 ret = find_lazy_match_lines(&pf->lcache, pf->fname,
1314 pf->pev->point.lazy_line); 1301 pf->pev->point.lazy_line);
1315 if (ret == 0) { 1302 if (ret <= 0)
1316 pr_debug("No matched lines found in %s.\n", pf->fname);
1317 return 0;
1318 } else if (ret < 0)
1319 return ret; 1303 return ret;
1320 } 1304 }
1321 1305