Skip to content

Commit

Permalink
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux…
Browse files Browse the repository at this point in the history
…/kernel/git/jolsa/perf into perf/core

Pull perf/core improvements and fixes from Jiri Olsa:

  * Honor user freq/interval properly in record command (Namhyung Kim)

  * Speedup DWARF unwind (Jiri Olsa)

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Ingo Molnar committed Jun 13, 2014
2 parents 7184062 + 45dc1bb commit 4ba9619
Show file tree
Hide file tree
Showing 10 changed files with 574 additions and 38 deletions.
42 changes: 40 additions & 2 deletions tools/perf/tests/builtin-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*
* Builtin regression testing command: ever growing number of sanity tests
*/
#include <unistd.h>
#include <string.h>
#include "builtin.h"
#include "intlist.h"
#include "tests.h"
Expand Down Expand Up @@ -50,9 +52,17 @@ static struct test {
.func = test__pmu,
},
{
.desc = "Test dso data interface",
.desc = "Test dso data read",
.func = test__dso_data,
},
{
.desc = "Test dso data cache",
.func = test__dso_data_cache,
},
{
.desc = "Test dso data reopen",
.func = test__dso_data_reopen,
},
{
.desc = "roundtrip evsel->name check",
.func = test__perf_evsel__roundtrip_name_test,
Expand Down Expand Up @@ -172,6 +182,34 @@ static bool perf_test__matches(int curr, int argc, const char *argv[])
return false;
}

static int run_test(struct test *test)
{
int status, err = -1, child = fork();

if (child < 0) {
pr_err("failed to fork test: %s\n", strerror(errno));
return -1;
}

if (!child) {
pr_debug("test child forked, pid %d\n", getpid());
err = test->func();
exit(err);
}

wait(&status);

if (WIFEXITED(status)) {
err = WEXITSTATUS(status);
pr_debug("test child finished with %d\n", err);
} else if (WIFSIGNALED(status)) {
err = -1;
pr_debug("test child interrupted\n");
}

return err;
}

static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
{
int i = 0;
Expand Down Expand Up @@ -200,7 +238,7 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
}

pr_debug("\n--- start ---\n");
err = tests[curr].func();
err = run_test(&tests[curr]);
pr_debug("---- end ----\n%s:", tests[curr].desc);

