]> sourceware.org Git - systemtap.git/commitdiff
2006-01-16 Josh Stone <joshua.i.stone@intel.com>
authorjistone <jistone>
Mon, 16 Jan 2006 23:40:50 +0000 (23:40 +0000)
committerjistone <jistone>
Mon, 16 Jan 2006 23:40:50 +0000 (23:40 +0000)
PR 2140
* translate.cxx (mapvar::del): Add ability to delete an indexed stat
from (p)maps.
(delete_statement_operand_visitor::visit_symbol): Add ability to
delete entire pmaps and scalars.
(delete_statement_operand_tmp_visitor): Add a special tmpvar visitor
to parallel delete_statement_operand_visitor.
(c_tmpcounter::visit_delete_statement): Invoke the new visitor.
* testsuite/buildok/delete.stp: Also test scalar deletes.
* vim/syntax/stap.vim: Recognize 'delete' operator.

2006-01-16  Josh Stone  <joshua.i.stone@intel.com>

* stat.c (_stp_stat_clear): add a function that just
clears a Stat, so we can use delete in the translator.

ChangeLog
runtime/ChangeLog
runtime/stat.c
testsuite/buildok/delete.stp
translate.cxx
vim/syntax/stap.vim

index 2410547bafbeaa47a2a58fa218c3bc3515121034..f9daa2414da969bace414c14b6bb1ebf50bb7b15 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2006-01-16  Josh Stone  <joshua.i.stone@intel.com>
+
+       PR 2140
+       * translate.cxx (mapvar::del): Add ability to delete an indexed stat
+       from (p)maps.
+       (delete_statement_operand_visitor::visit_symbol): Add ability to
+       delete entire pmaps and scalars.
+       (delete_statement_operand_tmp_visitor): Add a special tmpvar visitor
+       to parallel delete_statement_operand_visitor.
+       (c_tmpcounter::visit_delete_statement): Invoke the new visitor.
+       * testsuite/buildok/delete.stp: Also test scalar deletes.
+       * vim/syntax/stap.vim: Recognize 'delete' operator.
+
 2006-01-15  Frank Ch. Eigler  <fche@elastic.org>
 
        PR 2148
index 159bb4840d4bf460ea125868555f39deaa55965b..099949bfd6c6691d06df2875af1c0ce4715baa6d 100644 (file)
@@ -1,3 +1,8 @@
+2006-01-16  Josh Stone  <joshua.i.stone@intel.com>
+
+       * stat.c (_stp_stat_clear): add a function that just
+       clears a Stat, so we can use delete in the translator.
+
 2006-01-16  Martin Hunt  <hunt@redhat.com>
 
        * map.c (_stp_pmap_agg): Return NULL when aggregation
index c759a043ef15b2264229a739eb7e4eaa3ba7b021..29dcef9b871f8be653d6a90d89d7c17140b49c2e 100644 (file)
@@ -1,6 +1,7 @@
 /* -*- linux-c -*-
  * Statistics Aggregation
  * Copyright (C) 2005 Red Hat Inc.
+ * Copyright (C) 2006 Intel Corporation
  *
  * This file is part of systemtap, and is free software.  You can
  * redistribute it and/or modify it under the terms of the GNU General
@@ -270,6 +271,22 @@ void _stp_stat_print (Stat st, char *fmt, int clear)
        __stp_stat_print (fmt, st, agg, 0);
        STAT_UNLOCK(agg);
 }
+
+/** Clear Stats.
+ * Clears the Stats.
+ *
+ * @param st Stat
+ */
+void _stp_stat_clear (Stat st)
+{
+       int i;
+       for_each_cpu(i) {
+               stat *sd = per_cpu_ptr (st->sd, i);
+               STAT_LOCK(sd);
+               _stp_stat_clear_data (st, sd);
+               STAT_UNLOCK(sd);
+       }
+}
 /** @} */
 #endif /* _STAT_C_ */
 
index 20ad109a9ed2ea89a45c4b4405ef3c6ef7ce6c8d..52b3936d686547516e16038b1ed7fb67ab2596ce 100755 (executable)
@@ -1,20 +1,17 @@
 #! stap -p4
 #
 # Make sure that 'delete' works in all variations.
-#
-# NOTE: It hasn't been decided yet whether 'delete' should work on scalar
-# numbers and strings, so for now those are commented out.
 
 global a, b, c, d, e, f
 
 probe begin {
-    a = 1; #delete a;
-    b = "b"; #delete b;
+    a = 1; delete a;
+    b = "b"; delete b;
     c <<< 1; delete c;
     d[1] = 1; delete d[1]; delete d; 
     e[1] = "e"; delete e[1]; delete e; 
     f[1] <<< 1; delete f[1]; delete f;
 
-    x = 1; #delete x;
-    y = "y"; #delete y;
+    x = 1; delete x;
+    y = "y"; delete y;
 }
