#include #include #include #include #include #include #include namespace { std::uint64_t maximumResidentBytes() { rusage usage{}; getrusage(RUSAGE_SELF, &usage); #if defined(__APPLE__) return static_cast(usage.ru_maxrss); #else return static_cast(usage.ru_maxrss) * 1024; #endif } } // namespace int main(int argc, char** argv) { if (argc != 2) { std::cerr << "usage: " << argv[0] << " FILE.avro\n"; return 2; } try { avro::DataFileReader 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; } }