Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2157f6ee authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo
Browse files

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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 007b811b
Loading
Loading
Loading
Loading
+39 −0
Original line number Original line Diff line number Diff line
@@ -11,6 +11,7 @@
#include <errno.h>
#include <errno.h>
#include <inttypes.h>
#include <inttypes.h>
#include <linux/bitops.h>
#include <linux/bitops.h>
#include <api/fs/fs.h>
#include <api/fs/tracing_path.h>
#include <api/fs/tracing_path.h>
#include <traceevent/event-parse.h>
#include <traceevent/event-parse.h>
#include <linux/hw_breakpoint.h>
#include <linux/hw_breakpoint.h>
@@ -19,6 +20,8 @@
#include <linux/err.h>
#include <linux/err.h>
#include <sys/ioctl.h>
#include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <dirent.h>
#include "asm/bug.h"
#include "asm/bug.h"
#include "callchain.h"
#include "callchain.h"
#include "cgroup.h"
#include "cgroup.h"
@@ -2472,6 +2475,42 @@ bool perf_evsel__fallback(struct perf_evsel *evsel, int err,
	return false;
	return false;
}
}


static bool find_process(const char *name)
{
	size_t len = strlen(name);
	DIR *dir;
	struct dirent *d;
	int ret = -1;

	dir = opendir(procfs__mountpoint());
	if (!dir)
		return false;

	/* Walk through the directory. */
	while (ret && (d = readdir(dir)) != NULL) {
		char path[PATH_MAX];
		char *data;
		size_t size;

		if ((d->d_type != DT_DIR) ||
		     !strcmp(".", d->d_name) ||
		     !strcmp("..", d->d_name))
			continue;

		scnprintf(path, sizeof(path), "%s/%s/comm",
			  procfs__mountpoint(), d->d_name);

		if (filename__read_str(path, &data, &size))
			continue;

		ret = strncmp(name, data, len);
		free(data);
	}

	closedir(dir);
	return ret ? false : true;
}

int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
			      int err, char *msg, size_t size)
			      int err, char *msg, size_t size)
{
{
+0 −37
Original line number Original line Diff line number Diff line
@@ -343,43 +343,6 @@ int perf_event_paranoid(void)


	return value;
	return value;
}
}

bool find_process(const char *name)
{
	size_t len = strlen(name);
	DIR *dir;
	struct dirent *d;
	int ret = -1;

	dir = opendir(procfs__mountpoint());
	if (!dir)
		return false;

	/* Walk through the directory. */
	while (ret && (d = readdir(dir)) != NULL) {
		char path[PATH_MAX];
		char *data;
		size_t size;

		if ((d->d_type != DT_DIR) ||
		     !strcmp(".", d->d_name) ||
		     !strcmp("..", d->d_name))
			continue;

		scnprintf(path, sizeof(path), "%s/%s/comm",
			  procfs__mountpoint(), d->d_name);

		if (filename__read_str(path, &data, &size))
			continue;

		ret = strncmp(name, data, len);
		free(data);
	}

	closedir(dir);
	return ret ? false : true;
}

static int
static int
fetch_ubuntu_kernel_version(unsigned int *puint)
fetch_ubuntu_kernel_version(unsigned int *puint)
{
{
+0 −2
Original line number Original line Diff line number Diff line
@@ -49,8 +49,6 @@ int hex2u64(const char *ptr, u64 *val);
extern unsigned int page_size;
extern unsigned int page_size;
extern int cacheline_size;
extern int cacheline_size;


bool find_process(const char *name);

int fetch_kernel_version(unsigned int *puint,
int fetch_kernel_version(unsigned int *puint,
			 char *str, size_t str_sz);
			 char *str, size_t str_sz);
#define KVER_VERSION(x)		(((x) >> 16) & 0xff)
#define KVER_VERSION(x)		(((x) >> 16) & 0xff)