diff options
author | jistone <jistone> | 2006-01-05 21:59:21 +0000 |
---|---|---|
committer | jistone <jistone> | 2006-01-05 21:59:21 +0000 |
commit | 1820694f646c02851ecd223278d275e73ec1e1e0 (patch) | |
tree | dff3286272508f5b675ebe1724a75a05910bb69e | |
parent | 8616e84e10c240791bed6f1ce7d4da3476078acc (diff) | |
download | systemtap-steved-1820694f646c02851ecd223278d275e73ec1e1e0.tar.gz systemtap-steved-1820694f646c02851ecd223278d275e73ec1e1e0.tar.xz systemtap-steved-1820694f646c02851ecd223278d275e73ec1e1e0.zip |
2006-01-05 Josh Stone <joshua.i.stone@intel.com>
PR 2056
* translate.cxx (var::~var, var::hist, var::buckets): make these
methods virtual, so we can use polymorphism.
(mapvar::hist, mapvar::buckets): Override the corresponding var
methods to handle pmaps correctly.
(c_unparser::visit_arrayindex, c_unparser::visit_print_format): Make
use of the new polymorphic behavior of var & mapvar when dealing with
histogram data.
* testsuite/buildok/pmap_foreach.stp: Add tests to check histogram
accesses with for/foreach.
-rw-r--r-- | ChangeLog | 13 | ||||
-rwxr-xr-x | testsuite/buildok/pmap_foreach.stp | 12 | ||||
-rw-r--r-- | translate.cxx | 60 |
3 files changed, 70 insertions, 15 deletions
@@ -1,3 +1,16 @@ +2006-01-05 Josh Stone <joshua.i.stone@intel.com> + + PR 2056 + * translate.cxx (var::~var, var::hist, var::buckets): make these + methods virtual, so we can use polymorphism. + (mapvar::hist, mapvar::buckets): Override the corresponding var + methods to handle pmaps correctly. + (c_unparser::visit_arrayindex, c_unparser::visit_print_format): Make + use of the new polymorphic behavior of var & mapvar when dealing with + histogram data. + * testsuite/buildok/pmap_foreach.stp: Add tests to check histogram + accesses with for/foreach. + 2006-01-04 Frank Ch. Eigler <fche@elastic.org> PR 2057. diff --git a/testsuite/buildok/pmap_foreach.stp b/testsuite/buildok/pmap_foreach.stp index 8cc8decd..14912e16 100755 --- a/testsuite/buildok/pmap_foreach.stp +++ b/testsuite/buildok/pmap_foreach.stp @@ -14,9 +14,17 @@ probe begin { } probe end { - for (i=1;i<4;i++) + for (i=1;i<4;i++) { printf("count of foo[%d] = %d\n", i, @count(foo[i])) + printf("first bucket of hist_log of foo[%d] = %d\n", + i, @hist_log(foo[i])[0]) + print(@hist_log(foo[i])) + } - foreach (i in foo) + foreach (i in foo) { printf("count of foo[%d] = %d\n", i, @count(foo[i])) + printf("first bucket of hist_log of foo[%d] = %d\n", + i, @hist_log(foo[i])[0]) + print(@hist_log(foo[i])) + } } diff --git a/translate.cxx b/translate.cxx index 5bad6bdf..791e5434 100644 --- a/translate.cxx +++ b/translate.cxx @@ -1,6 +1,6 @@ // translation pass // Copyright (C) 2005, 2006 Red Hat Inc. -// Copyright (C) 2005 Intel Corporation +// Copyright (C) 2005, 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 @@ -294,6 +294,8 @@ public: : local(local), ty(ty), name(name) {} + virtual ~var() {} + bool is_local() const { return local; @@ -340,14 +342,14 @@ public: return "global_" + name; } - string hist() const + virtual string hist() const { assert (ty == pe_stats); assert (sd.type != statistic_decl::none); return "(&(" + qname() + "->hist))"; } - string buckets() const + virtual string buckets() const { assert (ty == pe_stats); assert (sd.type != statistic_decl::none); @@ -633,6 +635,20 @@ struct mapvar else throw semantic_error("setting a value of an unsupported map type"); } + + string hist() const + { + assert (ty == pe_stats); + assert (sd.type != statistic_decl::none); + return "(&(" + fetch_existing_aggregate() + "->hist))"; + } + + string buckets() const + { + assert (ty == pe_stats); + assert (sd.type != statistic_decl::none); + return "(" + fetch_existing_aggregate() + "->hist.buckets)"; + } string init () const { @@ -2854,13 +2870,19 @@ c_unparser::visit_arrayindex (arrayindex* e) assert(idx[0].type() == pe_long); symbol *sym = get_symbol_within_expression (hist->stat); - var v = getvar(sym->referent, sym->tok); - v.assert_hist_compatible(*hist); + + var *v; + if (sym->referent->arity < 1) + v = new var(getvar(sym->referent, e->tok)); + else + v = new mapvar(getmap(sym->referent, e->tok)); + + v->assert_hist_compatible(*hist); { - varlock_w guard(*this, v); + varlock_w guard(*this, *v); o->newline() << "c->last_stmt = " << lex_cast_qstring(*e->tok) << ";"; - o->newline() << "if (" << histogram_index_check(v, idx[0]) << ")"; + o->newline() << "if (" << histogram_index_check(*v, idx[0]) << ")"; o->newline() << "{"; o->newline(1) << res << " = " << agg << "->histogram[" << idx[0] << "];"; o->newline(-1) << "}"; @@ -2871,6 +2893,8 @@ c_unparser::visit_arrayindex (arrayindex* e) o->newline(-1) << "}"; } + delete v; + o->newline() << res << ";"; } } @@ -3161,13 +3185,23 @@ c_unparser::visit_print_format (print_format* e) stmt_expr block(*this); symbol *sym = get_symbol_within_expression (e->hist->stat); aggvar agg = gensym_aggregate (); - var v = getvar(sym->referent, e->tok); - v.assert_hist_compatible(*e->hist); - varlock_w guard(*this, v); - load_aggregate(e->hist->stat, agg); - o->newline() << "c->last_stmt = " << lex_cast_qstring(*e->tok) << ";"; - o->newline() << "_stp_stat_print_histogram (" << v.hist() << ", " << agg.qname() << ");"; + var *v; + if (sym->referent->arity < 1) + v = new var(getvar(sym->referent, e->tok)); + else + v = new mapvar(getmap(sym->referent, e->tok)); + + v->assert_hist_compatible(*e->hist); + + { + varlock_w guard(*this, *v); + load_aggregate(e->hist->stat, agg); + o->newline() << "c->last_stmt = " << lex_cast_qstring(*e->tok) << ";"; + o->newline() << "_stp_stat_print_histogram (" << v->hist() << ", " << agg.qname() << ");"; + } + + delete v; } else { |