switch (err) {
Expand Down
214 changes: 210 additions & 4 deletions tools/perf/tests/dso-data.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
#include "util.h"

#include <stdlib.h>
#include <linux/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

#include <sys/time.h>
#include <sys/resource.h>
#include <api/fs/fs.h>
#include "util.h"
#include "machine.h"
#include "symbol.h"
#include "tests.h"

static char *test_file(int size)
{
static char buf_templ[] = "/tmp/test-XXXXXX";
#define TEMPL "/tmp/perf-test-XXXXXX"
static char buf_templ[sizeof(TEMPL)];
char *templ = buf_templ;
int fd, i;
unsigned char *buf;

strcpy(buf_templ, TEMPL);
#undef TEMPL

fd = mkstemp(templ);
if (fd < 0) {
perror("mkstemp failed");
Expand Down Expand Up @@ -150,3 +155,204 @@ int test__dso_data(void)
unlink(file);
return 0;
}

static long open_files_cnt(void)
{
char path[PATH_MAX];
struct dirent *dent;
DIR *dir;
long nr = 0;

scnprintf(path, PATH_MAX, "%s/self/fd", procfs__mountpoint());
pr_debug("fd path: %s\n", path);

dir = opendir(path);
TEST_ASSERT_VAL("failed to open fd directory", dir);

while ((dent = readdir(dir)) != NULL) {
if (!strcmp(dent->d_name, ".") ||
!strcmp(dent->d_name, ".."))
continue;

nr++;
}

closedir(dir);
return nr - 1;
}

static struct dso **dsos;

static int dsos__create(int cnt, int size)
{
int i;

dsos = malloc(sizeof(dsos) * cnt);
TEST_ASSERT_VAL("failed to alloc dsos array", dsos);

for (i = 0; i < cnt; i++) {
char *file;

file = test_file(size);
TEST_ASSERT_VAL("failed to get dso file", file);

dsos[i] = dso__new(file);
TEST_ASSERT_VAL("failed to get dso", dsos[i]);
}

return 0;
}

static void dsos__delete(int cnt)
{
int i;

for (i = 0; i < cnt; i++) {
struct dso *dso = dsos[i];

unlink(dso->name);
dso__delete(dso);
}

free(dsos);
}

static int set_fd_limit(int n)
{
struct rlimit rlim;

if (getrlimit(RLIMIT_NOFILE, &rlim))
return -1;

pr_debug("file limit %ld, new %d\n", (long) rlim.rlim_cur, n);

rlim.rlim_cur = n;
return setrlimit(RLIMIT_NOFILE, &rlim);
}

int test__dso_data_cache(void)
{
struct machine machine;
long nr_end, nr = open_files_cnt();
int dso_cnt, limit, i, fd;

memset(&machine, 0, sizeof(machine));

/* set as system limit */
limit = nr * 4;
TEST_ASSERT_VAL("failed to set file limit", !set_fd_limit(limit));

/* and this is now our dso open FDs limit + 1 extra */
dso_cnt = limit / 2 + 1;
TEST_ASSERT_VAL("failed to create dsos\n",
!dsos__create(dso_cnt, TEST_FILE_SIZE));

for (i = 0; i < (dso_cnt - 1); i++) {
struct dso *dso = dsos[i];

/*
* Open dsos via dso__data_fd or dso__data_read_offset.
* Both opens the data file and keep it open.
*/
if (i % 2) {
fd = dso__data_fd(dso, &machine);
TEST_ASSERT_VAL("failed to get fd", fd > 0);
} else {
#define BUFSIZE 10
u8 buf[BUFSIZE];
ssize_t n;

n = dso__data_read_offset(dso, &machine, 0, buf, BUFSIZE);
TEST_ASSERT_VAL("failed to read dso", n == BUFSIZE);
}
}

/* open +1 dso over the allowed limit */
fd = dso__data_fd(dsos[i], &machine);
TEST_ASSERT_VAL("failed to get fd", fd > 0);

/* should force the first one to be closed */
TEST_ASSERT_VAL("failed to close dsos[0]", dsos[0]->data.fd == -1);

/* cleanup everything */
dsos__delete(dso_cnt);

/* Make sure we did not leak any file descriptor. */
nr_end = open_files_cnt();
pr_debug("nr start %ld, nr stop %ld\n", nr, nr_end);
TEST_ASSERT_VAL("failed leadking files", nr == nr_end);
return 0;
}

int test__dso_data_reopen(void)
{
struct machine machine;
long nr_end, nr = open_files_cnt();
int fd, fd_extra;

#define dso_0 (dsos[0])
#define dso_1 (dsos[1])
#define dso_2 (dsos[2])

memset(&machine, 0, sizeof(machine));

/*
* Test scenario:
* - create 3 dso objects
* - set process file descriptor limit to current
* files count + 3
* - test that the first dso gets closed when we
* reach the files count limit
*/

/* Make sure we are able to open 3 fds anyway */
TEST_ASSERT_VAL("failed to set file limit",
!set_fd_limit((nr + 3)));

TEST_ASSERT_VAL("failed to create dsos\n", !dsos__create(3, TEST_FILE_SIZE));

/* open dso_0 */
fd = dso__data_fd(dso_0, &machine);
TEST_ASSERT_VAL("failed to get fd", fd > 0);

/* open dso_1 */
fd = dso__data_fd(dso_1, &machine);
TEST_ASSERT_VAL("failed to get fd", fd > 0);

/*
* open extra file descriptor and we just
* reached the files count limit
*/
fd_extra = open("/dev/null", O_RDONLY);
TEST_ASSERT_VAL("failed to open extra fd", fd_extra > 0);

/* open dso_2 */
fd = dso__data_fd(dso_2, &machine);
TEST_ASSERT_VAL("failed to get fd", fd > 0);

/*
* dso_0 should get closed, because we reached
* the file descriptor limit
*/
TEST_ASSERT_VAL("failed to close dso_0", dso_0->data.fd == -1);

/* open dso_0 */
fd = dso__data_fd(dso_0, &machine);
TEST_ASSERT_VAL("failed to get fd", fd > 0);

/*
* dso_1 should get closed, because we reached
* the file descriptor limit
*/
TEST_ASSERT_VAL("failed to close dso_1", dso_1->data.fd == -1);

/* cleanup everything */
close(fd_extra);
dsos__delete(3);

/* Make sure we did not leak any file descriptor. */
nr_end = open_files_cnt();
pr_debug("nr start %ld, nr stop %ld\n", nr, nr_end);
TEST_ASSERT_VAL("failed leadking files", nr == nr_end);
return 0;
}
2 changes: 2 additions & 0 deletions tools/perf/tests/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ int test__syscall_open_tp_fields(void);
int test__pmu(void);
int test__attr(void);
int test__dso_data(void);
int test__dso_data_cache(void);
int test__dso_data_reopen(void);
int test__parse_events(void);
int test__hists_link(void);
int test__python_use(void);
Expand Down
Loading

0 comments on commit 4ba9619

Please sign in to comment.