]> sourceware.org Git - systemtap.git/commitdiff
Add more log messages and fix various formatting
authorLukas Berk <lberk@redhat.com>
Sun, 3 Mar 2013 00:35:06 +0000 (19:35 -0500)
committerLukas Berk <lberk@redhat.com>
Wed, 1 May 2013 15:10:08 +0000 (11:10 -0400)
*tapset-method.cxx: fix various formatting and add verbosity messages

tapset-method.cxx

index 03780d94c119f28d36c15abaddadc4bf470a2b04..561ac5bc67e6d3e9c70337d779c146a725333a0e 100644 (file)
@@ -28,15 +28,10 @@ extern "C" {
 using namespace std;
 using namespace __gnu_cxx;
 
-static const string TOK_CLASS("class");
-static const string TOK_METHOD("method");
-static const string TOK_PROCESS("process");
-static const string TOK_MARK("mark");
-
-/** check to see if TOK_CLASS is empty
-   if so, reverse check TOK_METHOD for '.'
-   representing the method name.
-*/
+static const string TOK_CLASS ("class");
+static const string TOK_METHOD ("method");
+static const string TOK_PROCESS ("process");
+static const string TOK_MARK ("mark");
 
 struct java_builder: public derived_probe_builder
 {
@@ -49,21 +44,21 @@ private:
   java_cache_t java_cache;
 
 public:
-  java_builder(): cache_initialized(false) {}
+  java_builder (): cache_initialized (false) {}
 
-  void build(systemtap_session & sess,
-            probe * base,
-            probe_point * location,
-            literal_map_t const & parameters,
-            vector<derived_probe *> & finished_results);
+  void build (systemtap_session & sess,
+             probe * base,
+             probe_point * location,
+             literal_map_t const & parameters,
+             vector <derived_probe *> & finished_results);
 
-  bool get_number_param(literal_map_t const & params,
-                       string const & k, int & v);
+  bool get_number_param (literal_map_t const & params,
+                        string const & k, int & v);
 };
 
 bool
-java_builder::get_number_param(literal_map_t const & params,
-                            string const & k, int & v)
+java_builder::get_number_param (literal_map_t const & params,
+                               string const & k, int & v)
 {
   int64_t value;
   bool present = derived_probe_builder::get_param (params, k, value);
@@ -73,41 +68,37 @@ java_builder::get_number_param(literal_map_t const & params,
 
 
 void
-java_builder::build(systemtap_session & sess,
-                   probe * base,
-                   probe_point * loc,
-                   literal_map_t const & parameters,
-                   vector<derived_probe *> & finished_results)
+java_builder::build (systemtap_session & sess,
+                    probe * base,
+                    probe_point * loc,
+                    literal_map_t const & parameters,
+                    vector <derived_probe *> & finished_results)
 {
 
-  // XXX eventually this is where we'll check the type of format
   string method_str_val;
   bool has_method_str = get_param (parameters, TOK_METHOD, method_str_val);
-  // XXX new var that is only the method name, go to the '('
-  int short_method_pos = method_str_val.find('(');
+  int short_method_pos = method_str_val.find ('(');
   //only if it exists, run check
   bool one_arg = false;
-  if(short_method_pos)
+  if (short_method_pos)
     {
       int second_method_pos = 0;
-      second_method_pos = method_str_val.find(')');
-      if((second_method_pos - short_method_pos) >=1)
+      second_method_pos = method_str_val.find (')');
+      if ((second_method_pos - short_method_pos) >= 1)
        one_arg = true;
     }
-  string short_method_str = method_str_val.substr(0, short_method_pos);
+  string short_method_str = method_str_val.substr (0, short_method_pos);
   string class_str_val; // fully qualified class string
   bool has_class_str = get_param (parameters, TOK_CLASS, class_str_val);
   int java_pid;
   bool has_pid_int = get_number_param (parameters, TOK_PROCESS, java_pid);
   //need to count the number of parameters, exit if more than 10
-  // need to account for just one var (which won't have any ',')
-  // XXX calculate distance between (), if greater than 0, assume one var
   int method_params_counter = 1;
-  int method_params_count = count(method_str_val.begin(), method_str_val.end(), ',');
-  if(one_arg && method_params_count == 0)
+  int method_params_count = count (method_str_val.begin (), method_str_val.end (), ',');
+  if (one_arg && method_params_count == 0)
     method_params_count++; // in this case we know there was at least a var, but no ','
 
-  if(method_params_count > 10)
+  if (method_params_count > 10)
     {
       cerr << _("Error: Maximum of 10 method parameters may be specified") << endl;
       return;
@@ -123,18 +114,24 @@ java_builder::build(systemtap_session & sess,
 
       cache_initialized = true;
       byteman_script_path = sess.tmpdir + "/stap-byteman.btm";
-      cout << "path: " << byteman_script_path << endl;
+      if (sess.verbose > 3)
+       {
+         clog << "byteman script path: " << byteman_script_path
+              << endl;
+       }
       ofstream byteman_script;
-      byteman_script.open(byteman_script_path.c_str(), ifstream::out);
+      byteman_script.open (byteman_script_path.c_str (), ifstream::out);
       if (! byteman_script)
        {
          if (sess.verbose > 3)
            //TRANSLATORS: Specific path cannot be opened
            clog << byteman_script_path << _(" cannot be opened: ")
-                << strerror(errno) << endl;
+                << strerror (errno) << endl;
          return;
        }
 
+      if (sess.verbose > 2)
+       clog << "Writting byteman script" << endl;
       // none of this should be translated, byteman syntax is specific
       byteman_script << "RULE Stap " << sess.base_hash << endl;
       // we'll need detection here for second type of syntax
@@ -148,17 +145,20 @@ java_builder::build(systemtap_session & sess,
                     << "(\"stap-" << sess.base_hash << "\", \""
                     << short_method_str << "\", ";
       // we need increment the var number, while decrementing the count
-      for(method_params_counter = 1;
-         method_params_counter <= method_params_count;
-         method_params_counter++)
+      for (method_params_counter = 1;
+          method_params_counter <= method_params_count;
+          method_params_counter++)
        {
          byteman_script << "$" << method_params_counter;
-         if(!(method_params_counter + 1 >= method_params_count))
+         if (! (method_params_counter + 1 >= method_params_count))
            byteman_script << ", ";
        }
       byteman_script << ")" << endl;
       byteman_script << "ENDRULE" << endl;
       byteman_script.close();
+      if (sess.verbose > 2)
+       clog << "Finished writting byteman script" << endl;
+      
     }
 
   /* we've written the byteman script, have its location 
@@ -169,25 +169,28 @@ java_builder::build(systemtap_session & sess,
    * continue regular compilation and action with redefined probe
    */
 
-  if(!(has_pid_int))
-    exit(1); //XXX proper exit with warning message
+  if (! (has_pid_int))
+    exit (1); //XXX proper exit with warning message
 
   //this could be done using itoa
-  string arg = static_cast<ostringstream*>( &(ostringstream()
-                                             << java_pid) )->str();
+  string arg = static_cast <ostringstream*> ( & (ostringstream ()
+                                             << java_pid) )->str ();
 
-  const char* a1 = arg.c_str();
-  const char* b1 = (find_executable("bminstall.sh")).c_str();
+  const char* java_pid_str = arg.c_str ();
+  const char* bminstall_path = (find_executable ("bminstall.sh")).c_str ();
+
+  if (sess.verbose > 3)
+    clog << "Reported bminstall.sh path: " << bminstall_path << endl;
   // XXX check both scripts here, exit if not available
-  const char* space = " "; //XXX test if required
+  const char* space = " ";
 
   int bminstall; //bminstall command status
   int bmsubmit; //bmsubmit command status
-  pid_t install_pid = fork();
-  if(install_pid == 0)
+  pid_t install_pid = fork ();
+  if (install_pid == 0)
     {
-      execl (b1, space, a1, (char*)NULL);
-      _exit(EXIT_FAILURE);
+      execl (bminstall_path, space, java_pid_str, (char*)NULL);
+      _exit (EXIT_FAILURE);
     }
   else if (install_pid < 0) //failure
     bminstall = -1;
@@ -195,15 +198,18 @@ java_builder::build(systemtap_session & sess,
     if (waitpid (install_pid, &bminstall, 0) != install_pid)
       bminstall = -1;
   //XXX better var names needed
-  const char* a2 = " -l";
-  const char* a3 = byteman_script_path.c_str();
+  const char* bmsubmit_option = " -l";
+  const char* bmsubmit_script = byteman_script_path.c_str ();
   //XXX once again check if needed
-  const char* b2 = (find_executable("bmsubmit.sh")).c_str();
-  pid_t submit_pid = fork();
-  if(submit_pid == 0)
+  const char* bmsubmit_path = (find_executable ("bmsubmit.sh")).c_str ();
+  if (sess.verbose > 3)
+    clog << "Reported bmsubmit.sh path: " << bminstall_path << endl;
+
+  pid_t submit_pid = fork ();
+  if (submit_pid == 0)
     {
-      execl(b2, a2, a3, NULL);
-      _exit(EXIT_FAILURE);
+      execl (bmsubmit_path, bmsubmit_option, bmsubmit_script, NULL);
+      _exit (EXIT_FAILURE);
     }
   else if (submit_pid < 0) //failure
     bmsubmit = -1;
@@ -217,29 +223,31 @@ java_builder::build(systemtap_session & sess,
    * using a vector, iterate though, changing as needed
    * redefine functor values with new literal_string("foo")
    */
-  probe_point* new_loc = new probe_point(*loc);
+  probe_point* new_loc = new probe_point (*loc);
   
   //XXX this needs to be checked if it exists, and made a configure var
   //XXX rename the variables here
   string helper_loc = "/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/jre/lib/amd64/libHelperSDTv2.so";
   vector<probe_point::component*> java_marker;
-  java_marker.push_back( new probe_point::component(TOK_PROCESS, new literal_string(helper_loc)));
-  java_marker.push_back( new probe_point::component(TOK_MARK, new literal_string("*")));
-  probe_point * derived_loc = new probe_point(*new_loc);
+  java_marker.push_back( new probe_point::component 
+                        (TOK_PROCESS, new literal_string (helper_loc)));
+  java_marker.push_back( new probe_point::component 
+                        (TOK_MARK, new literal_string ("*")));
+  probe_point * derived_loc = new probe_point (*new_loc);
   derived_loc->components = java_marker;
-  probe *new_base = base->create_alias(derived_loc, new_loc);
-  derive_probes(sess, new_base, finished_results);
+  probe *new_mark_probe = base->create_alias (derived_loc, new_loc);
+  derive_probes (sess, new_mark_probe, finished_results);
 }
 
 void
-register_tapset_java(systemtap_session& s)
+register_tapset_java (systemtap_session& s)
 {
   match_node* root = s.pattern_root;
-  derived_probe_builder *builder = new java_builder(); //XXX need to define
+  derived_probe_builder *builder = new java_builder ();
   
-  root = root->bind_num(TOK_PROCESS)
-    ->bind_str(TOK_CLASS)->bind_str(TOK_METHOD);
-  root->bind(builder);
+  root = root->bind_num (TOK_PROCESS)
+    ->bind_str (TOK_CLASS)->bind_str (TOK_METHOD);
+  root->bind (builder);
 
 }
 
This page took 0.038096 seconds and 5 git commands to generate.