Class DiagnosticUtil


  • public class DiagnosticUtil
    extends java.lang.Object
    • Field Detail

      • FILE_DATE_FORMAT

        public static final java.lang.String FILE_DATE_FORMAT
        See Also:
        Constant Field Values
      • THREAD_DUMP_PREFIX

        public static final java.lang.String THREAD_DUMP_PREFIX
        See Also:
        Constant Field Values
      • THREAD_DUMP_EXTENSION

        public static final java.lang.String THREAD_DUMP_EXTENSION
        See Also:
        Constant Field Values
      • TC_TOTAL_MEMORY_USAGE_KEY

        public static final java.lang.String TC_TOTAL_MEMORY_USAGE_KEY
        See Also:
        Constant Field Values
      • THREAD_DUMP_DATE_PATTERN

        public static final java.lang.String THREAD_DUMP_DATE_PATTERN
        See Also:
        Constant Field Values
    • Constructor Detail

      • DiagnosticUtil

        public DiagnosticUtil()
    • Method Detail

      • threadDumpToStream

        public static void threadDumpToStream​(@NotNull
                                              java.io.PrintStream out)
        Shouldn't be used for streaming thread dump to log. All thread dumps should be saved to a separate file in the log directory. To be used in web request and tests only
        Parameters:
        out - stream to write dump to
        See Also:
        threadDumpToDirectory(File, ThreadDumpData)
      • threadDumpToStream

        public static void threadDumpToStream​(@NotNull
                                              java.io.PrintWriter out)
        Shouldn't be used for streaming thread dump to log. All thread dumps should be saved to a separate file in the log directory. To be used in web request and tests only
        Parameters:
        out - writer to write dump to
        See Also:
        threadDumpToDirectory(File, ThreadDumpData)
      • threadDumpToStream

        public static void threadDumpToStream​(@NotNull
                                              java.io.PrintWriter out,
                                              @NotNull
                                              DiagnosticUtil.ThreadDumpData threadDumpData)
      • threadDumpToDirectory

        public static java.io.File threadDumpToDirectory​(@Nullable
                                                         java.io.File dir,
                                                         @Nullable
                                                         java.lang.String suffix,
                                                         @NotNull
                                                         DiagnosticUtil.ThreadDumpData data)
      • threadDumpToDirectory

        public static java.io.File threadDumpToDirectory​(@Nullable
                                                         java.io.File dir,
                                                         @NotNull
                                                         DiagnosticUtil.ThreadDumpData data)
      • writeThreadDump

        public static java.io.File writeThreadDump​(@NotNull
                                                   java.io.File baseDir,
                                                   @NotNull
                                                   java.lang.String threadDump)
      • getAutomaticThreadDumpsSubdirectory

        public static java.io.File getAutomaticThreadDumpsSubdirectory​(@NotNull
                                                                       java.io.File baseDir)
                                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • getDiagnosticFile

        public static java.io.File getDiagnosticFile​(@Nullable
                                                     java.io.File baseDir,
                                                     @NotNull
                                                     java.lang.String suffix,
                                                     @NotNull
                                                     java.lang.String ext)
      • threadDumpToString

        @NotNull
        public static java.lang.String threadDumpToString()
        Shouldn't be used for streaming thread dump to log. All thread dumps should be saved to a separate file in the log directory. To be used in tests only
        Returns:
        thread dump
      • threadDumpToString

        @NotNull
        public static java.lang.String threadDumpToString​(@NotNull
                                                          DiagnosticUtil.ThreadDumpData data)
        Shouldn't be used for streaming thread dump to log. All thread dumps should be saved to a separate file in the log directory. To be used in request and tests only. Is also used in SQL exception handling.
        Parameters:
        data - thread dump data
        Returns:
        thread dump
      • getHeapMemoryUsage

        @NotNull
        public static java.lang.management.MemoryUsage getHeapMemoryUsage()
      • getPermGenPoolMemoryUsage

        @Nullable
        public static java.lang.management.MemoryUsage getPermGenPoolMemoryUsage()
      • isPermGenPool

        public static boolean isPermGenPool​(java.lang.String name)
      • getMemoryUsageBeans

        public static java.util.List<java.lang.management.MemoryPoolMXBean> getMemoryUsageBeans()
      • getMaxPoolSize

        public static long getMaxPoolSize​(java.lang.String key)
      • appendCurrentThreadStacktrace

        @NotNull
        public static java.lang.StringBuilder appendCurrentThreadStacktrace​(@NotNull
                                                                            java.lang.StringBuilder sb)
      • getThreadDumpDateFormat

        public static java.text.SimpleDateFormat getThreadDumpDateFormat()
      • memoryDumpAvailable

        public static boolean memoryDumpAvailable()
        Returns:
        true iff JVM supports memory dump capture
        Since:
        8.0
      • memoryDump

        @NotNull
        public static java.io.File memoryDump​(@Nullable
                                              java.io.File hprofDir)
                                       throws java.lang.Exception
        Deprecated.
        Takes JVM memory dump
        Parameters:
        hprofDir - directory to write dump. It's required ~ 2*heap-size of free space
        Returns:
        path to saved .hprof
        Throws:
        java.lang.Exception - on error or if memory dump is not supported
        Since:
        8.0
      • memoryDump

        @NotNull
        public static java.io.File memoryDump​(@Nullable
                                              java.io.File dir,
                                              boolean zip,
                                              @NotNull
                                              java.lang.String requestorData,
                                              @NotNull
                                              com.intellij.openapi.diagnostic.Logger logger)
                                       throws java.lang.Exception
        Takes hprof and logs the result into the passed logger
        Parameters:
        dir - path to write file. If zip is used, it's required ~ 2*heap-size of free space
        zip - to archived dump or leave as it is
        requestorData - text describing why the dump is created to be used in the logging
        logger - logger to log success/failure messages to
        Returns:
        path to created dump file
        Throws:
        java.lang.Exception - on error or if memory dump is not supported
        Since:
        2019.2.1
      • memoryDumpZipped

        @NotNull
        public static java.io.File memoryDumpZipped​(@Nullable
                                                    java.io.File dir)
                                             throws java.lang.Exception
        Deprecated.
        Takes hprof and than zips it
        Parameters:
        dir - path to write file. It's required ~ 2*heap-size of free space
        Returns:
        path to created dump file
        Throws:
        java.lang.Exception - on error or if memory dump is not supported
        Since:
        8.0
      • getJVMArgs

        @NotNull
        public static java.util.List<java.lang.String> getJVMArgs()
      • getJVMArgsString

        @NotNull
        public static java.lang.String getJVMArgsString()
      • getUser

        public static java.lang.String getUser()
        Returns:
        Current username
      • getJavaDetails

        public static java.lang.String getJavaDetails()
      • getJVMDiagnosticString

        @NotNull
        public static java.lang.String getJVMDiagnosticString()
        Returns:
        String containing JVM info: version, bitness, vendor
      • getJVMName

        @NotNull
        public static java.lang.String getJVMName()
      • getOsEnvironmentDetails

        @NotNull
        public static java.lang.String getOsEnvironmentDetails()
      • getFriendlyTimeZone

        public static java.lang.String getFriendlyTimeZone()