class Gen,
class Handler>
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) {
- gen.self().apply(std::forward<Handler>(handler));
+ return gen.self().apply(std::forward<Handler>(handler));
}
/**
} // namespace
-using namespace ::facebook::symbolizer;
+using namespace ::folly::symbolizer;
using namespace __cxxabiv1;
+namespace folly {
namespace exception_tracer {
std::ostream& operator<<(std::ostream& out, const ExceptionInfo& info) {
}
} // namespace exception_tracer
+} // namespace folly
#include <vector>
#include <iostream>
+namespace folly {
namespace exception_tracer {
struct ExceptionInfo {
void installHandlers();
} // namespace exception_tracer
+} // namespace folly
#endif /* FOLLY_EXPERIMENTAL_EXCEPTION_TRACER_EXCEPTIONTRACER_H_ */
struct Initializer {
Initializer() {
try {
- exception_tracer::installHandlers();
+ ::folly::exception_tracer::installHandlers();
} catch (...) {
}
}
void dumpExceptions(const char* prefix) {
std::cerr << "--- " << prefix << "\n";
- auto exceptions = exception_tracer::getCurrentExceptions();
+ auto exceptions = ::folly::exception_tracer::getCurrentExceptions();
for (auto& exc : exceptions) {
std::cerr << exc << "\n";
}
#include "folly/Range.h"
#include "folly/ScopeGuard.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 {
size_t getDefaultHugePageSize() {
// We need to parse /proc/meminfo
static const boost::regex regex(R"!(Hugepagesize:\s*(\d+)\s*kB)!");
+ size_t pageSize = 0;
boost::cmatch match;
- for (auto& byteLine : byLine("/proc/meminfo")) {
- StringPiece line(byteLine);
- if (boost::regex_match(line.begin(), line.end(), match, regex)) {
- StringPiece numStr(line.begin() + match.position(1), match.length(1));
- return to<size_t>(numStr) * 1024; // in KiB
- }
+
+ bool error = gen::byLine("/proc/meminfo") | gen::eachAs<StringPiece>() |
+ [&] (StringPiece line) -> bool {
+ if (boost::regex_match(line.begin(), line.end(), match, regex)) {
+ StringPiece numStr(line.begin() + match.position(1), match.length(1));
+ 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)
// Read and parse /proc/mounts
std::vector<StringPiece> parts;
std::vector<StringPiece> options;
- for (auto& byteLine : byLine("/proc/mounts")) {
- StringPiece line(byteLine);
- parts.clear();
- split(" ", line, parts);
- // device path fstype options uid gid
- if (parts.size() != 6) {
- throw std::runtime_error("Invalid /proc/mounts line");
- }
- if (parts[2] != "hugetlbfs") {
- continue; // we only care about hugetlbfs
- }
- options.clear();
- split(",", parts[3], options);
- size_t pageSize = defaultHugePageSize;
- // Search for the "pagesize" option, which must have a value
- for (auto& option : options) {
- // key=value
- const char* p = static_cast<const char*>(
- memchr(option.data(), '=', option.size()));
- if (!p) {
- continue;
+ gen::byLine("/proc/mounts") | gen::eachAs<StringPiece>() |
+ [&](StringPiece line) {
+ parts.clear();
+ split(" ", line, parts);
+ // device path fstype options uid gid
+ if (parts.size() != 6) {
+ throw std::runtime_error("Invalid /proc/mounts line");
}
- if (StringPiece(option.data(), p) != "pagesize") {
- continue;
+ if (parts[2] != "hugetlbfs") {
+ return; // we only care about hugetlbfs
}
- pageSize = parsePageSizeValue(StringPiece(p + 1, option.end()));
- break;
- }
- auto pos = std::lower_bound(sizeVec.begin(), sizeVec.end(), pageSize,
- PageSizeLess());
- if (pos == sizeVec.end() || pos->size != pageSize) {
- throw std::runtime_error("Mount page size not found");
- }
- if (pos->mountPoint.empty()) {
- // Store mount point
- pos->mountPoint = fs::canonical(fs::path(parts[1].begin(),
- parts[1].end()));
- }
- }
+ options.clear();
+ split(",", parts[3], options);
+ size_t pageSize = defaultHugePageSize;
+ // Search for the "pagesize" option, which must have a value
+ for (auto& option : options) {
+ // key=value
+ const char* p = static_cast<const char*>(
+ memchr(option.data(), '=', option.size()));
+ if (!p) {
+ continue;
+ }
+ if (StringPiece(option.data(), p) != "pagesize") {
+ continue;
+ }
+ pageSize = parsePageSizeValue(StringPiece(p + 1, option.end()));
+ break;
+ }
+
+ auto pos = std::lower_bound(sizeVec.begin(), sizeVec.end(), pageSize,
+ PageSizeLess());
+ if (pos == sizeVec.end() || pos->size != pageSize) {
+ throw std::runtime_error("Mount page size not found");
+ }
+ if (pos->mountPoint.empty()) {
+ // Store mount point
+ pos->mountPoint = fs::canonical(fs::path(parts[1].begin(),
+ parts[1].end()));
+ }
+ };
return sizeVec;
}
#include <dwarf.h>
-namespace facebook {
+namespace folly {
namespace symbolizer {
Dwarf::Dwarf(const ElfFile* elf) : elf_(elf) {
}
} // namespace symbolizer
-} // namespace facebook
+} // namespace folly
#include "folly/experimental/symbolizer/Elf.h"
#include "folly/Range.h"
-namespace facebook {
+namespace folly {
namespace symbolizer {
/**
}
} // namespace symbolizer
-} // namespace facebook
+} // namespace folly
#endif /* FOLLY_EXPERIMENTAL_SYMBOLIZER_DWARF_H_ */
# error This file must be included from Elf.h
#endif
-namespace facebook {
+namespace folly {
namespace symbolizer {
template <class Fn>
} // namespace symbolizer
-} // namespace facebook
+} // namespace folly
#include "folly/Conv.h"
-namespace facebook {
+namespace folly {
namespace symbolizer {
ElfFile::ElfFile()
}
} // namespace symbolizer
-} // namespace facebook
+} // namespace folly
#include "folly/Range.h"
#include "folly/Conv.h"
-namespace facebook {
+namespace folly {
namespace symbolizer {
/**
}
} // namespace symbolizer
-} // namespace facebook
+} // namespace folly
#include "folly/experimental/symbolizer/Elf-inl.h"
#include <gflags/gflags.h>
#include <glog/logging.h>
-using namespace facebook;
-using namespace facebook::symbolizer;
+using namespace folly;
+using namespace folly::symbolizer;
int main(int argc, char *argv[]) {
google::ParseCommandLineFlags(&argc, &argv, true);
#include "folly/experimental/symbolizer/Symbolizer.h"
#include <boost/regex.hpp>
+#include <glog/logging.h>
#include "folly/experimental/symbolizer/Elf.h"
#include "folly/experimental/symbolizer/Dwarf.h"
-#include "glog/logging.h"
#include "folly/Range.h"
#include "folly/FBString.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 {
-folly::StringPiece sp(const boost::csub_match& m) {
- return folly::StringPiece(m.first, m.second);
+StringPiece sp(const boost::csub_match& m) {
+ 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
- folly::fbstring str(s.data(), s.size());
+ fbstring str(s.data(), s.size());
const char* p = str.c_str();
char* end;
uint64_t val = strtoull(p, &end, 16);
} // namespace
-bool Symbolizer::symbolize(uintptr_t address, folly::StringPiece& symbolName,
+bool Symbolizer::symbolize(uintptr_t address, StringPiece& symbolName,
Dwarf::LocationInfo& location) {
symbolName.clear();
location = Dwarf::LocationInfo();
boost::cmatch match;
MappedFile foundFile;
- bool found = false;
- for (auto& byteLine : folly::byLine("/proc/self/maps")) {
- folly::StringPiece line(byteLine);
- CHECK(boost::regex_match(line.begin(), line.end(), match, mapLineRegex));
- uint64_t begin = fromHex(sp(match[1]));
- uint64_t end = fromHex(sp(match[2]));
- uint64_t fileOffset = fromHex(sp(match[3]));
- if (fileOffset != 0) {
- continue; // main mapping starts at 0
- }
+ bool error = gen::byLine("/proc/self/maps") | gen::eachAs<StringPiece>() |
+ [&] (StringPiece line) -> bool {
+ CHECK(boost::regex_match(line.begin(), line.end(), match, mapLineRegex));
+ uint64_t begin = fromHex(sp(match[1]));
+ uint64_t end = fromHex(sp(match[2]));
+ uint64_t fileOffset = fromHex(sp(match[3]));
+ if (fileOffset != 0) {
+ return true; // main mapping starts at 0
+ }
- if (begin <= address && address < end) {
- found = true;
- foundFile.begin = begin;
- foundFile.end = end;
- foundFile.name.assign(match[4].first, match[4].second);
- break;
- }
- }
+ if (begin <= address && address < end) {
+ foundFile.begin = begin;
+ foundFile.end = end;
+ foundFile.name.assign(match[4].first, match[4].second);
+ return false;
+ }
+
+ return true;
+ };
- if (!found) {
+ if (error) {
return false;
}
}
void Symbolizer::write(std::ostream& out, uintptr_t address,
- folly::StringPiece symbolName,
+ StringPiece symbolName,
const Dwarf::LocationInfo& location) {
char buf[20];
sprintf(buf, "%#18jx", address);
out << " @ " << buf;
if (!symbolName.empty()) {
- out << " " << folly::demangle(symbolName.toString().c_str());
+ out << " " << demangle(symbolName.toString().c_str());
std::string file;
if (location.hasFileAndLine) {
}
} // namespace symbolizer
-} // namespace facebook
+} // namespace folly
#include "folly/experimental/symbolizer/Elf.h"
#include "folly/experimental/symbolizer/Dwarf.h"
-namespace facebook {
+namespace folly {
namespace symbolizer {
/**
};
} // namespace symbolizer
-} // namespace facebook
+} // namespace folly
#endif /* 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 facebook::symbolizer;
+using namespace folly;
+using namespace folly::symbolizer;
int main(int argc, char *argv[]) {
- facebook::initFacebook(&argc, &argv);
+ google::InitGoogleLogging(argv[0]);
Symbolizer s;
- folly::StringPiece name;
+ StringPiece name;
Dwarf::LocationInfo location;
CHECK(s.symbolize(reinterpret_cast<uintptr_t>(main), name, location));
LOG(INFO) << name << " " << location.file << " " << location.line << " ("
{
auto pieces = split(",,", ',') | take(1) | collect;
EXPECT_EQ(1, pieces.size());
- EXPECT_EQ("", pieces[1]);
+ EXPECT_EQ("", pieces[0]);
}
}
#include <gtest/gtest.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;
TEST(PopenSubprocessTest, PopenRead) {
Subprocess proc("ls /", Subprocess::pipeStdout());
int found = 0;
- for (auto bline : byLine(proc.stdout())) {
- StringPiece line(bline);
- if (line == "etc" || line == "bin" || line == "usr") {
- ++found;
- }
- }
+ gen::byLine(proc.stdout()) | gen::eachAs<StringPiece>() |
+ [&] (StringPiece line) {
+ if (line == "etc" || line == "bin" || line == "usr") {
+ ++found;
+ }
+ };
EXPECT_EQ(3, found);
proc.waitChecked();
}