]> sourceware.org Git - systemtap.git/commitdiff
fixes part of PR1194 (passing -o option to stpd)
authortrz <trz>
Wed, 19 Oct 2005 19:35:35 +0000 (19:35 +0000)
committertrz <trz>
Wed, 19 Oct 2005 19:35:35 +0000 (19:35 +0000)
ChangeLog
buildrun.cxx
elaborate.h
main.cxx
runtime/stpd/ChangeLog
runtime/stpd/librelay.c
runtime/stpd/stpd.c

index 672a2afff1e96fb40efd38e27599d3a796d4efd7..cbd613fbd83c81e6d6cdc4221652b5b73353b130 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-10-19  Tom Zanussi  <zanussi@us.ibm.com>
+
+       PR 1194.
+       * elaborate.h: Move output_file variable into systemtap_session.
+       * buildrun.cxx (run_pass): Pass output file to stpd if applicable.
+       * main.cxx (main): Set output_file if -o option specified.
+
 2005-10-18  Frank Ch. Eigler  <fche@redhat.com>
 
        PR 1477.
index 8bc0c4bf51869894b308c7d8e5dd275b8a167a26..ade972be12ff57a4b794d9448a8c21a9d5f03d76 100644 (file)
@@ -148,7 +148,8 @@ run_pass (systemtap_session& s)
       string stpd_cmd = string("sudo ") 
         + string(PKGLIBDIR) + "/stpd "
         + (s.bulk_mode ? "" : "-r ")
-        + (s.verbose ? "" : "-q ");
+        + (s.verbose ? "" : "-q ")
+        + (s.output_file.empty() ? "" : "-o " + s.output_file + " ");
 
       if (s.cmd != "")
        stpd_cmd += "-c \"" + s.cmd + "\" ";
index b2eec8a20c611b1eb8c74f6517fc3ecb7ecfcc93..a4546274afdd64fd5126510aee73c9ba5fbcdd5e 100644 (file)
@@ -206,6 +206,7 @@ struct systemtap_session
   std::string kernel_release;
   std::string runtime_path;
   std::string module_name;
+  std::string output_file;
   std::string cmd;
   int target_pid;
   int last_pass;
index 88ee9540048ac75b71ece2208b0c46922153de28..ca9bfc69c2e91a02778ddc92796c955354467a91 100644 (file)
--- a/main.cxx
+++ b/main.cxx
@@ -110,7 +110,6 @@ main (int argc, char * const argv [])
   string cmdline_script; // -e PROGRAM
   string script_file; // FILE
   bool have_script = false;
-  string output_file = "-"; // -o FILE
 
   // Initialize defaults
   systemtap_session s;
@@ -124,6 +123,7 @@ main (int argc, char * const argv [])
   s.buffer_size = 0;
   s.last_pass = 5;
   s.module_name = "stap_" + stringify(getpid());
+  s.output_file = ""; // -o FILE
   s.keep_tmpdir = false;
   s.cmd = "";
   s.target_pid = 0;
@@ -176,7 +176,7 @@ main (int argc, char * const argv [])
           break;
 
         case 'o':
-          output_file = string (optarg);
+          s.output_file = string (optarg);
           break;
 
         case 't':
index 01a8ef18be069c10242c102fa15c2d0b5d477e4d..2fd032594e08aa6972fdaedeb9a0275ec1380ebe 100644 (file)
@@ -1,3 +1,13 @@
+2005-10-19  Tom Zanussi  <zanussi@us.ibm.com>
+
+       * librelay.c: Move output_file var to stpd.c.
+       (stp_main_loop): If the output_file option was specified,
+       and streaming mode is being used, send output to the file
+       instead of stdout.  If !streaming, send output to the file
+       instead of probe.out.
+       * stpd.c (usage): Add comment for -o option.
+       (main): Add -o option.
+
 2005-10-19  Tom Zanussi  <zanussi@us.ibm.com>
 
        * librelay.c (merge_output): Switch to binary TIMESTAMP.
index b173b5d564ff2505faee6e520b3962d87505f8be..9ed408d9b7fc73cad502c3f874d24d6143fba793 100644 (file)
@@ -58,8 +58,8 @@ static char *percpu_tmpfilebase = "stpd_cpu";
 static char proc_filebase[128];
 static int proc_file[NR_CPUS];
 
-/* probe output written here  */
-static char *outfile_name = "probe.out";
+/* probe output written here, if non-NULL */
+extern char *outfile_name;
 
 /* internal variables */
 static int transport_mode;
