src/hotspot/os/aix/os_perf_aix.cpp
author mikael
Thu, 21 Feb 2019 16:56:06 -0800
changeset 53882 ca682d9d8db5
parent 51106 f605c91e5219
child 54470 14986fb09d9a
permissions -rw-r--r--
8214777: Avoid some GCC 8.X strncpy() errors in HotSpot Reviewed-by: kbarrett, rehn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50160
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
     1
/*
53882
ca682d9d8db5 8214777: Avoid some GCC 8.X strncpy() errors in HotSpot
mikael
parents: 51106
diff changeset
     2
 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
50160
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
     4
 *
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
     8
 *
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    13
 * accompanied this code).
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    14
 *
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    18
 *
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    21
 * questions.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    22
 *
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    23
 */
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    24
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    25
#include "precompiled.hpp"
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    26
#include "jvm.h"
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    27
#include "memory/allocation.inline.hpp"
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    28
#include "os_aix.inline.hpp"
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    29
#include "runtime/os.hpp"
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    30
#include "runtime/os_perf.hpp"
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    31
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    32
#include CPU_HEADER(vm_version_ext)
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    33
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    34
#include <stdio.h>
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    35
#include <stdarg.h>
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    36
#include <unistd.h>
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    37
#include <errno.h>
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    38
#include <string.h>
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    39
#include <sys/resource.h>
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    40
#include <sys/types.h>
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    41
#include <sys/stat.h>
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    42
#include <dirent.h>
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    43
#include <stdlib.h>
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    44
#include <dlfcn.h>
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    45
#include <pthread.h>
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    46
#include <limits.h>
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    47
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    48
/**
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    49
   /proc/[number]/stat
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    50
              Status information about the process.  This is used by ps(1).  It is defined in /usr/src/linux/fs/proc/array.c.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    51
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    52
              The fields, in order, with their proper scanf(3) format specifiers, are:
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    53
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    54
              1. pid %d The process id.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    55
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    56
              2. comm %s
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    57
                     The filename of the executable, in parentheses.  This is visible whether or not the executable is swapped out.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    58
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    59
              3. state %c
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    60
                     One  character  from  the  string "RSDZTW" where R is running, S is sleeping in an interruptible wait, D is waiting in uninterruptible disk
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    61
                     sleep, Z is zombie, T is traced or stopped (on a signal), and W is paging.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    62
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    63
              4. ppid %d
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    64
                     The PID of the parent.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    65
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    66
              5. pgrp %d
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    67
                     The process group ID of the process.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    68
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    69
              6. session %d
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    70
                     The session ID of the process.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    71
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    72
              7. tty_nr %d
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    73
                     The tty the process uses.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    74
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    75
              8. tpgid %d
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    76
                     The process group ID of the process which currently owns the tty that the process is connected to.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    77
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    78
              9. flags %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    79
                     The flags of the process.  The math bit is decimal 4, and the traced bit is decimal 10.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    80
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    81
              10. minflt %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    82
                     The number of minor faults the process has made which have not required loading a memory page from disk.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    83
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    84
              11. cminflt %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    85
                     The number of minor faults that the process's waited-for children have made.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    86
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    87
              12. majflt %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    88
                     The number of major faults the process has made which have required loading a memory page from disk.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    89
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    90
              13. cmajflt %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    91
                     The number of major faults that the process's waited-for children have made.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    92
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    93
              14. utime %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    94
                     The number of jiffies that this process has been scheduled in user mode.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    95
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    96
              15. stime %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    97
                     The number of jiffies that this process has been scheduled in kernel mode.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    98
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
    99
              16. cutime %ld
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   100
                     The number of jiffies that this process's waited-for children have been scheduled in user mode. (See also times(2).)
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   101
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   102
              17. cstime %ld
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   103
                     The number of jiffies that this process' waited-for children have been scheduled in kernel mode.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   104
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   105
              18. priority %ld
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   106
                     The standard nice value, plus fifteen.  The value is never negative in the kernel.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   107
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   108
              19. nice %ld
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   109
                     The nice value ranges from 19 (nicest) to -19 (not nice to others).
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   110
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   111
              20. 0 %ld  This value is hard coded to 0 as a placeholder for a removed field.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   112
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   113
              21. itrealvalue %ld
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   114
                     The time in jiffies before the next SIGALRM is sent to the process due to an interval timer.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   115
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   116
              22. starttime %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   117
                     The time in jiffies the process started after system boot.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   118
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   119
              23. vsize %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   120
                     Virtual memory size in bytes.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   121
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   122
              24. rss %ld
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   123
                     Resident Set Size: number of pages the process has in real memory, minus 3 for administrative purposes. This is just the pages which  count
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   124
                     towards text, data, or stack space.  This does not include pages which have not been demand-loaded in, or which are swapped out.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   125
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   126
              25. rlim %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   127
                     Current limit in bytes on the rss of the process (usually 4294967295 on i386).
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   128
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   129
              26. startcode %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   130
                     The address above which program text can run.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   131
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   132
              27. endcode %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   133
                     The address below which program text can run.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   134
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   135
              28. startstack %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   136
                     The address of the start of the stack.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   137
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   138
              29. kstkesp %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   139
                     The current value of esp (stack pointer), as found in the kernel stack page for the process.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   140
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   141
              30. kstkeip %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   142
                     The current EIP (instruction pointer).
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   143
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   144
              31. signal %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   145
                     The bitmap of pending signals (usually 0).
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   146
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   147
              32. blocked %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   148
                     The bitmap of blocked signals (usually 0, 2 for shells).
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   149
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   150
              33. sigignore %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   151
                     The bitmap of ignored signals.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   152
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   153
              34. sigcatch %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   154
                     The bitmap of catched signals.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   155
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   156
              35. wchan %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   157
                     This  is the "channel" in which the process is waiting.  It is the address of a system call, and can be looked up in a namelist if you need
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   158
                     a textual name.  (If you have an up-to-date /etc/psdatabase, then try ps -l to see the WCHAN field in action.)
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   159
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   160
              36. nswap %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   161
                     Number of pages swapped - not maintained.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   162
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   163
              37. cnswap %lu
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   164
                     Cumulative nswap for child processes.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   165
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   166
              38. exit_signal %d
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   167
                     Signal to be sent to parent when we die.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   168
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   169
              39. processor %d
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   170
                     CPU number last executed on.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   171
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   172
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   173
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   174
 ///// SSCANF FORMAT STRING. Copy and use.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   175
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   176
field:        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
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   177
format:       %d %s %c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld %lu %lu %ld %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %d %d
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   178
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   179
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   180
*/
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   181
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   182
/**
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   183
 * For platforms that have them, when declaring
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   184
 * a printf-style function,
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   185
 *   formatSpec is the parameter number (starting at 1)
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   186
 *       that is the format argument ("%d pid %s")
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   187
 *   params is the parameter number where the actual args to
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   188
 *       the format starts. If the args are in a va_list, this
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   189
 *       should be 0.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   190
 */
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   191
#ifndef PRINTF_ARGS
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   192
#  define PRINTF_ARGS(formatSpec,  params) ATTRIBUTE_PRINTF(formatSpec, params)
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   193
#endif
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   194
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   195
#ifndef SCANF_ARGS
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   196
#  define SCANF_ARGS(formatSpec,   params) ATTRIBUTE_SCANF(formatSpec, params)
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   197
#endif
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   198
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   199
#ifndef _PRINTFMT_
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   200
#  define _PRINTFMT_
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   201
#endif
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   202
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   203
#ifndef _SCANFMT_
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   204
#  define _SCANFMT_
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   205
#endif
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   206
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   207
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   208
struct CPUPerfTicks {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   209
  uint64_t  used;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   210
  uint64_t  usedKernel;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   211
  uint64_t  total;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   212
};
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   213
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   214
typedef enum {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   215
  CPU_LOAD_VM_ONLY,
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   216
  CPU_LOAD_GLOBAL,
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   217
} CpuLoadTarget;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   218
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   219
enum {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   220
  UNDETECTED,
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   221
  UNDETECTABLE,
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   222
  LINUX26_NPTL,
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   223
  BAREMETAL
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   224
};
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   225
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   226
struct CPUPerfCounters {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   227
  int   nProcs;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   228
  CPUPerfTicks jvmTicks;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   229
  CPUPerfTicks* cpus;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   230
};
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   231
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   232
static double get_cpu_load(int which_logical_cpu, CPUPerfCounters* counters, double* pkernelLoad, CpuLoadTarget target);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   233
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   234
/** reads /proc/<pid>/stat data, with some checks and some skips.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   235
 *  Ensure that 'fmt' does _NOT_ contain the first two "%d %s"
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   236
 */
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   237
static int SCANF_ARGS(2, 0) vread_statdata(const char* procfile, _SCANFMT_ const char* fmt, va_list args) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   238
  FILE*f;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   239
  int n;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   240
  char buf[2048];
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   241
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   242
  if ((f = fopen(procfile, "r")) == NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   243
    return -1;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   244
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   245
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   246
  if ((n = fread(buf, 1, sizeof(buf), f)) != -1) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   247
    char *tmp;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   248
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   249
    buf[n-1] = '\0';
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   250
    /** skip through pid and exec name. */
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   251
    if ((tmp = strrchr(buf, ')')) != NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   252
      // skip the ')' and the following space
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   253
      // but check that buffer is long enough
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   254
      tmp += 2;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   255
      if (tmp < buf + n) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   256
        n = vsscanf(tmp, fmt, args);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   257
      }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   258
    }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   259
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   260
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   261
  fclose(f);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   262
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   263
  return n;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   264
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   265
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   266
static int SCANF_ARGS(2, 3) read_statdata(const char* procfile, _SCANFMT_ const char* fmt, ...) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   267
  int   n;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   268
  va_list args;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   269
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   270
  va_start(args, fmt);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   271
  n = vread_statdata(procfile, fmt, args);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   272
  va_end(args);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   273
  return n;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   274
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   275
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   276
static FILE* open_statfile(void) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   277
  FILE *f;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   278
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   279
  if ((f = fopen("/proc/stat", "r")) == NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   280
    static int haveWarned = 0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   281
    if (!haveWarned) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   282
      haveWarned = 1;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   283
    }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   284
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   285
  return f;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   286
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   287
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   288
static void
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   289
next_line(FILE *f) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   290
  int c;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   291
  do {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   292
    c = fgetc(f);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   293
  } while (c != '\n' && c != EOF);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   294
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   295
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   296
/**
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   297
 * Return the total number of ticks since the system was booted.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   298
 * If the usedTicks parameter is not NULL, it will be filled with
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   299
 * the number of ticks spent on actual processes (user, system or
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   300
 * nice processes) since system boot. Note that this is the total number
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   301
 * of "executed" ticks on _all_ CPU:s, that is on a n-way system it is
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   302
 * n times the number of ticks that has passed in clock time.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   303
 *
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   304
 * Returns a negative value if the reading of the ticks failed.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   305
 */
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   306
static OSReturn get_total_ticks(int which_logical_cpu, CPUPerfTicks* pticks) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   307
  FILE*         fh;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   308
  uint64_t      userTicks, niceTicks, systemTicks, idleTicks;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   309
  uint64_t      iowTicks = 0, irqTicks = 0, sirqTicks= 0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   310
  int           logical_cpu = -1;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   311
  const int     expected_assign_count = (-1 == which_logical_cpu) ? 4 : 5;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   312
  int           n;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   313
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   314
  if ((fh = open_statfile()) == NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   315
    return OS_ERR;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   316
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   317
  if (-1 == which_logical_cpu) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   318
    n = fscanf(fh, "cpu " UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " "
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   319
            UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT,
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   320
            &userTicks, &niceTicks, &systemTicks, &idleTicks,
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   321
            &iowTicks, &irqTicks, &sirqTicks);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   322
  } else {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   323
    // Move to next line
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   324
    next_line(fh);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   325
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   326
    // find the line for requested cpu faster to just iterate linefeeds?
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   327
    for (int i = 0; i < which_logical_cpu; i++) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   328
      next_line(fh);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   329
    }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   330
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   331
    n = fscanf(fh, "cpu%u " UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " "
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   332
               UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT,
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   333
               &logical_cpu, &userTicks, &niceTicks,
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   334
               &systemTicks, &idleTicks, &iowTicks, &irqTicks, &sirqTicks);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   335
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   336
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   337
  fclose(fh);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   338
  if (n < expected_assign_count || logical_cpu != which_logical_cpu) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   339
