summaryrefslogtreecommitdiffstats
path: root/main.cxx
diff options
context:
space:
mode:
authorNobuhiro Tachino <tachino@jp.fujitsu.com>2010-02-02 12:19:18 -0500
committerFrank Ch. Eigler <fche@elastic.org>2010-02-02 12:19:18 -0500
commitd0bfd2ac518333369a384d58882ff37d5288225f (patch)
treee034cfa1267148ca18a42b0bc9d56813ea48e56d /main.cxx
parent495b9d7c310985f3c185f4ca642b521141d9b722 (diff)
downloadsystemtap-steved-d0bfd2ac518333369a384d58882ff37d5288225f.tar.gz
systemtap-steved-d0bfd2ac518333369a384d58882ff37d5288225f.tar.xz
systemtap-steved-d0bfd2ac518333369a384d58882ff37d5288225f.zip
rhbz 560890: preserve -L/-l variable ordering
Switch to list<string> from set<string> for collecting available $var lists. Use O(N**2) list-uniqueifier that preserves initial ordering.
Diffstat (limited to 'main.cxx')
-rw-r--r--main.cxx53
1 files changed, 41 insertions, 12 deletions
diff --git a/main.cxx b/main.cxx
index cbedd6e4..0126f323 100644
--- a/main.cxx
+++ b/main.cxx
@@ -156,6 +156,26 @@ usage (systemtap_session& s, int exitcode)
}
+static void uniq_list(list<string>& l)
+{
+ list<string> r;
+ set<string> s;
+
+ for (list<string>::iterator i = l.begin(); i != l.end(); ++i) {
+ s.insert(*i);
+ }
+
+ for (list<string>::iterator i = l.begin(); i != l.end(); ++i) {
+ if (s.find(*i) != s.end()) {
+ s.erase(*i);
+ r.push_back(*i);
+ }
+ }
+
+ l.clear();
+ l.assign(r.begin(), r.end());
+}
+
static void
printscript(systemtap_session& s, ostream& o)
{
@@ -211,8 +231,10 @@ printscript(systemtap_session& s, ostream& o)
// Print the locals and arguments for -L mode only
if (s.listing_mode_vars)
{
- map<string,unsigned> var_list; // format <"name:type",count>
- map<string,unsigned> arg_list;
+ map<string,unsigned> var_count; // format <"name:type",count>
+ map<string,unsigned> arg_count;
+ list<string> var_list;
+ list<string> arg_list;
// traverse set<derived_probe *> to collect all locals and arguments
for (set<derived_probe *>::iterator ix=it->second.begin(); ix!=it->second.end(); ++ix)
{
@@ -223,21 +245,28 @@ printscript(systemtap_session& s, ostream& o)
stringstream tmps;
vardecl* v = p->locals[j];
v->printsig (tmps);
- var_list[tmps.str()]++;
+ var_count[tmps.str()]++;
+ var_list.push_back(tmps.str());
}
// collect arguments of the probe if there
- set<string> arg_set;
+ list<string> arg_set;
p->getargs(arg_set);
- for (set<string>::iterator ia=arg_set.begin(); ia!=arg_set.end(); ++ia)
- arg_list[*ia]++;
+ for (list<string>::iterator ia=arg_set.begin(); ia!=arg_set.end(); ++ia) {
+ arg_count[*ia]++;
+ arg_list.push_back(*ia);
+ }
}
+
+ uniq_list(arg_list);
+ uniq_list(var_list);
+
// print the set-intersection only
- for (map<string,unsigned>::iterator ir=var_list.begin(); ir!=var_list.end(); ++ir)
- if (ir->second == it->second.size()) // print locals
- o << " " << ir->first;
- for (map<string,unsigned>::iterator ir=arg_list.begin(); ir!=arg_list.end(); ++ir)
- if (ir->second == it->second.size()) // print arguments
- o << " " << ir->first;
+ for (list<string>::iterator ir=var_list.begin(); ir!=var_list.end(); ++ir)
+ if (var_count.find(*ir)->second == it->second.size()) // print locals
+ o << " " << *ir;
+ for (list<string>::iterator ir=arg_list.begin(); ir!=arg_list.end(); ++ir)
+ if (arg_count.find(*ir)->second == it->second.size()) // print arguments
+ o << " " << *ir;
}
o << endl;
}