Commit d8c1a8c0 authored by Tudor Bosman's avatar Tudor Bosman Committed by Jordan DeLong

Remove Stream

Summary:
Switch existing code to gen::byLine.  Also fix namespaces in
folly/experimental/(symbolizer|exception_tracer).

Test Plan:
fbconfig -r folly && fbmake runtests_opt, ran non-test folly
binaries by hand, fbgs for other uses (there aren't any)

Reviewed By: tjackson@fb.com

FB internal diff: D629576
parent a0b4acce
...@@ -247,9 +247,9 @@ template<class Value, ...@@ -247,9 +247,9 @@ template<class Value,
class Gen, class Gen,
class Handler> class Handler>
typename std::enable_if< typename std::enable_if<
IsCompatibleSignature<Handler, bool(Value)>::value>::type IsCompatibleSignature<Handler, bool(Value)>::value, bool>::type
operator|(const GenImpl<Value, Gen>& gen, Handler&& handler) { operator|(const GenImpl<Value, Gen>& gen, Handler&& handler) {
gen.self().apply(std::forward<Handler>(handler)); return gen.self().apply(std::forward<Handler>(handler));
} }
/** /**
......
...@@ -36,9 +36,10 @@ GetExceptionStackTraceStackType getExceptionStackTraceStackFn; ...@@ -36,9 +36,10 @@ GetExceptionStackTraceStackType getExceptionStackTraceStackFn;
} // namespace } // namespace
using namespace ::facebook::symbolizer; using namespace ::folly::symbolizer;
using namespace __cxxabiv1; using namespace __cxxabiv1;
namespace folly {
namespace exception_tracer { namespace exception_tracer {
std::ostream& operator<<(std::ostream& out, const ExceptionInfo& info) { std::ostream& operator<<(std::ostream& out, const ExceptionInfo& info) {
...@@ -198,4 +199,5 @@ void installHandlers() { ...@@ -198,4 +199,5 @@ void installHandlers() {
} }
} // namespace exception_tracer } // namespace exception_tracer
} // namespace folly
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <vector> #include <vector>
#include <iostream> #include <iostream>
namespace folly {
namespace exception_tracer { namespace exception_tracer {
struct ExceptionInfo { struct ExceptionInfo {
...@@ -47,6 +48,7 @@ std::vector<ExceptionInfo> getCurrentExceptions(); ...@@ -47,6 +48,7 @@ std::vector<ExceptionInfo> getCurrentExceptions();
void installHandlers(); void installHandlers();
} // namespace exception_tracer } // namespace exception_tracer
} // namespace folly
#endif /* FOLLY_EXPERIMENTAL_EXCEPTION_TRACER_EXCEPTIONTRACER_H_ */ #endif /* FOLLY_EXPERIMENTAL_EXCEPTION_TRACER_EXCEPTIONTRACER_H_ */
...@@ -173,7 +173,7 @@ namespace { ...@@ -173,7 +173,7 @@ namespace {
struct Initializer { struct Initializer {
Initializer() { Initializer() {
try { try {
exception_tracer::installHandlers(); ::folly::exception_tracer::installHandlers();
} catch (...) { } catch (...) {
} }
} }
......
...@@ -25,7 +25,7 @@ void bar() { ...@@ -25,7 +25,7 @@ void bar() {
void dumpExceptions(const char* prefix) { void dumpExceptions(const char* prefix) {
std::cerr << "--- " << prefix << "\n"; std::cerr << "--- " << prefix << "\n";
auto exceptions = exception_tracer::getCurrentExceptions(); auto exceptions = ::folly::exception_tracer::getCurrentExceptions();
for (auto& exc : exceptions) { for (auto& exc : exceptions) {
std::cerr << exc << "\n"; std::cerr << exc << "\n";
} }
......
...@@ -38,7 +38,10 @@ ...@@ -38,7 +38,10 @@
#include "folly/Range.h" #include "folly/Range.h"
#include "folly/ScopeGuard.h" #include "folly/ScopeGuard.h"
#include "folly/String.h" #include "folly/String.h"
#include "folly/experimental/io/Stream.h"
#include "folly/experimental/Gen.h"
#include "folly/experimental/FileGen.h"
#include "folly/experimental/StringGen.h"
namespace folly { namespace folly {
...@@ -48,15 +51,23 @@ namespace { ...@@ -48,15 +51,23 @@ namespace {
size_t getDefaultHugePageSize() { size_t getDefaultHugePageSize() {
// We need to parse /proc/meminfo // We need to parse /proc/meminfo
static const boost::regex regex(R"!(Hugepagesize:\s*(\d+)\s*kB)!"); static const boost::regex regex(R"!(Hugepagesize:\s*(\d+)\s*kB)!");
size_t pageSize = 0;
boost::cmatch match; boost::cmatch match;
for (auto& byteLine : byLine("/proc/meminfo")) {
StringPiece line(byteLine); bool error = gen::byLine("/proc/meminfo") | gen::eachAs<StringPiece>() |
[&] (StringPiece line) -> bool {
if (boost::regex_match(line.begin(), line.end(), match, regex)) { if (boost::regex_match(line.begin(), line.end(), match, regex)) {
StringPiece numStr(line.begin() + match.position(1), match.length(1)); StringPiece numStr(line.begin() + match.position(1), match.length(1));
return to<size_t>(numStr) * 1024; // in KiB pageSize = to<size_t>(numStr) * 1024; // in KiB
} return false; // stop
} }
return true;
};
if (error) {
throw std::runtime_error("Can't find default huge page size"); throw std::runtime_error("Can't find default huge page size");
}
return pageSize;
} }
// Get raw huge page sizes (without mount points, they'll be filled later) // Get raw huge page sizes (without mount points, they'll be filled later)
...@@ -124,8 +135,9 @@ HugePageSizeVec getHugePageSizes() { ...@@ -124,8 +135,9 @@ HugePageSizeVec getHugePageSizes() {
// Read and parse /proc/mounts // Read and parse /proc/mounts
std::vector<StringPiece> parts; std::vector<StringPiece> parts;
std::vector<StringPiece> options; std::vector<StringPiece> options;
for (auto& byteLine : byLine("/proc/mounts")) {
StringPiece line(byteLine); gen::byLine("/proc/mounts") | gen::eachAs<StringPiece>() |
[&](StringPiece line) {
parts.clear(); parts.clear();
split(" ", line, parts); split(" ", line, parts);
// device path fstype options uid gid // device path fstype options uid gid
...@@ -133,7 +145,7 @@ HugePageSizeVec getHugePageSizes() { ...@@ -133,7 +145,7 @@ HugePageSizeVec getHugePageSizes() {
throw std::runtime_error("Invalid /proc/mounts line"); throw std::runtime_error("Invalid /proc/mounts line");
} }
if (parts[2] != "hugetlbfs") { if (parts[2] != "hugetlbfs") {
continue; // we only care about hugetlbfs return; // we only care about hugetlbfs
} }
options.clear(); options.clear();
...@@ -164,7 +176,7 @@ HugePageSizeVec getHugePageSizes() { ...@@ -164,7 +176,7 @@ HugePageSizeVec getHugePageSizes() {
pos->mountPoint = fs::canonical(fs::path(parts[1].begin(), pos->mountPoint = fs::canonical(fs::path(parts[1].begin(),
parts[1].end())); parts[1].end()));
} }
} };
return sizeVec; return sizeVec;
} }
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include <dwarf.h> #include <dwarf.h>
namespace facebook { namespace folly {
namespace symbolizer { namespace symbolizer {
Dwarf::Dwarf(const ElfFile* elf) : elf_(elf) { Dwarf::Dwarf(const ElfFile* elf) : elf_(elf) {
...@@ -815,5 +815,5 @@ bool Dwarf::LineNumberVM::findAddress(uintptr_t target, Path& file, ...@@ -815,5 +815,5 @@ bool Dwarf::LineNumberVM::findAddress(uintptr_t target, Path& file,
} }
} // namespace symbolizer } // namespace symbolizer
} // namespace facebook } // namespace folly
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "folly/experimental/symbolizer/Elf.h" #include "folly/experimental/symbolizer/Elf.h"
#include "folly/Range.h" #include "folly/Range.h"
namespace facebook { namespace folly {
namespace symbolizer { namespace symbolizer {
/** /**
...@@ -270,7 +270,7 @@ inline std::ostream& operator<<(std::ostream& out, const Dwarf::Path& path) { ...@@ -270,7 +270,7 @@ inline std::ostream& operator<<(std::ostream& out, const Dwarf::Path& path) {
} }
} // namespace symbolizer } // namespace symbolizer
} // namespace facebook } // namespace folly
#endif /* FOLLY_EXPERIMENTAL_SYMBOLIZER_DWARF_H_ */ #endif /* FOLLY_EXPERIMENTAL_SYMBOLIZER_DWARF_H_ */
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
# error This file must be included from Elf.h # error This file must be included from Elf.h
#endif #endif
namespace facebook { namespace folly {
namespace symbolizer { namespace symbolizer {
template <class Fn> template <class Fn>
...@@ -61,5 +61,5 @@ const char* ElfFile::iterateStrings(const ElfW(Shdr)& stringTable, Fn fn) ...@@ -61,5 +61,5 @@ const char* ElfFile::iterateStrings(const ElfW(Shdr)& stringTable, Fn fn)
} // namespace symbolizer } // namespace symbolizer
} // namespace facebook } // namespace folly
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "folly/Conv.h" #include "folly/Conv.h"
namespace facebook { namespace folly {
namespace symbolizer { namespace symbolizer {
ElfFile::ElfFile() ElfFile::ElfFile()
...@@ -287,5 +287,5 @@ const char* ElfFile::getSymbolName(Symbol symbol) const { ...@@ -287,5 +287,5 @@ const char* ElfFile::getSymbolName(Symbol symbol) const {
} }
} // namespace symbolizer } // namespace symbolizer
} // namespace facebook } // namespace folly
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include "folly/Range.h" #include "folly/Range.h"
#include "folly/Conv.h" #include "folly/Conv.h"
namespace facebook { namespace folly {
namespace symbolizer { namespace symbolizer {
/** /**
...@@ -151,7 +151,7 @@ inline void enforce(bool v, Args... args) { ...@@ -151,7 +151,7 @@ inline void enforce(bool v, Args... args) {
} }
} // namespace symbolizer } // namespace symbolizer
} // namespace facebook } // namespace folly
#include "folly/experimental/symbolizer/Elf-inl.h" #include "folly/experimental/symbolizer/Elf-inl.h"
......
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
#include <gflags/gflags.h> #include <gflags/gflags.h>
#include <glog/logging.h> #include <glog/logging.h>
using namespace facebook; using namespace folly;
using namespace facebook::symbolizer; using namespace folly::symbolizer;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
google::ParseCommandLineFlags(&argc, &argv, true); google::ParseCommandLineFlags(&argc, &argv, true);
......
...@@ -18,26 +18,28 @@ ...@@ -18,26 +18,28 @@
#include "folly/experimental/symbolizer/Symbolizer.h" #include "folly/experimental/symbolizer/Symbolizer.h"
#include <boost/regex.hpp> #include <boost/regex.hpp>
#include <glog/logging.h>
#include "folly/experimental/symbolizer/Elf.h" #include "folly/experimental/symbolizer/Elf.h"
#include "folly/experimental/symbolizer/Dwarf.h" #include "folly/experimental/symbolizer/Dwarf.h"
#include "glog/logging.h"
#include "folly/Range.h" #include "folly/Range.h"
#include "folly/FBString.h" #include "folly/FBString.h"
#include "folly/String.h" #include "folly/String.h"
#include "folly/experimental/io/Stream.h" #include "folly/experimental/Gen.h"
#include "folly/experimental/FileGen.h"
#include "folly/experimental/StringGen.h"
namespace facebook { namespace folly {
namespace symbolizer { namespace symbolizer {
namespace { namespace {
folly::StringPiece sp(const boost::csub_match& m) { StringPiece sp(const boost::csub_match& m) {
return folly::StringPiece(m.first, m.second); return StringPiece(m.first, m.second);
} }
uint64_t fromHex(folly::StringPiece s) { uint64_t fromHex(StringPiece s) {
// Make a copy; we need a null-terminated string for strtoull // Make a copy; we need a null-terminated string for strtoull
folly::fbstring str(s.data(), s.size()); fbstring str(s.data(), s.size());
const char* p = str.c_str(); const char* p = str.c_str();
char* end; char* end;
uint64_t val = strtoull(p, &end, 16); uint64_t val = strtoull(p, &end, 16);
...@@ -53,7 +55,7 @@ struct MappedFile { ...@@ -53,7 +55,7 @@ struct MappedFile {
} // namespace } // namespace
bool Symbolizer::symbolize(uintptr_t address, folly::StringPiece& symbolName, bool Symbolizer::symbolize(uintptr_t address, StringPiece& symbolName,
Dwarf::LocationInfo& location) { Dwarf::LocationInfo& location) {
symbolName.clear(); symbolName.clear();
location = Dwarf::LocationInfo(); location = Dwarf::LocationInfo();
...@@ -75,27 +77,27 @@ bool Symbolizer::symbolize(uintptr_t address, folly::StringPiece& symbolName, ...@@ -75,27 +77,27 @@ bool Symbolizer::symbolize(uintptr_t address, folly::StringPiece& symbolName,
boost::cmatch match; boost::cmatch match;
MappedFile foundFile; MappedFile foundFile;
bool found = false; bool error = gen::byLine("/proc/self/maps") | gen::eachAs<StringPiece>() |
for (auto& byteLine : folly::byLine("/proc/self/maps")) { [&] (StringPiece line) -> bool {
folly::StringPiece line(byteLine);
CHECK(boost::regex_match(line.begin(), line.end(), match, mapLineRegex)); CHECK(boost::regex_match(line.begin(), line.end(), match, mapLineRegex));
uint64_t begin = fromHex(sp(match[1])); uint64_t begin = fromHex(sp(match[1]));
uint64_t end = fromHex(sp(match[2])); uint64_t end = fromHex(sp(match[2]));
uint64_t fileOffset = fromHex(sp(match[3])); uint64_t fileOffset = fromHex(sp(match[3]));
if (fileOffset != 0) { if (fileOffset != 0) {
continue; // main mapping starts at 0 return true; // main mapping starts at 0
} }
if (begin <= address && address < end) { if (begin <= address && address < end) {
found = true;
foundFile.begin = begin; foundFile.begin = begin;
foundFile.end = end; foundFile.end = end;
foundFile.name.assign(match[4].first, match[4].second); foundFile.name.assign(match[4].first, match[4].second);
break; return false;
}
} }
if (!found) { return true;
};
if (error) {
return false; return false;
} }
...@@ -128,14 +130,14 @@ ElfFile& Symbolizer::getFile(const std::string& name) { ...@@ -128,14 +130,14 @@ ElfFile& Symbolizer::getFile(const std::string& name) {
} }
void Symbolizer::write(std::ostream& out, uintptr_t address, void Symbolizer::write(std::ostream& out, uintptr_t address,
folly::StringPiece symbolName, StringPiece symbolName,
const Dwarf::LocationInfo& location) { const Dwarf::LocationInfo& location) {
char buf[20]; char buf[20];
sprintf(buf, "%#18jx", address); sprintf(buf, "%#18jx", address);
out << " @ " << buf; out << " @ " << buf;
if (!symbolName.empty()) { if (!symbolName.empty()) {
out << " " << folly::demangle(symbolName.toString().c_str()); out << " " << demangle(symbolName.toString().c_str());
std::string file; std::string file;
if (location.hasFileAndLine) { if (location.hasFileAndLine) {
...@@ -158,4 +160,4 @@ void Symbolizer::write(std::ostream& out, uintptr_t address, ...@@ -158,4 +160,4 @@ void Symbolizer::write(std::ostream& out, uintptr_t address,
} }
} // namespace symbolizer } // namespace symbolizer
} // namespace facebook } // namespace folly
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "folly/experimental/symbolizer/Elf.h" #include "folly/experimental/symbolizer/Elf.h"
#include "folly/experimental/symbolizer/Dwarf.h" #include "folly/experimental/symbolizer/Dwarf.h"
namespace facebook { namespace folly {
namespace symbolizer { namespace symbolizer {
/** /**
...@@ -55,7 +55,7 @@ class Symbolizer { ...@@ -55,7 +55,7 @@ class Symbolizer {
}; };
} // namespace symbolizer } // namespace symbolizer
} // namespace facebook } // namespace folly
#endif /* FOLLY_EXPERIMENTAL_SYMBOLIZER_SYMBOLIZER_H_ */ #endif /* FOLLY_EXPERIMENTAL_SYMBOLIZER_SYMBOLIZER_H_ */
...@@ -18,16 +18,15 @@ ...@@ -18,16 +18,15 @@
#include "folly/experimental/symbolizer/Symbolizer.h" #include "folly/experimental/symbolizer/Symbolizer.h"
#include "common/init/Init.h" #include <glog/logging.h>
#include "glog/logging.h"
using namespace facebook; using namespace folly;
using namespace facebook::symbolizer; using namespace folly::symbolizer;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
facebook::initFacebook(&argc, &argv); google::InitGoogleLogging(argv[0]);
Symbolizer s; Symbolizer s;
folly::StringPiece name; StringPiece name;
Dwarf::LocationInfo location; Dwarf::LocationInfo location;
CHECK(s.symbolize(reinterpret_cast<uintptr_t>(main), name, location)); CHECK(s.symbolize(reinterpret_cast<uintptr_t>(main), name, location));
LOG(INFO) << name << " " << location.file << " " << location.line << " (" LOG(INFO) << name << " " << location.file << " " << location.line << " ("
......
...@@ -619,7 +619,7 @@ TEST(StringGen, EmptySplit) { ...@@ -619,7 +619,7 @@ TEST(StringGen, EmptySplit) {
{ {
auto pieces = split(",,", ',') | take(1) | collect; auto pieces = split(",,", ',') | take(1) | collect;
EXPECT_EQ(1, pieces.size()); EXPECT_EQ(1, pieces.size());
EXPECT_EQ("", pieces[1]); EXPECT_EQ("", pieces[0]);
} }
} }
......
...@@ -20,7 +20,9 @@ ...@@ -20,7 +20,9 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "folly/Format.h" #include "folly/Format.h"
#include "folly/experimental/io/Stream.h" #include "folly/experimental/Gen.h"
#include "folly/experimental/FileGen.h"
#include "folly/experimental/StringGen.h"
using namespace folly; using namespace folly;
...@@ -57,12 +59,12 @@ TEST(SimpleSubprocessTest, ShellExitsWithError) { ...@@ -57,12 +59,12 @@ TEST(SimpleSubprocessTest, ShellExitsWithError) {
TEST(PopenSubprocessTest, PopenRead) { TEST(PopenSubprocessTest, PopenRead) {
Subprocess proc("ls /", Subprocess::pipeStdout()); Subprocess proc("ls /", Subprocess::pipeStdout());
int found = 0; int found = 0;
for (auto bline : byLine(proc.stdout())) { gen::byLine(proc.stdout()) | gen::eachAs<StringPiece>() |
StringPiece line(bline); [&] (StringPiece line) {
if (line == "etc" || line == "bin" || line == "usr") { if (line == "etc" || line == "bin" || line == "usr") {
++found; ++found;
} }
} };
EXPECT_EQ(3, found); EXPECT_EQ(3, found);
proc.waitChecked(); proc.waitChecked();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment