DCmdConfigure.java 9.5 KB
Newer Older
A
apetushkov 已提交
1
/*
2
 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
A
apetushkov 已提交
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
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

package jdk.jfr.internal.dcmd;



30
import jdk.jfr.FlightRecorder;
A
apetushkov 已提交
31 32 33 34
import jdk.jfr.internal.LogLevel;
import jdk.jfr.internal.LogTag;
import jdk.jfr.internal.Logger;
import jdk.jfr.internal.Options;
35
import jdk.jfr.internal.PlatformRecorder;
36
import jdk.jfr.internal.PrivateAccess;
A
apetushkov 已提交
37 38 39 40 41 42 43 44 45 46 47 48
import jdk.jfr.internal.Repository;
import jdk.jfr.internal.SecuritySupport.SafePath;

/**
 * JFR.configure - invoked from native
 *
 */
//Instantiated by native
final class DCmdConfigure extends AbstractDCmd {
    /**
     * Execute JFR.configure.
     *
49
     * @param onVMStart if cmd is invoked at the moment when vm is started
A
apetushkov 已提交
50 51 52 53 54 55 56 57
     * @param repositoryPath the path
     * @param dumpPath path to dump to on fatal error (oom)
     * @param stackDepth depth of stack traces
     * @param globalBufferCount number of global buffers
     * @param globalBufferSize size of global buffers
     * @param threadBufferSize size of thread buffer for events
     * @param maxChunkSize threshold at which a new chunk is created in the disk repository
     * @param sampleThreads if thread sampling should be enabled
58 59
     * @param sampleObjectAllocations if object allocations sampling should be enbaled
     * @param objectAllocationsSamplingInterval interval of object allocations samplings
A
apetushkov 已提交
60 61 62 63 64 65 66 67
     *
     * @return result

     * @throws DCmdException
     *             if the dump could not be completed
     */
    public String execute
    (
68
            Boolean onVMStart,
A
apetushkov 已提交
69 70 71 72 73 74 75 76
            String repositoryPath,
            String dumpPath,
            Integer stackDepth,
            Long globalBufferCount,
            Long globalBufferSize,
            Long threadBufferSize,
            Long memorySize,
            Long maxChunkSize,
77 78 79
            Boolean sampleThreads,
            Boolean sampleObjectAllocations,
            Long objectAllocationsSamplingInterval
A
apetushkov 已提交
80
    ) throws DCmdException {
81
        if (Logger.shouldLog(LogTag.JFR_DCMD, LogLevel.DEBUG)) {
A
apetushkov 已提交
82 83 84 85 86 87 88 89 90 91 92
            Logger.log(LogTag.JFR_DCMD, LogLevel.DEBUG, "Executing DCmdConfigure: repositorypath=" + repositoryPath +
                    ", dumppath=" + dumpPath +
                    ", stackdepth=" + stackDepth +
                    ", globalbuffercount=" + globalBufferCount +
                    ", globalbuffersize=" + globalBufferSize +
                    ", thread_buffer_size" + threadBufferSize +
                    ", memorysize" + memorySize +
                    ", maxchunksize=" + maxChunkSize +
                    ", samplethreads" + sampleThreads);
        }

93 94 95 96 97 98 99
        // Check parameters correctness
        if (!onVMStart) {
            if (sampleObjectAllocations != null || objectAllocationsSamplingInterval != null) {
                Logger.log(LogTag.JFR, LogLevel.ERROR, "Could not change sampleObjectAllocations and objectAllocationsSamplingInterval during application's running");
                return getResult();
            }
        }
A
apetushkov 已提交
100 101 102 103 104

        boolean updated = false;
        if (repositoryPath != null) {
            try {
                SafePath s = new SafePath(repositoryPath);
105
                if (FlightRecorder.isInitialized()) {
106 107 108
                    PrivateAccess.getInstance().getPlatformRecorder().migrate(s);
                } else {
                    Repository.getRepository().setBasePath(s);
109
                }
110
                Logger.log(LogTag.JFR, LogLevel.INFO, "Base repository path set to " + repositoryPath);
A
apetushkov 已提交
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
            } catch (Exception e) {
                throw new DCmdException("Could not use " + repositoryPath + " as repository. " + e.getMessage(), e);
            }
            printRepositoryPath();
            updated = true;
        }

        if (dumpPath != null)  {
            Options.setDumpPath(new SafePath(dumpPath));
            Logger.log(LogTag.JFR, LogLevel.INFO, "Emergency dump path set to " + dumpPath);
            printDumpPath();
            updated = true;
        }

        if (stackDepth != null)  {
            Options.setStackDepth(stackDepth);
            Logger.log(LogTag.JFR, LogLevel.INFO, "Stack depth set to " + stackDepth);
            printStackDepth();
            updated = true;
        }

        if (globalBufferCount != null)  {
            Options.setGlobalBufferCount(globalBufferCount);
            Logger.log(LogTag.JFR, LogLevel.INFO, "Global buffer count set to " + globalBufferCount);
            printGlobalBufferCount();
            updated = true;
        }

        if (globalBufferSize != null)  {
            Options.setGlobalBufferSize(globalBufferSize);
            Logger.log(LogTag.JFR, LogLevel.INFO, "Global buffer size set to " + globalBufferSize);
            printGlobalBufferSize();
            updated = true;
        }

        if (threadBufferSize != null)  {
            Options.setThreadBufferSize(threadBufferSize);
            Logger.log(LogTag.JFR, LogLevel.INFO, "Thread buffer size set to " + threadBufferSize);
            printThreadBufferSize();
            updated = true;
        }

        if (memorySize != null) {
            Options.setMemorySize(memorySize);
            Logger.log(LogTag.JFR, LogLevel.INFO, "Memory size set to " + memorySize);
            printMemorySize();
            updated = true;
        }

        if (maxChunkSize != null)  {
            Options.setMaxChunkSize(maxChunkSize);
            Logger.log(LogTag.JFR, LogLevel.INFO, "Max chunk size set to " + maxChunkSize);
            printMaxChunkSize();
            updated = true;
        }

        if (sampleThreads != null)  {
            Options.setSampleThreads(sampleThreads);
            Logger.log(LogTag.JFR, LogLevel.INFO, "Sample threads set to " + sampleThreads);
            printSampleThreads();
            updated = true;
        }

174 175 176 177 178 179 180 181 182 183 184 185 186 187
        if (objectAllocationsSamplingInterval != null) {
            Options.setObjectAllocationsSamplingInterval(objectAllocationsSamplingInterval);
            Logger.log(LogTag.JFR, LogLevel.INFO, "object allocations sampling interval set to " + objectAllocationsSamplingInterval);
            printObjectAllocationsSamplingInterval();
            updated = true;
        }

        if (sampleObjectAllocations != null) {
            Options.setSampleObjectAllocations(sampleObjectAllocations); 
            Logger.log(LogTag.JFR, LogLevel.INFO, "Sample object allocations set to " + sampleObjectAllocations);
            printSampleObjectAllocations();
            updated = true;
        }

A
apetushkov 已提交
188 189 190 191 192 193 194 195 196 197 198
        if (!updated) {
            println("Current configuration:");
            println();
            printRepositoryPath();
            printStackDepth();
            printGlobalBufferCount();
            printGlobalBufferSize();
            printThreadBufferSize();
            printMemorySize();
            printMaxChunkSize();
            printSampleThreads();
199 200
            printSampleObjectAllocations();
            printObjectAllocationsSamplingInterval();
A
apetushkov 已提交
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
        }
        return getResult();
    }

