summaryrefslogtreecommitdiffstats
path: root/buildrun.cxx
diff options
context:
space:
mode:
authorDavid Smith <dsmith@redhat.com>2009-03-12 12:58:49 -0500
committerDavid Smith <dsmith@redhat.com>2009-03-12 12:58:49 -0500
commit2791f774da562b5a2bfc976baad246999da29ea6 (patch)
treed1ece2d650e6307d86ed6269d4afffbaf30e05c3 /buildrun.cxx
parent976f6b6a6fae081d1d72d06457d64af87db789ef (diff)
parent96b030fe8a0bb0297d23638e2975a3e9eb2b85b6 (diff)
downloadsystemtap-steved-2791f774da562b5a2bfc976baad246999da29ea6.tar.gz
systemtap-steved-2791f774da562b5a2bfc976baad246999da29ea6.tar.xz
systemtap-steved-2791f774da562b5a2bfc976baad246999da29ea6.zip
Merge branch 'master' of ssh://sources.redhat.com/git/systemtap into pr7043
Diffstat (limited to 'buildrun.cxx')
-rw-r--r--buildrun.cxx78
1 files changed, 78 insertions, 0 deletions
diff --git a/buildrun.cxx b/buildrun.cxx
index fe060236..b9d648ef 100644
--- a/buildrun.cxx
+++ b/buildrun.cxx
@@ -24,6 +24,7 @@ extern "C" {
#include <unistd.h>
#include <string.h>
#include <errno.h>
+#include <glob.h>
}
@@ -146,6 +147,7 @@ compile_pass (systemtap_session& s)
output_autoconf(s, o, "autoconf-task-uid.c", "STAPCONF_TASK_UID", NULL);
output_autoconf(s, o, "autoconf-vm-area.c", "STAPCONF_VM_AREA", NULL);
output_autoconf(s, o, "autoconf-procfs-owner.c", "STAPCONF_PROCFS_OWNER", NULL);
+ output_autoconf(s, o, "autoconf-alloc-percpu-align.c", "STAPCONF_ALLOC_PERCPU_ALIGN", NULL);
#if 0
/* NB: For now, the performance hit of probe_kernel_read/write (vs. our
@@ -153,6 +155,8 @@ compile_pass (systemtap_session& s)
* this autoconf. */
output_autoconf(s, o, "autoconf-probe-kernel.c", "STAPCONF_PROBE_KERNEL", NULL);
#endif
+ output_autoconf(s, o, "autoconf-save-stack-trace.c",
+ "STAPCONF_KERNEL_STACKTRACE", NULL);
o << module_cflags << " += -include $(STAPCONF_HEADER)" << endl;
@@ -334,4 +338,78 @@ run_pass (systemtap_session& s)
return rc;
}
+
+// Build a tiny kernel module to query tracepoints
+int
+make_tracequery(systemtap_session& s, string& name)
+{
+ // create a subdirectory for the module
+ string dir(s.tmpdir + "/tracequery");
+ if (create_dir(dir.c_str()) != 0)
+ {
+ if (! s.suppress_warnings)
+ cerr << "Warning: failed to create directory for querying tracepoints." << endl;
+ return 1;
+ }
+
+ name = dir + "/tracequery.ko";
+
+ // create a simple Makefile
+ string makefile(dir + "/Makefile");
+ ofstream omf(makefile.c_str());
+ omf << "EXTRA_CFLAGS := -g" << endl; // force debuginfo generation
+ omf << "obj-m := tracequery.o" << endl;
+ omf.close();
+
+ // create our source file
+ string source(dir + "/tracequery.c");
+ ofstream osrc(source.c_str());
+ osrc << "#include <linux/module.h>" << endl;
+ osrc << "#ifdef CONFIG_TRACEPOINTS" << endl;
+ osrc << "#include <linux/tracepoint.h>" << endl;
+
+ // override DECLARE_TRACE to synthesize probe functions for us
+ osrc << "#undef DECLARE_TRACE" << endl;
+ osrc << "#define DECLARE_TRACE(name, proto, args) \\" << endl;
+ osrc << " void stapprobe_##name(proto) {}" << endl;
+
+ // older tracepoints used DEFINE_TRACE, so redirect that too
+ osrc << "#undef DEFINE_TRACE" << endl;
+ osrc << "#define DEFINE_TRACE(name, proto, args) \\" << endl;
+ osrc << " DECLARE_TRACE(name, TPPROTO(proto), TPARGS(args))" << endl;
+
+ // dynamically pull in all tracepoint headers from include/trace/
+ glob_t trace_glob;
+ string glob_str(s.kernel_build_tree + "/include/trace/*.h");
+ glob(glob_str.c_str(), 0, NULL, &trace_glob);
+ for (unsigned i = 0; i < trace_glob.gl_pathc; ++i)
+ {
+ string header(basename(trace_glob.gl_pathv[i]));
+
+ // filter out a few known "internal-only" headers
+ if (header == "trace_events.h")
+ continue;
+ if (header.find("_event_types.h") != string::npos)
+ continue;
+
+ osrc << "#include <trace/" << header << ">" << endl;
+ }
+ globfree(&trace_glob);
+
+ // finish up the module source
+ osrc << "#endif /* CONFIG_TRACEPOINTS */" << endl;
+ osrc << "int init_module(void) { return 0; }" << endl;
+ osrc << "void cleanup_module(void) {}" << endl;
+ osrc << "MODULE_DESCRIPTION(\"tracepoint query\");" << endl;
+ osrc << "MODULE_LICENSE(\"GPL\");" << endl;
+ osrc.close();
+
+ // make the module
+ string make_cmd = "make -C '" + s.kernel_build_tree + "'"
+ + " M='" + dir + "' modules";
+ if (s.verbose < 4)
+ make_cmd += " >/dev/null 2>&1";
+ return run_make_cmd(s, make_cmd);
+}
+
/* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */