提交 67936b03 编写于 作者: J jiakai

fix scripts

上级 b47e63cb
...@@ -3,8 +3,9 @@ ...@@ -3,8 +3,9 @@
import argparse import argparse
import sys import sys
import subprocess
MAGIC = 'midout_trace v0\n' MAGIC = 'midout_trace v1\n'
class MidoutHeaderGen: class MidoutHeaderGen:
_tag_names = None _tag_names = None
...@@ -16,7 +17,7 @@ class MidoutHeaderGen: ...@@ -16,7 +17,7 @@ class MidoutHeaderGen:
def add_item(self, name: str): def add_item(self, name: str):
prefix = 'midout::Region<midout::tags::' prefix = 'midout::Region<midout::tags::'
assert name.startswith(prefix), 'bad name: {}'.format(name) assert name.startswith(prefix), 'bad name: {!r}'.format(name)
comma = name.find(',', len(prefix)) comma = name.find(',', len(prefix))
self._tag_names.add(name[len(prefix):comma]) self._tag_names.add(name[len(prefix):comma])
self._region_names.add(name) self._region_names.add(name)
...@@ -30,6 +31,7 @@ class MidoutHeaderGen: ...@@ -30,6 +31,7 @@ class MidoutHeaderGen:
for i in self._region_names: for i in self._region_names:
i = i.replace('midout::', '') i = i.replace('midout::', '')
i = i.replace('__ndk1::', '')
print('template<> \\', file=fout) print('template<> \\', file=fout)
print('struct {} {{ static constexpr bool enable = true; }}; \\'. print('struct {} {{ static constexpr bool enable = true; }}; \\'.
format(i), file=fout) format(i), file=fout)
...@@ -49,8 +51,12 @@ def main(): ...@@ -49,8 +51,12 @@ def main():
for i in args.inputs: for i in args.inputs:
with open(i) as fin: with open(i) as fin:
assert fin.read(len(MAGIC)) == MAGIC, 'bad trace file' assert fin.read(len(MAGIC)) == MAGIC, 'bad trace file'
for line in fin: demangle = subprocess.check_output(
gen.add_item(line.strip()) ['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: if not args.output:
gen.write(sys.stdout) gen.write(sys.stdout)
......
...@@ -20,31 +20,6 @@ void midout_empty() { ...@@ -20,31 +20,6 @@ void midout_empty() {
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#ifdef __GNUG__
#include <cstdlib>
#include <memory>
#include <cxxabi.h>
std::string demangle(const char* name) {
int status;
std::unique_ptr<char, void(*)(void*)> 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 { namespace {
class UsedTypes { class UsedTypes {
std::unordered_set<const char*> m_types; std::unordered_set<const char*> m_types;
...@@ -71,11 +46,11 @@ namespace { ...@@ -71,11 +46,11 @@ namespace {
"midout: failed to open output file %s: %s\n", "midout: failed to open output file %s: %s\n",
output_fname, strerror(errno)); output_fname, strerror(errno));
} }
fprintf(fout, "midout_trace v0\n"); fprintf(fout, "midout_trace v1\n");
std::vector<std::string> sorted_types; std::vector<std::string> sorted_types;
sorted_types.reserve(m_types.size()); sorted_types.reserve(m_types.size());
for (auto &&i: m_types) { for (auto &&i: m_types) {
sorted_types.emplace_back(demangle(i)); sorted_types.emplace_back(i);
} }
std::sort(sorted_types.begin(), sorted_types.end()); std::sort(sorted_types.begin(), sorted_types.end());
for (auto &&i: sorted_types) { for (auto &&i: sorted_types) {
...@@ -87,11 +62,11 @@ namespace { ...@@ -87,11 +62,11 @@ namespace {
sorted_types.size(), output_fname); sorted_types.size(), output_fname);
} }
}; };
UsedTypes g_used_types;
} }
void midout::on_region_used(const std::type_info &type) { 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 #endif // MIDOUT_PROFILING
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册