[PATCH] Support oprofilefs mounted at mount points other than /dev/oprofile.
Arun Sharma <arun.sharma <at> google.com>
2007-03-05 17:52:38 GMT
Support oprofilefs mounted at mount points other than /dev/oprofile.
- Without this, users are required to have write access to /dev
- Clearly isolated from dynamic /dev management schemes if any.
Signed-off-by: Arun Sharma <arun.sharma <at> google.com>
diff -r 996b95f67f09 -r 62d6409be195 daemon/init.c
--- a/daemon/init.c Thu Jan 4 04:32:48 2007
+++ b/daemon/init.c Wed Feb 21 22:59:04 2007
<at> <at> -34,6 +34,7 <at> <at>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
+#include <limits.h>
size_t kernel_pointer_size;
<at> <at> -53,7 +54,9 <at> <at>
*/
static void opd_open_files(void)
{
- devfd = op_open_device("/dev/oprofile/buffer");
+ char dev_path[PATH_MAX + 1];
+ snprintf(dev_path, PATH_MAX, "%s/buffer", getenv("OPROFILEFS_MOUNT"));
+ devfd = op_open_device(dev_path);
if (devfd == -1) {
if (errno == EINVAL)
fprintf(stderr, "Failed to open device. Possibly you have passed incorrect\n"
<at> <at> -227,8 +230,10 <at> <at>
opd_create_vmlinux(vmlinux, kernel_range);
opd_create_xen(xenimage, xen_range);
- opd_buf_size = opd_read_fs_int("/dev/oprofile/", "buffer_size", 1);
- kernel_pointer_size = opd_read_fs_int("/dev/oprofile/", "pointer_size", 1);
+ opd_buf_size = opd_read_fs_int(getenv("OPROFILEFS_MOUNT"),
+ "buffer_size", 1);
+ kernel_pointer_size = opd_read_fs_int(getenv("OPROFILEFS_MOUNT"),
+ "pointer_size", 1);
s_buf_bytesize = opd_buf_size * kernel_pointer_size;
diff -r 996b95f67f09 -r 62d6409be195 daemon/opd_stats.c
--- a/daemon/opd_stats.c Thu Jan 4 04:32:48 2007
+++ b/daemon/opd_stats.c Wed Feb 21 22:59:04 2007
<at> <at> -17,6 +17,7 <at> <at>
#include <dirent.h>
#include <stdlib.h>
#include <stdio.h>
+#include <limits.h>
unsigned long opd_stats[OPD_MAX_STATS];
<at> <at> -66,7 +67,8 <at> <at>
char path[256];
if (sscanf(dirent->d_name, "cpu%d", &cpu_nr) != 1)
continue;
- snprintf(path, 256, "/dev/oprofile/stats/%s", dirent->d_name);
+ snprintf(path, 256, "%s/stats/%s", getenv("OPROFILEFS_MOUNT"),
+ dirent->d_name);
print_if("Nr. samples lost cpu buffer overflow: %u\n",
path, "sample_lost_overflow", 1);
diff -r 996b95f67f09 -r 62d6409be195 libop/op_cpu_type.c
--- a/libop/op_cpu_type.c Thu Jan 4 04:32:48 2007
+++ b/libop/op_cpu_type.c Wed Feb 21 22:59:04 2007
<at> <at> -12,6 +12,7 <at> <at>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
#include "op_cpu_type.h"
<at> <at> -74,12 +75,15 <at> <at>
{
int cpu_type = CPU_NO_GOOD;
char str[100];
+ char cpu_type_path[PATH_MAX + 1];
FILE * fp;
fp = fopen("/proc/sys/dev/oprofile/cpu_type", "r");
if (!fp) {
/* Try 2.6's oprofilefs one instead. */
- fp = fopen("/dev/oprofile/cpu_type", "r");
+ snprintf(cpu_type_path, PATH_MAX, "%s/cpu_type",
+ getenv("OPROFILEFS_MOUNT"));
+ fp = fopen(cpu_type_path, "r");
if (!fp) {
fprintf(stderr, "Unable to open cpu_type file for reading\n");
fprintf(stderr, "Make sure you have done opcontrol --init\n");
diff -r 996b95f67f09 -r 62d6409be195 libop/op_get_interface.c
--- a/libop/op_get_interface.c Thu Jan 4 04:32:48 2007
+++ b/libop/op_get_interface.c Wed Feb 21 22:59:04 2007
<at> <at> -11,6 +11,7 <at> <at>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
#include "op_cpu_type.h"
#include "op_file.h"
<at> <at> -18,14 +19,19 <at> <at>
op_interface op_get_interface(void)
{
static op_interface current_interface = OP_INTERFACE_NO_GOOD;
+ char cpu_type_path[PATH_MAX + 1];
if (current_interface != OP_INTERFACE_NO_GOOD)
return current_interface;
if (op_file_readable("/proc/sys/dev/oprofile/cpu_type")) {
current_interface = OP_INTERFACE_24;
- } else if (op_file_readable("/dev/oprofile/cpu_type")) {
- current_interface = OP_INTERFACE_26;
+ } else {
+ snprintf(cpu_type_path, PATH_MAX, "%s/cpu_type",
+ getenv("OPROFILEFS_MOUNT"));
+ if (op_file_readable(cpu_type_path)) {
+ current_interface = OP_INTERFACE_26;
+ }
}
return current_interface;
diff -r 996b95f67f09 -r 62d6409be195 utils/opcontrol
--- a/utils/opcontrol Thu Jan 4 04:32:48 2007
+++ b/utils/opcontrol Wed Feb 21 22:59:04 2007
<at> <at> -246,10 +246,16 <at> <at>
decide_oprofile_device_mount()
{
if test "$KERNEL_SUPPORT" = "yes"; then
- MOUNT="/dev/oprofile"
+ MOUNT=`grep oprofilefs /etc/mtab | awk '{print $2}'`
+ if test -z "$MOUNT"; then
+ MOUNT="/dev/oprofile"
+ fi
else
MOUNT="/proc/sys/dev/oprofile"
fi
+ # op_cpu_type.c uses it
+ OPROFILEFS_MOUNT=${MOUNT}
+ export OPROFILEFS_MOUNT
}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV