This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: pre-compiled systemtap modules (try 2)


Frank Ch. Eigler wrote:
Hi -

On Thu, Sep 21, 2006 at 01:08:37PM -0500, David Smith wrote:

[...] OK, in the interests of furthering this, I'm attaching a
patch. [...]

Nice, thanks! Go ahead and commit that, and make the needed tweaks in the documentation.

- FChE

That's checked in. Here's a patch to add a '-S dir' option to systemtap, so that you can saved a compiled module to a directory.


--
David Smith
dsmith@redhat.com
Red Hat, Inc.
http://www.redhat.com
256.217.0141 (direct)
256.837.0057 (fax)
Index: main.cxx
===================================================================
RCS file: /cvs/systemtap/src/main.cxx,v
retrieving revision 1.53
diff -u -p -r1.53 main.cxx
--- main.cxx	28 Sep 2006 01:48:59 -0000	1.53
+++ main.cxx	3 Oct 2006 20:03:11 -0000
@@ -26,8 +26,11 @@ extern "C" {
 #include <glob.h>
 #include <unistd.h>
 #include <sys/utsname.h>
+#include <sys/stat.h>
 #include <sys/times.h>
 #include <sys/time.h>
+#include <sys/types.h>
+#include <fcntl.h>
 #include <time.h>
 #include <elfutils/libdwfl.h>
 }
@@ -94,6 +97,7 @@ usage (systemtap_session& s, int exitcod
     << endl
     << "   -x PID     sets target() to PID" << endl
     << "   -t         benchmarking timing information generated" << endl
+    << "   -S DIR     Save the compiled module in DIR" << endl
     ;
   // -d: dump safety-related external references
 
@@ -119,6 +123,7 @@ main (int argc, char * const argv [])
   string cmdline_script; // -e PROGRAM
   string script_file; // FILE
   bool have_script = false;
+  string saved_module_dir = "";
 
   // Initialize defaults
   systemtap_session s;
@@ -161,7 +166,7 @@ main (int argc, char * const argv [])
 
   while (true)
     {
-      int grc = getopt (argc, argv, "hVMvtp:I:e:o:R:r:m:kgc:x:D:bs:u");
+      int grc = getopt (argc, argv, "hVMvtp:I:e:o:R:r:m:kgc:x:D:bs:uS:");
       if (grc < 0)
         break;
       switch (grc)
@@ -259,6 +264,20 @@ main (int argc, char * const argv [])
 	  s.macros.push_back (string (optarg));
 	  break;
 
+	case 'S':
+	  saved_module_dir = string (optarg);
+	  {
+	    struct stat st;
+	    int rc = stat(saved_module_dir.c_str(), &st);
+	    if (rc != 0)
+	      {
+		clog << "Saved module directory " << saved_module_dir
+		     << " check failed: " << strerror(errno) << endl;
+		usage (s, 1);
+	      }
+	  }
+	  break;
+
         case 'h':
           usage (s, 0);
           break;
@@ -299,7 +318,21 @@ main (int argc, char * const argv [])
       usage(s, 1);
     }
 
+  if (!saved_module_dir.empty())
+    {
+      // With '-S', you must run at least pass 4 (the compilation
+      // phase) since there wouldn't be anything to save if we stopped
+      // before pass 4.
+      if (s.last_pass < 4)
+        {
+	  cerr << "When using the -S option, you must specify at least"
+	       << " pass 4 with the -p option." << endl;
+	  usage(s, 1);
+	}
+    }
+
   int rc = 0;
+  int pass4_rc = 0;
 
   // override PATH and LC_ALL
   const char *path = "/bin:/sbin:/usr/bin:/usr/sbin";
@@ -592,6 +625,7 @@ main (int argc, char * const argv [])
          << endl;
 
   // XXX: what to do if rc==0 && last_pass == 4?  dump .ko file to stdout?
+  pass4_rc = rc;
   if (rc || s.last_pass == 4) goto cleanup;
 
   // PASS 5: RUN
@@ -616,6 +650,22 @@ main (int argc, char * const argv [])
   // if (rc) goto cleanup;
 
  cleanup:
+  // If the user requested that we save the module and pass 4 worked,
+  // save module.
+  if (!saved_module_dir.empty() && !pass4_rc && s.last_pass >= 4)
+    {
+      string copycmd = "cp ";
+      copycmd += s.tmpdir + "/" + s.module_name + ".ko " + saved_module_dir;
+      if (s.verbose>1)
+	clog << "Running " << copycmd << endl;
+      int status = system (copycmd.c_str());
+      if (status != 0)
+	clog << "Module save failed, status: " << status << endl;
+      else
+	clog << "Module saved as " << saved_module_dir << "/" 
+	     << s.module_name << ".ko" << endl;
+    }
+
   // Clean up temporary directory.  Obviously, be careful with this.
   if (s.tmpdir == "")
     ; // do nothing

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]