@@ -652,6 +652,7 @@ int stp_main_loop(void)
        struct transport_start ts;
        void *data;
        int type;
+       FILE *ofp = stdout;
 
        pthread_mutex_init(&processing_mutex, NULL);
 
@@ -700,13 +701,20 @@ int stp_main_loop(void)
                                        fprintf(stderr, "ERROR: couldn't init relayfs, exiting\n");
                                        exit(1);
                                }
+                       } else if (outfile_name) {
+                               ofp = fopen (outfile_name, "w");
+                               if (!ofp) {
+                                       fprintf (stderr, "ERROR: couldn't open output file %s: errcode = %s\n",
+                                                outfile_name, strerror(errno));
+                                       exit(1);
+                               }
                        }
                        ts.pid = 0; // FIXME. not implemented yet
                        send_request(STP_START, &ts, sizeof(ts));
                        break;
                }
                case STP_REALTIME_DATA:
-                       fputs ((char *)data, stdout);
+                       fputs ((char *)data, ofp);
                        break;
                case STP_OOB_DATA:
                        fputs ((char *)data, stderr);
@@ -732,5 +740,6 @@ int stp_main_loop(void)
                        fprintf(stderr, "WARNING: ignored netlink message of type %d\n", (type));
                }
        }
+       fclose(ofp);
        return 0;
 }
index 2fecc380072ea8159f70b8943dcfa88950c68c10..9587d29f9b76e1245e95437a47090aa48790850e 100644 (file)
@@ -41,10 +41,14 @@ unsigned int buffer_size = 0;
 char *modname = NULL;
 char *modpath = NULL;
 char *target_cmd = NULL;
+char *outfile_name = NULL;
 
  /* relayfs base file name */
 static char stpd_filebase[1024];
 
+/* if no output file name is specified, use this */
+#define DEFAULT_OUTFILE_NAME "probe.out"
+
 /* stp_check script */
 #ifdef PKGLIBDIR
 char *stp_check=PKGLIBDIR "/stp_check";
@@ -54,7 +58,7 @@ char *stp_check="stp_check";
 
 static void usage(char *prog)
 {
-       fprintf(stderr, "\n%s [-m] [-p] [-q] [-r] [-c cmd ] [-t pid] [-b bufsize] kmod-name\n", prog);
+       fprintf(stderr, "\n%s [-m] [-p] [-q] [-r] [-c cmd ] [-t pid] [-b bufsize] [-o FILE] kmod-name\n", prog);
        fprintf(stderr, "-m  Don't merge per-cpu files.\n");
        fprintf(stderr, "-p  Print only.  Don't log to files.\n");
        fprintf(stderr, "-q  Quiet. Don't display trace to stdout.\n");
@@ -63,6 +67,7 @@ static void usage(char *prog)
        fprintf(stderr, "   _stp_target will contain the pid for the command.\n");
        fprintf(stderr, "-t pid.  Sets _stp_target to pid.\n");
        fprintf(stderr, "-b buffer size. The systemtap module will specify a buffer size.\n");
+       fprintf(stderr, "-o FILE. Send output to FILE.\n");
        fprintf(stderr, "   Setting one here will override that value. The value should be\n");
        fprintf(stderr, "   an integer between 1 and 64 which be assumed to be the\n");
        fprintf(stderr, "   buffer size in MB. That value will be per-cpu if relayfs is used.\n");
@@ -74,7 +79,7 @@ int main(int argc, char **argv)
        int c, status;
        pid_t pid;
 
-       while ((c = getopt(argc, argv, "mpqrb:n:t:c:v")) != EOF) 
+       while ((c = getopt(argc, argv, "mpqrb:n:t:c:vo:")) != EOF)
        {
                switch (c) {
                case 'm':
@@ -110,6 +115,9 @@ int main(int argc, char **argv)
                case 'c':
                        target_cmd = optarg;
                        break;
+               case 'o':
+                       outfile_name = optarg;
+                       break;
                default:
                        usage(argv[0]);
                }
@@ -160,6 +168,8 @@ int main(int argc, char **argv)
                        fprintf(stderr, "Could not execute %s\n", stp_check);
                        exit(1);
                }
+               if (!outfile_name)
+                       outfile_name = DEFAULT_OUTFILE_NAME;
        }
        
        sprintf(stpd_filebase, "/mnt/relay/%d/cpu", getpid());
This page took 0.06887 seconds and 5 git commands to generate.