index 2b0e44fa8996935333c4580e741005705a625626..094262f34f1c80acc7a4024fc96bd088a6852d15 100644 (file)
@@ -185,7 +185,7 @@ struct c_tmpcounter:
   void visit_for_loop (for_loop* s);
   void visit_foreach_loop (foreach_loop* s);
   // void visit_return_statement (return_statement* s);
-  // void visit_delete_statement (delete_statement* s);
+  void visit_delete_statement (delete_statement* s);
   void visit_binary_expression (binary_expression* e);
   // void visit_unary_expression (unary_expression* e);
   void visit_pre_crement (pre_crement* e);
@@ -610,7 +610,7 @@ struct mapvar
   { 
     if (type() == pe_string)
       return (call_prefix("set", indices) + ", NULL)");
-    else if (type() == pe_long)
+    else if ((type() == pe_long) || (type() == pe_stats))
       return (call_prefix("set", indices) + ", 0)");
     else
       throw semantic_error("setting a value of an unsupported map type");
@@ -2135,6 +2135,18 @@ c_unparser::visit_next_statement (next_statement* s)
 }
 
 
+struct delete_statement_operand_tmp_visitor:
+  public traversing_visitor
+{
+  c_tmpcounter *parent;
+  delete_statement_operand_tmp_visitor (c_tmpcounter *p):
+    parent (p)
+  {}
+  //void visit_symbol (symbol* e);
+  void visit_arrayindex (arrayindex* e);
+};
+
+
 struct delete_statement_operand_visitor:
   public throwing_visitor
 {
@@ -2150,14 +2162,65 @@ struct delete_statement_operand_visitor:
 void 
 delete_statement_operand_visitor::visit_symbol (symbol* e)
 {
-  mapvar mvar = parent->getmap(e->referent, e->tok);  
-  varlock_w guard (*parent, mvar);
-  /* NB: such memory deallocation/allocation operations
-     are not generally legal in all probe contexts.
-  parent->o->newline() << mvar.fini ();
-  parent->o->newline() << mvar.init ();  
-  */
-  parent->o->newline() << "_stp_map_clear (" << mvar.qname() << ");";
+  if (e->referent->arity > 0)
+    {
+      mapvar mvar = parent->getmap(e->referent, e->tok);  
+      varlock_w guard (*parent, mvar);
+      /* NB: such memory deallocation/allocation operations
+       are not generally legal in all probe contexts.
+      parent->o->newline() << mvar.fini ();
+      parent->o->newline() << mvar.init ();  
+      */
+      if (mvar.is_parallel())
+       parent->o->newline() << "_stp_pmap_clear (" << mvar.qname() << ");";
+      else
+       parent->o->newline() << "_stp_map_clear (" << mvar.qname() << ");";
+    }
+  else
+    {
+      var v = parent->getvar(e->referent, e->tok);  
+      varlock_w guard (*parent, v);
+      switch (e->type)
+       {
+       case pe_stats:
+         parent->o->newline() << "_stp_stat_clear (" << v.qname() << ");";
+         break;
+       case pe_long:
+         parent->o->newline() << v.qname() << " = 0;";
+         break;
+       case pe_string:
+         parent->o->newline() << v.qname() << "[0] = '\\0';";
+         break;
+       case pe_unknown:
+       default:
+         throw semantic_error("Cannot delete unknown expression type", e->tok);
+       }
+    }
+}
+
+void 
+delete_statement_operand_tmp_visitor::visit_arrayindex (arrayindex* e)
+{
+  symbol *array;  
+  hist_op *hist;
+  classify_indexable (e->base, array, hist);
+
+  if (array)
+    {
+      vardecl* r = array->referent;
+
+      // One temporary per index dimension.
+      for (unsigned i=0; i<r->index_types.size(); i++)
+       {
+         tmpvar ix = parent->parent->gensym (r->index_types[i]);
+         ix.declare (*(parent->parent));
+         e->indexes[i]->visit(parent);
+       }
+    }
+  else
+    {
+      throw semantic_error("cannot delete histogram bucket entries\n", e->tok);
+    }
 }
 
 void 
@@ -2185,6 +2248,14 @@ delete_statement_operand_visitor::visit_arrayindex (arrayindex* e)
 }
 
 
+void
+c_tmpcounter::visit_delete_statement (delete_statement* s)
+{
+  delete_statement_operand_tmp_visitor dv (this);
+  s->value->visit (&dv);
+}
+
+
 void
 c_unparser::visit_delete_statement (delete_statement* s)
 {
index 39947179cf2be4b71d894f498a148aa3a732f0c4..86c7d260fe1fc0f92f00b0dd222f3656ac340edc 100644 (file)
@@ -11,7 +11,7 @@ elseif exists("b:current_syntax")
   finish
 endif
 
-syn keyword stapStatement   contained break continue return next containedin=stapBlock
+syn keyword stapStatement   contained break continue return next delete containedin=stapBlock
 syn keyword stapRepeat      contained while for foreach in containedin=stapBlock
 syn keyword stapConditional contained if else containedin=stapBlock
 syn keyword stapDeclaration global probe function
This page took 0.056868 seconds and 5 git commands to generate.