| #include <avro/DataFile.hh> |
| #include <avro/Generic.hh> |
|
|
| #include <cstdint> |
| #include <exception> |
| #include <iostream> |
| #include <string> |
| #include <sys/resource.h> |
|
|
| namespace { |
|
|
| std::uint64_t maximumResidentBytes() { |
| rusage usage{}; |
| getrusage(RUSAGE_SELF, &usage); |
| #if defined(__APPLE__) |
| return static_cast<std::uint64_t>(usage.ru_maxrss); |
| #else |
| return static_cast<std::uint64_t>(usage.ru_maxrss) * 1024; |
| #endif |
| } |
|
|
| } |
|
|
| int main(int argc, char** argv) { |
| if (argc != 2) { |
| std::cerr << "usage: " << argv[0] << " FILE.avro\n"; |
| return 2; |
| } |
|
|
| try { |
| avro::DataFileReader<avro::GenericDatum> reader(argv[1]); |
| avro::GenericDatum datum(reader.readerSchema()); |
| const bool decoded = reader.read(datum); |
| std::cout << "decoded=" << decoded |
| << " max_rss_bytes=" << maximumResidentBytes() << "\n"; |
| return 0; |
| } catch (const std::bad_alloc& error) { |
| std::cerr << "BAD_ALLOC " << error.what() |
| << " max_rss_bytes=" << maximumResidentBytes() << "\n"; |
| return 42; |
| } catch (const std::length_error& error) { |
| std::cerr << "LENGTH_ERROR " << error.what() |
| << " max_rss_bytes=" << maximumResidentBytes() << "\n"; |
| return 43; |
| } catch (const std::exception& error) { |
| std::cerr << "EXCEPTION " << error.what() |
| << " max_rss_bytes=" << maximumResidentBytes() << "\n"; |
| return 44; |
| } |
| } |
|
|