aboutsummaryrefslogtreecommitdiffstats
path: root/metrics-proxy/src/main/java/ai/vespa/metricsproxy/service/CpuJiffies.java
blob: 7efd3a89f77b1d7219e8e1e1b9b07d1a366dc874 (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
40
41
42
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.metricsproxy.service;

class CpuJiffies {

    private int cpuId;
    private long jiffies;

    CpuJiffies(String line) {
        parseLine(line);
    }

    private void parseLine(String line) {
        String elems[];
        String cpuId;
        long jiffies;

        elems = line.split("\\s+");
        cpuId = elems[0].substring(3);
        if (cpuId.length() == 0) {
            this.cpuId = -1;
        } else {
            this.cpuId = Integer.parseInt(cpuId);
        }

        jiffies = 0;
        for (int i = 1; i < elems.length; i++) {
            jiffies += Long.parseLong(elems[i].replaceAll("[\\n\\r]+", ""));
        }

        this.jiffies = jiffies;
    }

    public int getCpuId() {
        return cpuId;
    }

    public long getTotalJiffies() {
        return jiffies;
    }

}