summaryrefslogtreecommitdiffstats
path: root/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/maintenance/servicedump/PerfReportProducer.java
blob: 1407153f50fe617f91055756e874f02ab42bcae8 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.maintenance.servicedump;

import com.yahoo.vespa.hosted.node.admin.container.ContainerOperations;
import com.yahoo.vespa.hosted.node.admin.nodeagent.NodeAgentContext;
import com.yahoo.vespa.hosted.node.admin.task.util.file.UnixPath;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author bjorncs
 */
class PerfReportProducer extends AbstractProducer {

    public static String NAME = "perf-report";

    PerfReportProducer(ContainerOperations container) { super(container); }

    @Override public String name() { return NAME; }

    @Override
    public void produceArtifact(NodeAgentContext context, String configId, ServiceDumpReport.DumpOptions options,
                                UnixPath resultDirectoryInNode) throws IOException {
        int pid = findVespaServicePid(context, configId);
        int duration = options != null && options.duration() != null && options.duration() > 0
                ? options.duration().intValue() : 30;
        List<String> perfRecordCommand = new ArrayList<>(List.of("perf", "record"));
        if (options != null && Boolean.TRUE.equals(options.callGraphRecording())) {
            perfRecordCommand.add("-g");
        }
        String recordFile = resultDirectoryInNode.resolve("perf-record.bin").toString();
        perfRecordCommand.addAll(
                List.of("--output=" + recordFile,
                        "--pid=" + pid, "sleep", Integer.toString(duration)));
        executeCommand(context, perfRecordCommand, true);
        String perfReportFile = resultDirectoryInNode.resolve("perf-report.txt").toString();
        executeCommand(context, List.of("bash", "-c", "perf report --input=" + recordFile + " > " + perfReportFile), true);
    }
}