#ifdef DEBUG_LINUX_PROC_STAT
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   340
    vm_fprintf(stderr, "[stat] read failed");
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   341
#endif
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   342
    return OS_ERR;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   343
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   344
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   345
#ifdef DEBUG_LINUX_PROC_STAT
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   346
  vm_fprintf(stderr, "[stat] read "
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   347
          UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " "
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   348
          UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " \n",
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   349
          userTicks, niceTicks, systemTicks, idleTicks,
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   350
          iowTicks, irqTicks, sirqTicks);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   351
#endif
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   352
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   353
  pticks->used       = userTicks + niceTicks;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   354
  pticks->usedKernel = systemTicks + irqTicks + sirqTicks;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   355
  pticks->total      = userTicks + niceTicks + systemTicks + idleTicks +
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   356
                       iowTicks + irqTicks + sirqTicks;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   357
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   358
  return OS_OK;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   359
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   360
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   361
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   362
static int get_systemtype(void) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   363
  static int procEntriesType = UNDETECTED;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   364
  DIR *taskDir;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   365
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   366
  if (procEntriesType != UNDETECTED) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   367
    return procEntriesType;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   368
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   369
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   370
  // Check whether we have a task subdirectory
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   371
  if ((taskDir = opendir("/proc/self/task")) == NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   372
    procEntriesType = UNDETECTABLE;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   373
  } else {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   374
    // The task subdirectory exists; we're on a Linux >= 2.6 system
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   375
    closedir(taskDir);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   376
    procEntriesType = LINUX26_NPTL;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   377
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   378
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   379
  return procEntriesType;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   380
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   381
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   382
/** read user and system ticks from a named procfile, assumed to be in 'stat' format then. */
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   383
static int read_ticks(const char* procfile, uint64_t* userTicks, uint64_t* systemTicks) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   384
  return read_statdata(procfile, "%*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u " UINT64_FORMAT " " UINT64_FORMAT,
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   385
    userTicks, systemTicks);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   386
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   387
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   388
/**
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   389
 * Return the number of ticks spent in any of the processes belonging
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   390
 * to the JVM on any CPU.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   391
 */
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   392
static OSReturn get_jvm_ticks(CPUPerfTicks* pticks) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   393
  uint64_t userTicks;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   394
  uint64_t systemTicks;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   395
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   396
  if (get_systemtype() != LINUX26_NPTL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   397
    return OS_ERR;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   398
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   399
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   400
  if (read_ticks("/proc/self/stat", &userTicks, &systemTicks) != 2) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   401
    return OS_ERR;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   402
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   403
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   404
  // get the total
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   405
  if (get_total_ticks(-1, pticks) != OS_OK) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   406
    return OS_ERR;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   407
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   408
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   409
  pticks->used       = userTicks;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   410
  pticks->usedKernel = systemTicks;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   411
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   412
  return OS_OK;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   413
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   414
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   415
/**
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   416
 * Return the load of the CPU as a double. 1.0 means the CPU process uses all
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   417
 * available time for user or system processes, 0.0 means the CPU uses all time
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   418
 * being idle.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   419
 *
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   420
 * Returns a negative value if there is a problem in determining the CPU load.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   421
 */
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   422
static double get_cpu_load(int which_logical_cpu, CPUPerfCounters* counters, double* pkernelLoad, CpuLoadTarget target) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   423
  uint64_t udiff, kdiff, tdiff;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   424
  CPUPerfTicks* pticks;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   425
  CPUPerfTicks  tmp;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   426
  double user_load;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   427
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   428
  *pkernelLoad = 0.0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   429
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   430
  if (target == CPU_LOAD_VM_ONLY) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   431
    pticks = &counters->jvmTicks;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   432
  } else if (-1 == which_logical_cpu) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   433
    pticks = &counters->cpus[counters->nProcs];
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   434
  } else {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   435
    pticks = &counters->cpus[which_logical_cpu];
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   436
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   437
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   438
  tmp = *pticks;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   439
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   440
  if (target == CPU_LOAD_VM_ONLY) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   441
    if (get_jvm_ticks(pticks) != OS_OK) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   442
      return -1.0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   443
    }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   444
  } else if (get_total_ticks(which_logical_cpu, pticks) != OS_OK) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   445
    return -1.0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   446
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   447
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   448
  // seems like we sometimes end up with less kernel ticks when
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   449
  // reading /proc/self/stat a second time, timing issue between cpus?
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   450
  if (pticks->usedKernel < tmp.usedKernel) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   451
    kdiff = 0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   452
  } else {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   453
    kdiff = pticks->usedKernel - tmp.usedKernel;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   454
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   455
  tdiff = pticks->total - tmp.total;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   456
  udiff = pticks->used - tmp.used;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   457
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   458
  if (tdiff == 0) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   459
    return 0.0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   460
  } else if (tdiff < (udiff + kdiff)) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   461
    tdiff = udiff + kdiff;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   462
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   463
  *pkernelLoad = (kdiff / (double)tdiff);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   464
  // BUG9044876, normalize return values to sane values
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   465
  *pkernelLoad = MAX2<double>(*pkernelLoad, 0.0);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   466
  *pkernelLoad = MIN2<double>(*pkernelLoad, 1.0);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   467
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   468
  user_load = (udiff / (double)tdiff);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   469
  user_load = MAX2<double>(user_load, 0.0);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   470
  user_load = MIN2<double>(user_load, 1.0);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   471
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   472
  return user_load;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   473
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   474
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   475
static int SCANF_ARGS(1, 2) parse_stat(_SCANFMT_ const char* fmt, ...) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   476
  FILE *f;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   477
  va_list args;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   478
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   479
  va_start(args, fmt);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   480
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   481
  if ((f = open_statfile()) == NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   482
    va_end(args);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   483
    return OS_ERR;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   484
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   485
  for (;;) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   486
    char line[80];
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   487
    if (fgets(line, sizeof(line), f) != NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   488
      if (vsscanf(line, fmt, args) == 1) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   489
        fclose(f);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   490
        va_end(args);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   491
        return OS_OK;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   492
      }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   493
    } else {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   494
        fclose(f);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   495
        va_end(args);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   496
        return OS_ERR;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   497
    }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   498
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   499
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   500
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   501
static int get_noof_context_switches(uint64_t* switches) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   502
  return parse_stat("ctxt " UINT64_FORMAT "\n", switches);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   503
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   504
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   505
/** returns boot time in _seconds_ since epoch */
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   506
static int get_boot_time(uint64_t* time) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   507
  return parse_stat("btime " UINT64_FORMAT "\n", time);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   508
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   509
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   510
static int perf_context_switch_rate(double* rate) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   511
  static pthread_mutex_t contextSwitchLock = PTHREAD_MUTEX_INITIALIZER;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   512
  static uint64_t      lastTime;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   513
  static uint64_t      lastSwitches;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   514
  static double        lastRate;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   515
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   516
  uint64_t lt = 0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   517
  int res = 0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   518
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   519
  if (lastTime == 0) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   520
    uint64_t tmp;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   521
    if (get_boot_time(&tmp) < 0) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   522
      return OS_ERR;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   523
    }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   524
    lt = tmp * 1000;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   525
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   526
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   527
  res = OS_OK;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   528
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   529
  pthread_mutex_lock(&contextSwitchLock);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   530
  {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   531
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   532
    uint64_t sw;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   533
    s8 t, d;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   534
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   535
    if (lastTime == 0) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   536
      lastTime = lt;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   537
    }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   538
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   539
    t = os::javaTimeMillis();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   540
    d = t - lastTime;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   541
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   542
    if (d == 0) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   543
      *rate = lastRate;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   544
    } else if (!get_noof_context_switches(&sw)) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   545
      *rate      = ( (double)(sw - lastSwitches) / d ) * 1000;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   546
      lastRate     = *rate;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   547
      lastSwitches = sw;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   548
      lastTime     = t;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   549
    } else {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   550
      *rate = 0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   551
      res   = OS_ERR;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   552
    }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   553
    if (*rate <= 0) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   554
      *rate = 0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   555
      lastRate = 0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   556
    }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   557
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   558
  pthread_mutex_unlock(&contextSwitchLock);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   559
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   560
  return res;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   561
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   562
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   563
class CPUPerformanceInterface::CPUPerformance : public CHeapObj<mtInternal> {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   564
  friend class CPUPerformanceInterface;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   565
 private:
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   566
  CPUPerfCounters _counters;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   567
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   568
  int cpu_load(int which_logical_cpu, double* cpu_load);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   569
  int context_switch_rate(double* rate);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   570
  int cpu_load_total_process(double* cpu_load);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   571
  int cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   572
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   573
 public:
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   574
  CPUPerformance();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   575
  bool initialize();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   576
  ~CPUPerformance();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   577
};
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   578
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   579
CPUPerformanceInterface::CPUPerformance::CPUPerformance() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   580
  _counters.nProcs = os::active_processor_count();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   581
  _counters.cpus = NULL;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   582
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   583
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   584
bool CPUPerformanceInterface::CPUPerformance::initialize() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   585
  size_t tick_array_size = (_counters.nProcs +1) * sizeof(CPUPerfTicks);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   586
  _counters.cpus = (CPUPerfTicks*)NEW_C_HEAP_ARRAY(char, tick_array_size, mtInternal);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   587
  if (NULL == _counters.cpus) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   588
    return false;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   589
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   590
  memset(_counters.cpus, 0, tick_array_size);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   591
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   592
  // For the CPU load total
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   593
  get_total_ticks(-1, &_counters.cpus[_counters.nProcs]);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   594
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   595
  // For each CPU
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   596
  for (int i = 0; i < _counters.nProcs; i++) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   597
    get_total_ticks(i, &_counters.cpus[i]);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   598
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   599
  // For JVM load
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   600
  get_jvm_ticks(&_counters.jvmTicks);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   601
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   602
  // initialize context switch system
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   603
  // the double is only for init
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   604
  double init_ctx_switch_rate;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   605
  perf_context_switch_rate(&init_ctx_switch_rate);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   606
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   607
  return true;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   608
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   609
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   610
CPUPerformanceInterface::CPUPerformance::~CPUPerformance() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   611
  if (_counters.cpus != NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   612
    FREE_C_HEAP_ARRAY(char, _counters.cpus);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   613
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   614
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   615
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   616
int CPUPerformanceInterface::CPUPerformance::cpu_load(int which_logical_cpu, double* cpu_load) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   617
  double u, s;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   618
  u = get_cpu_load(which_logical_cpu, &_counters, &s, CPU_LOAD_GLOBAL);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   619
  if (u < 0) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   620
    *cpu_load = 0.0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   621
    return OS_ERR;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   622
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   623
  // Cap total systemload to 1.0
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   624
  *cpu_load = MIN2<double>((u + s), 1.0);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   625
  return OS_OK;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   626
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   627
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   628
int CPUPerformanceInterface::CPUPerformance::cpu_load_total_process(double* cpu_load) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   629
  double u, s;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   630
  u = get_cpu_load(-1, &_counters, &s, CPU_LOAD_VM_ONLY);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   631
  if (u < 0) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   632
    *cpu_load = 0.0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   633
    return OS_ERR;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   634
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   635
  *cpu_load = u + s;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   636
  return OS_OK;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   637
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   638
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   639
int CPUPerformanceInterface::CPUPerformance::cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   640
  double u, s, t;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   641
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   642
  assert(pjvmUserLoad != NULL, "pjvmUserLoad not inited");
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   643
  assert(pjvmKernelLoad != NULL, "pjvmKernelLoad not inited");
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   644
  assert(psystemTotalLoad != NULL, "psystemTotalLoad not inited");
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   645
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   646
  u = get_cpu_load(-1, &_counters, &s, CPU_LOAD_VM_ONLY);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   647
  if (u < 0) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   648
    *pjvmUserLoad = 0.0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   649
    *pjvmKernelLoad = 0.0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   650
    *psystemTotalLoad = 0.0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   651
    return OS_ERR;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   652
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   653
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   654
  cpu_load(-1, &t);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   655
  // clamp at user+system and 1.0
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   656
  if (u + s > t) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   657
    t = MIN2<double>(u + s, 1.0);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   658
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   659
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   660
  *pjvmUserLoad = u;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   661
  *pjvmKernelLoad = s;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   662
  *psystemTotalLoad = t;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   663
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   664
  return OS_OK;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   665
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   666
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   667
int CPUPerformanceInterface::CPUPerformance::context_switch_rate(double* rate) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   668
  return perf_context_switch_rate(rate);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   669
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   670
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   671
CPUPerformanceInterface::CPUPerformanceInterface() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   672
  _impl = NULL;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   673
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   674
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   675
bool CPUPerformanceInterface::initialize() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   676
  _impl = new CPUPerformanceInterface::CPUPerformance();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   677
  return NULL == _impl ? false : _impl->initialize();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   678
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   679
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   680
CPUPerformanceInterface::~CPUPerformanceInterface() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   681
  if (_impl != NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   682
    delete _impl;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   683
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   684
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   685
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   686
int CPUPerformanceInterface::cpu_load(int which_logical_cpu, double* cpu_load) const {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   687
  return _impl->cpu_load(which_logical_cpu, cpu_load);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   688
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   689
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   690
int CPUPerformanceInterface::cpu_load_total_process(double* cpu_load) const {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   691
  return _impl->cpu_load_total_process(cpu_load);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   692
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   693
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   694
int CPUPerformanceInterface::cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad) const {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   695
  return _impl->cpu_loads_process(pjvmUserLoad, pjvmKernelLoad, psystemTotalLoad);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   696
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   697
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   698
int CPUPerformanceInterface::context_switch_rate(double* rate) const {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   699
  return _impl->context_switch_rate(rate);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   700
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   701
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   702
class SystemProcessInterface::SystemProcesses : public CHeapObj<mtInternal> {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   703
  friend class SystemProcessInterface;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   704
 private:
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   705
  class ProcessIterator : public CHeapObj<mtInternal> {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   706
    friend class SystemProcessInterface::SystemProcesses;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   707
   private:
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   708
    DIR*           _dir;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   709
    struct dirent* _entry;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   710
    bool           _valid;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   711
    char           _exeName[PATH_MAX];
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   712
    char           _exePath[PATH_MAX];
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   713
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   714
    ProcessIterator();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   715
    ~ProcessIterator();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   716
    bool initialize();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   717
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   718
    bool is_valid() const { return _valid; }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   719
    bool is_valid_entry(struct dirent* entry) const;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   720
    bool is_dir(const char* name) const;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   721
    int  fsize(const char* name, uint64_t& size) const;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   722
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   723
    char* allocate_string(const char* str) const;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   724
    void  get_exe_name();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   725
    char* get_exe_path();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   726
    char* get_cmdline();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   727
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   728
    int current(SystemProcess* process_info);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   729
    int next_process();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   730
  };
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   731
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   732
  ProcessIterator* _iterator;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   733
  SystemProcesses();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   734
  bool initialize();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   735
  ~SystemProcesses();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   736
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   737
  //information about system processes
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   738
  int system_processes(SystemProcess** system_processes, int* no_of_sys_processes) const;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   739
};
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   740
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   741
bool SystemProcessInterface::SystemProcesses::ProcessIterator::is_dir(const char* name) const {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   742
  struct stat mystat;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   743
  int ret_val = 0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   744
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   745
  ret_val = stat(name, &mystat);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   746
  if (ret_val < 0) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   747
    return false;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   748
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   749
  ret_val = S_ISDIR(mystat.st_mode);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   750
  return ret_val > 0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   751
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   752
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   753
int SystemProcessInterface::SystemProcesses::ProcessIterator::fsize(const char* name, uint64_t& size) const {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   754
  assert(name != NULL, "name pointer is NULL!");
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   755
  size = 0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   756
  struct stat fbuf;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   757
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   758
  if (stat(name, &fbuf) < 0) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   759
    return OS_ERR;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   760
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   761
  size = fbuf.st_size;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   762
  return OS_OK;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   763
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   764
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   765
// if it has a numeric name, is a directory and has a 'stat' file in it
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   766
bool SystemProcessInterface::SystemProcesses::ProcessIterator::is_valid_entry(struct dirent* entry) const {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   767
  char buffer[PATH_MAX];
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   768
  uint64_t size = 0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   769
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   770
  if (atoi(entry->d_name) != 0) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   771
    jio_snprintf(buffer, PATH_MAX, "/proc/%s", entry->d_name);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   772
    buffer[PATH_MAX - 1] = '\0';
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   773
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   774
    if (is_dir(buffer)) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   775
      jio_snprintf(buffer, PATH_MAX, "/proc/%s/stat", entry->d_name);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   776
      buffer[PATH_MAX - 1] = '\0';
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   777
      if (fsize(buffer, size) != OS_ERR) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   778
        return true;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   779
      }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   780
    }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   781
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   782
  return false;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   783
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   784
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   785
// get exe-name from /proc/<pid>/stat
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   786
void SystemProcessInterface::SystemProcesses::ProcessIterator::get_exe_name() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   787
  FILE* fp;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   788
  char  buffer[PATH_MAX];
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   789
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   790
  jio_snprintf(buffer, PATH_MAX, "/proc/%s/stat", _entry->d_name);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   791
  buffer[PATH_MAX - 1] = '\0';
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   792
  if ((fp = fopen(buffer, "r")) != NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   793
    if (fgets(buffer, PATH_MAX, fp) != NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   794
      char* start, *end;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   795
      // exe-name is between the first pair of ( and )
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   796
      start = strchr(buffer, '(');
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   797
      if (start != NULL && start[1] != '\0') {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   798
        start++;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   799
        end = strrchr(start, ')');
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   800
        if (end != NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   801
          size_t len;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   802
          len = MIN2<size_t>(end - start, sizeof(_exeName) - 1);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   803
          memcpy(_exeName, start, len);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   804
          _exeName[len] = '\0';
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   805
        }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   806
      }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   807
    }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   808
    fclose(fp);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   809
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   810
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   811
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   812
// get command line from /proc/<pid>/cmdline
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   813
char* SystemProcessInterface::SystemProcesses::ProcessIterator::get_cmdline() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   814
  FILE* fp;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   815
  char  buffer[PATH_MAX];
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   816
  char* cmdline = NULL;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   817
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   818
  jio_snprintf(buffer, PATH_MAX, "/proc/%s/cmdline", _entry->d_name);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   819
  buffer[PATH_MAX - 1] = '\0';
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   820
  if ((fp = fopen(buffer, "r")) != NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   821
    size_t size = 0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   822
    char   dummy;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   823
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   824
    // find out how long the file is (stat always returns 0)
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   825
    while (fread(&dummy, 1, 1, fp) == 1) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   826
      size++;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   827
    }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   828
    if (size > 0) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   829
      cmdline = NEW_C_HEAP_ARRAY(char, size + 1, mtInternal);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   830
      if (cmdline != NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   831
        cmdline[0] = '\0';
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   832
        if (fseek(fp, 0, SEEK_SET) == 0) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   833
          if (fread(cmdline, 1, size, fp) == size) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   834
            // the file has the arguments separated by '\0',
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   835
            // so we translate '\0' to ' '
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   836
            for (size_t i = 0; i < size; i++) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   837
              if (cmdline[i] == '\0') {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   838
                cmdline[i] = ' ';
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   839
              }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   840
            }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   841
            cmdline[size] = '\0';
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   842
          }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   843
        }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   844
      }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   845
    }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   846
    fclose(fp);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   847
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   848
  return cmdline;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   849
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   850
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   851
// get full path to exe from /proc/<pid>/exe symlink
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   852
char* SystemProcessInterface::SystemProcesses::ProcessIterator::get_exe_path() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   853
  char buffer[PATH_MAX];
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   854
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   855
  jio_snprintf(buffer, PATH_MAX, "/proc/%s/exe", _entry->d_name);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   856
  buffer[PATH_MAX - 1] = '\0';
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   857
  return realpath(buffer, _exePath);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   858
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   859
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   860
char* SystemProcessInterface::SystemProcesses::ProcessIterator::allocate_string(const char* str) const {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   861
  if (str != NULL) {
53882
ca682d9d8db5 8214777: Avoid some GCC 8.X strncpy() errors in HotSpot
mikael
parents: 51106
diff changeset
   862
    return os::strdup_check_oom(str, mtInternal);
50160
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   863
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   864
  return NULL;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   865
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   866
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   867
int SystemProcessInterface::SystemProcesses::ProcessIterator::current(SystemProcess* process_info) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   868
  if (!is_valid()) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   869
    return OS_ERR;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   870
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   871
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   872
  process_info->set_pid(atoi(_entry->d_name));
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   873
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   874
  get_exe_name();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   875
  process_info->set_name(allocate_string(_exeName));
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   876
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   877
  if (get_exe_path() != NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   878
     process_info->set_path(allocate_string(_exePath));
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   879
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   880
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   881
  char* cmdline = NULL;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   882
  cmdline = get_cmdline();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   883
  if (cmdline != NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   884
    process_info->set_command_line(allocate_string(cmdline));
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   885
    FREE_C_HEAP_ARRAY(char, cmdline);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   886
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   887
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   888
  return OS_OK;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   889
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   890
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   891
int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   892
  if (!is_valid()) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   893
    return OS_ERR;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   894
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   895
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   896
  do {
51106
f605c91e5219 8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents: 50879
diff changeset
   897
    _entry = os::readdir(_dir);
50160
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   898
    if (_entry == NULL) {
51106
f605c91e5219 8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents: 50879
diff changeset
   899
      // Error or reached end.  Could use errno to distinguish those cases.
50160
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   900
      _valid = false;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   901
      return OS_ERR;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   902
    }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   903
  } while(!is_valid_entry(_entry));
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   904
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   905
  _valid = true;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   906
  return OS_OK;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   907
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   908
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   909
SystemProcessInterface::SystemProcesses::ProcessIterator::ProcessIterator() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   910
  _dir = NULL;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   911
  _entry = NULL;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   912
  _valid = false;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   913
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   914
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   915
bool SystemProcessInterface::SystemProcesses::ProcessIterator::initialize() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   916
  // Not yet implemented.
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   917
  return false;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   918
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   919
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   920
SystemProcessInterface::SystemProcesses::ProcessIterator::~ProcessIterator() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   921
  if (_dir != NULL) {
51106
f605c91e5219 8202353: os::readdir should use readdir instead of readdir_r
kbarrett
parents: 50879
diff changeset
   922
    os::closedir(_dir);
50160
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   923
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   924
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   925
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   926
SystemProcessInterface::SystemProcesses::SystemProcesses() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   927
  _iterator = NULL;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   928
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   929
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   930
bool SystemProcessInterface::SystemProcesses::initialize() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   931
  _iterator = new SystemProcessInterface::SystemProcesses::ProcessIterator();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   932
  return NULL == _iterator ? false : _iterator->initialize();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   933
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   934
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   935
SystemProcessInterface::SystemProcesses::~SystemProcesses() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   936
  if (_iterator != NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   937
    delete _iterator;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   938
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   939
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   940
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   941
int SystemProcessInterface::SystemProcesses::system_processes(SystemProcess** system_processes, int* no_of_sys_processes) const {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   942
  assert(system_processes != NULL, "system_processes pointer is NULL!");
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   943
  assert(no_of_sys_processes != NULL, "system_processes counter pointers is NULL!");
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   944
  assert(_iterator != NULL, "iterator is NULL!");
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   945
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   946
  // initialize pointers
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   947
  *no_of_sys_processes = 0;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   948
  *system_processes = NULL;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   949
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   950
  while (_iterator->is_valid()) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   951
    SystemProcess* tmp = new SystemProcess();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   952
    _iterator->current(tmp);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   953
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   954
    //if already existing head
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   955
    if (*system_processes != NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   956
      //move "first to second"
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   957
      tmp->set_next(*system_processes);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   958
    }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   959
    // new head
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   960
    *system_processes = tmp;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   961
    // increment
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   962
    (*no_of_sys_processes)++;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   963
    // step forward
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   964
    _iterator->next_process();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   965
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   966
  return OS_OK;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   967
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   968
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   969
int SystemProcessInterface::system_processes(SystemProcess** system_procs, int* no_of_sys_processes) const {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   970
  return _impl->system_processes(system_procs, no_of_sys_processes);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   971
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   972
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   973
SystemProcessInterface::SystemProcessInterface() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   974
  _impl = NULL;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   975
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   976
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   977
bool SystemProcessInterface::initialize() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   978
  _impl = new SystemProcessInterface::SystemProcesses();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   979
  return NULL == _impl ? false : _impl->initialize();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   980
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   981
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   982
SystemProcessInterface::~SystemProcessInterface() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   983
  if (_impl != NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   984
    delete _impl;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   985
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   986
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   987
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   988
CPUInformationInterface::CPUInformationInterface() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   989
  _cpu_info = NULL;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   990
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   991
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   992
bool CPUInformationInterface::initialize() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   993
  _cpu_info = new CPUInformation();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   994
  if (NULL == _cpu_info) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   995
    return false;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   996
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   997
  _cpu_info->set_number_of_hardware_threads(VM_Version_Ext::number_of_threads());
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   998
  _cpu_info->set_number_of_cores(VM_Version_Ext::number_of_cores());
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
   999
  _cpu_info->set_number_of_sockets(VM_Version_Ext::number_of_sockets());
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1000
  _cpu_info->set_cpu_name(VM_Version_Ext::cpu_name());
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1001
  _cpu_info->set_cpu_description(VM_Version_Ext::cpu_description());
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1002
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1003
  return true;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1004
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1005
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1006
CPUInformationInterface::~CPUInformationInterface() {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1007
  if (_cpu_info != NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1008
    if (_cpu_info->cpu_name() != NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1009
      const char* cpu_name = _cpu_info->cpu_name();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1010
      FREE_C_HEAP_ARRAY(char, cpu_name);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1011
      _cpu_info->set_cpu_name(NULL);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1012
    }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1013
    if (_cpu_info->cpu_description() != NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1014
       const char* cpu_desc = _cpu_info->cpu_description();
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1015
       FREE_C_HEAP_ARRAY(char, cpu_desc);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1016
      _cpu_info->set_cpu_description(NULL);
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1017
    }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1018
    delete _cpu_info;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1019
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1020
}
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1021
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1022
int CPUInformationInterface::cpu_information(CPUInformation& cpu_info) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1023
  if (_cpu_info == NULL) {
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1024
    return OS_ERR;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1025
  }
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1026
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1027
  cpu_info = *_cpu_info; // shallow copy assignment
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1028
  return OS_OK;
dc18db671651 8203288: PPC64 and s390 fail to build after JDK-8199712 (Flight Recorder)
mdoerr
parents:
diff changeset
  1029
}
50879
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1030
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1031
class NetworkPerformanceInterface::NetworkPerformance : public CHeapObj<mtInternal> {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1032
  friend class NetworkPerformanceInterface;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1033
 private:
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1034
  NetworkPerformance();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1035
  NetworkPerformance(const NetworkPerformance& rhs); // no impl
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1036
  NetworkPerformance& operator=(const NetworkPerformance& rhs); // no impl
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1037
  bool initialize();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1038
  ~NetworkPerformance();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1039
  int network_utilization(NetworkInterface** network_interfaces) const;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1040
};
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1041
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1042
NetworkPerformanceInterface::NetworkPerformance::NetworkPerformance() {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1043
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1044
}
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1045
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1046
bool NetworkPerformanceInterface::NetworkPerformance::initialize() {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1047
  return true;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1048
}
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1049
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1050
NetworkPerformanceInterface::NetworkPerformance::~NetworkPerformance() {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1051
}
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1052
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1053
int NetworkPerformanceInterface::NetworkPerformance::network_utilization(NetworkInterface** network_interfaces) const
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1054
{
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1055
  return FUNCTIONALITY_NOT_IMPLEMENTED;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1056
}
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1057
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1058
NetworkPerformanceInterface::NetworkPerformanceInterface() {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1059
  _impl = NULL;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1060
}
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1061
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1062
NetworkPerformanceInterface::~NetworkPerformanceInterface() {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1063
  if (_impl != NULL) {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1064
    delete _impl;
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1065
  }
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1066
}
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1067
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1068
bool NetworkPerformanceInterface::initialize() {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1069
  _impl = new NetworkPerformanceInterface::NetworkPerformance();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1070
  return _impl != NULL && _impl->initialize();
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1071
}
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1072
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1073
int NetworkPerformanceInterface::network_utilization(NetworkInterface** network_interfaces) const {
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1074
  return _impl->network_utilization(network_interfaces);
d90c3cbf13df 8003209: JFR events for network utilization
rwestberg
parents: 50160
diff changeset
  1075
}