    private void printRepositoryPath() {
        print("Repository path: ");
        printPath(Repository.getRepository().getRepositoryPath());
        println();
    }

    private void printDumpPath() {
        print("Dump path: ");
        printPath(Options.getDumpPath());
        println();
    }

    private void printSampleThreads() {
        println("Sample threads: " + Options.getSampleThreads());
    }

    private void printStackDepth() {
        println("Stack depth: " +  Options.getStackDepth());
    }

    private void printGlobalBufferCount() {
        println("Global buffer count: " +  Options.getGlobalBufferCount());
    }

    private void printGlobalBufferSize() {
        print("Global buffer size: ");
231
        printBytes(Options.getGlobalBufferSize());
A
apetushkov 已提交
232 233 234 235 236
        println();
    }

    private void printThreadBufferSize() {
        print("Thread buffer size: ");
237
        printBytes(Options.getThreadBufferSize());
A
apetushkov 已提交
238 239 240 241 242
        println();
    }

    private void printMemorySize() {
        print("Memory size: ");
243
        printBytes(Options.getMemorySize());
A
apetushkov 已提交
244 245 246 247 248
        println();
    }

    private void printMaxChunkSize() {
        print("Max chunk size: ");
249
        printBytes(Options.getMaxChunkSize());
A
apetushkov 已提交
250 251
        println();
    }
252 253 254 255 256 257 258 259

    private void printSampleObjectAllocations() {
        println("Sample object allocations: " + Options.getSampleObjectAllocations());
    }

    private void printObjectAllocationsSamplingInterval() {
        println("objects allocations sampling interval: " + Options.getObjectAllocationsSamplingInterval());
    }
A
apetushkov 已提交
260
}