Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf evsel: Adopt find_process()

And make it static, nobody else uses it, if we ever need it in more
places we can carve a new source file for process related methods,
for now lets reduce util.{c,h} a tad more.

Link: http://lkml.kernel.org/n/tip-zgb28rllvypjibw52aaz9p15@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+39 -39
+39
tools/perf/util/evsel.c
··· 11 11 #include <errno.h> 12 12 #include <inttypes.h> 13 13 #include <linux/bitops.h> 14 + #include <api/fs/fs.h> 14 15 #include <api/fs/tracing_path.h> 15 16 #include <traceevent/event-parse.h> 16 17 #include <linux/hw_breakpoint.h> ··· 20 19 #include <linux/err.h> 21 20 #include <sys/ioctl.h> 22 21 #include <sys/resource.h> 22 + #include <sys/types.h> 23 + #include <dirent.h> 23 24 #include "asm/bug.h" 24 25 #include "callchain.h" 25 26 #include "cgroup.h" ··· 2473 2470 } 2474 2471 2475 2472 return false; 2473 + } 2474 + 2475 + static bool find_process(const char *name) 2476 + { 2477 + size_t len = strlen(name); 2478 + DIR *dir; 2479 + struct dirent *d; 2480 + int ret = -1; 2481 + 2482 + dir = opendir(procfs__mountpoint()); 2483 + if (!dir) 2484 + return false; 2485 + 2486 + /* Walk through the directory. */ 2487 + while (ret && (d = readdir(dir)) != NULL) { 2488 + char path[PATH_MAX]; 2489 + char *data; 2490 + size_t size; 2491 + 2492 + if ((d->d_type != DT_DIR) || 2493 + !strcmp(".", d->d_name) || 2494 + !strcmp("..", d->d_name)) 2495 + continue; 2496 + 2497 + scnprintf(path, sizeof(path), "%s/%s/comm", 2498 + procfs__mountpoint(), d->d_name); 2499 + 2500 + if (filename__read_str(path, &data, &size)) 2501 + continue; 2502 + 2503 + ret = strncmp(name, data, len); 2504 + free(data); 2505 + } 2506 + 2507 + closedir(dir); 2508 + return ret ? false : true; 2476 2509 } 2477 2510 2478 2511 int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
-37
tools/perf/util/util.c
··· 343 343 344 344 return value; 345 345 } 346 - 347 - bool find_process(const char *name) 348 - { 349 - size_t len = strlen(name); 350 - DIR *dir; 351 - struct dirent *d; 352 - int ret = -1; 353 - 354 - dir = opendir(procfs__mountpoint()); 355 - if (!dir) 356 - return false; 357 - 358 - /* Walk through the directory. */ 359 - while (ret && (d = readdir(dir)) != NULL) { 360 - char path[PATH_MAX]; 361 - char *data; 362 - size_t size; 363 - 364 - if ((d->d_type != DT_DIR) || 365 - !strcmp(".", d->d_name) || 366 - !strcmp("..", d->d_name)) 367 - continue; 368 - 369 - scnprintf(path, sizeof(path), "%s/%s/comm", 370 - procfs__mountpoint(), d->d_name); 371 - 372 - if (filename__read_str(path, &data, &size)) 373 - continue; 374 - 375 - ret = strncmp(name, data, len); 376 - free(data); 377 - } 378 - 379 - closedir(dir); 380 - return ret ? false : true; 381 - } 382 - 383 346 static int 384 347 fetch_ubuntu_kernel_version(unsigned int *puint) 385 348 {
-2
tools/perf/util/util.h
··· 49 49 extern unsigned int page_size; 50 50 extern int cacheline_size; 51 51 52 - bool find_process(const char *name); 53 - 54 52 int fetch_kernel_version(unsigned int *puint, 55 53 char *str, size_t str_sz); 56 54 #define KVER_VERSION(x) (((x) >> 16) & 0xff)