File size: 1,477 Bytes
b99d599
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#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
}

}  // namespace

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;
    }
}