From 67936b03557b2fae27600f858ef319477923b3ea Mon Sep 17 00:00:00 2001 From: jiakai Date: Fri, 29 Sep 2017 17:21:25 +0800 Subject: [PATCH] fix scripts --- gen_header.py | 14 ++++++++++---- src/midout.cpp | 33 ++++----------------------------- 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/gen_header.py b/gen_header.py index d077c34..89fb08a 100755 --- a/gen_header.py +++ b/gen_header.py @@ -3,8 +3,9 @@ import argparse import sys +import subprocess -MAGIC = 'midout_trace v0\n' +MAGIC = 'midout_trace v1\n' class MidoutHeaderGen: _tag_names = None @@ -16,7 +17,7 @@ class MidoutHeaderGen: def add_item(self, name: str): prefix = 'midout::Region \\', file=fout) print('struct {} {{ static constexpr bool enable = true; }}; \\'. format(i), file=fout) @@ -49,8 +51,12 @@ def main(): for i in args.inputs: with open(i) as fin: assert fin.read(len(MAGIC)) == MAGIC, 'bad trace file' - for line in fin: - gen.add_item(line.strip()) + demangle = subprocess.check_output( + ['c++filt', '-t'], input='\n'.join(list(fin)).encode('utf-8')) + for line in demangle.decode('utf-8').split('\n'): + line = line.strip() + if line: + gen.add_item(line) if not args.output: gen.write(sys.stdout) diff --git a/src/midout.cpp b/src/midout.cpp index 89bd8f9..2e6dd3f 100644 --- a/src/midout.cpp +++ b/src/midout.cpp @@ -20,31 +20,6 @@ void midout_empty() { #include #include -#ifdef __GNUG__ -#include -#include -#include - -std::string demangle(const char* name) { - int status; - - std::unique_ptr res { - abi::__cxa_demangle(name, NULL, NULL, &status), - std::free - }; - - if (status) { - fprintf(stderr, "midout: failed to demangle\n"); - abort(); - } - - return res.get(); -} - -#else -#error "unsupported compiler: can not demangle type name" -#endif - namespace { class UsedTypes { std::unordered_set m_types; @@ -71,11 +46,11 @@ namespace { "midout: failed to open output file %s: %s\n", output_fname, strerror(errno)); } - fprintf(fout, "midout_trace v0\n"); + fprintf(fout, "midout_trace v1\n"); std::vector sorted_types; sorted_types.reserve(m_types.size()); for (auto &&i: m_types) { - sorted_types.emplace_back(demangle(i)); + sorted_types.emplace_back(i); } std::sort(sorted_types.begin(), sorted_types.end()); for (auto &&i: sorted_types) { @@ -87,11 +62,11 @@ namespace { sorted_types.size(), output_fname); } }; - UsedTypes g_used_types; } void midout::on_region_used(const std::type_info &type) { - g_used_types.add(type.name()); + static UsedTypes used_types; + used_types.add(type.name()); } #endif // MIDOUT_PROFILING -- GitLab