Skip to content

Commit

Permalink
perf tools: Allow overriding sysfs and proc finding with env var
Browse files Browse the repository at this point in the history
SYSFS_PATH and PROC_PATH environment variables now let the user override
the detection of sysfs and proc locations for testing purposes.

Signed-off-by: Cody P Schafer <[email protected]>
Cc: Sukadev Bhattiprolu <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
codyps authored and olsajiri committed Jun 3, 2014
1 parent 16a6433 commit f2d9627
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion tools/lib/api/fs/fs.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* TODO merge/factor in debugfs.c here */

#include <ctype.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/vfs.h>

Expand Down Expand Up @@ -96,12 +98,51 @@ static bool fs__check_mounts(struct fs *fs)
return false;
}

static void mem_toupper(char *f, size_t len)
{
while (len) {
*f = toupper(*f);
f++;
len--;
}
}

/*
* Check for "NAME_PATH" environment variable to override fs location (for
* testing). This matches the recommendation in Documentation/sysfs-rules.txt
* for SYSFS_PATH.
*/
static bool fs__env_override(struct fs *fs)
{
char *override_path;
size_t name_len = strlen(fs->name);
/* name + "_PATH" + '\0' */
char upper_name[name_len + 5 + 1];
memcpy(upper_name, fs->name, name_len);
mem_toupper(upper_name, name_len);
strcpy(&upper_name[name_len], "_PATH");

override_path = getenv(upper_name);
if (!override_path)
return false;

fs->found = true;
strncpy(fs->path, override_path, sizeof(fs->path));
return true;
}

static const char *fs__get_mountpoint(struct fs *fs)
{
if (fs__env_override(fs))
return fs->path;

if (fs__check_mounts(fs))
return fs->path;

return fs__read_mounts(fs) ? fs->path : NULL;
if (fs__read_mounts(fs))
return fs->path;

return NULL;
}

static const char *fs__mountpoint(int idx)
Expand Down

0 comments on commit f2d9627

Please sign in to comment.