aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/rusage.h
blob: 32f257e7dbd39034ea5f5b618f93646bb5ae8975 (plain) (blame)
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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/vespalib/stllike/string.h>
#include <vespa/vespalib/util/time.h>
#include <sys/resource.h>

namespace vespalib {

class RUsage : private rusage {
public:
    /**
     * Create an rusage with all member set to zero.
     **/
    RUsage();
    /**
     * Will create an RUsage and initialize member with RUSAGE_SELF
     **/
    static RUsage createSelf();
    static RUsage createSelf(vespalib::steady_time since);
    /**
     * Will create an RUsage and initialize member with RUSAGE_CHILDREN
     **/
    static RUsage createChildren();
    static RUsage createChildren(vespalib::steady_time since);
    /**
     * Will create an RUsage and initialize member with RUSAGE_CHILDREN
     **/
    vespalib::string toString();
    RUsage & operator -= (const RUsage & rhs);
private:
    vespalib::duration _time;
};

RUsage operator -(const RUsage & a, const RUsage & b);
timeval operator -(const timeval & a, const timeval & b);

}