/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/resource.h>
#include <dirent.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <pthread.h>
#include "com_sun_management_UnixOperatingSystem.h"
struct ticks {
};
typedef enum {
static struct perfbuf {
int nProcs;
} counters;
while (fgetc(f) != '\n');
}
/**
* Return the total number of ticks since the system was booted.
* If the usedTicks parameter is not NULL, it will be filled with
* the number of ticks spent on actual processes (user, system or
* nice processes) since system boot. Note that this is the total number
* of "executed" ticks on _all_ CPU:s, that is on a n-way system it is
* n times the number of ticks that has passed in clock time.
*
* Returns a negative value if the reading of the ticks failed.
*/
int n;
return -1;
}
// Move to next line
//find the line for requested cpu faster to just iterate linefeeds?
if (which != -1) {
int i;
for (i = 0; i < which; i++) {
if (fscanf(fh, "cpu%*d " DEC_64 " " DEC_64 " " DEC_64 " " DEC_64, &userTicks, &niceTicks, &systemTicks, &idleTicks) != 4) {
return -2;
}
}
}
if (n != 4) {
return -2;
}
return 0;
}
FILE *f;
int n;
return -1;
}
char *tmp;
/** skip through pid and exec name. the exec name _could be wacky_ (renamed) and
* make scanf go mupp.
*/
// skip the ')' and the following space but check that the buffer is long enough
tmp += 2;
}
}
}
fclose(f);
return n;
}
int n;
return n;
}
/** read user and system ticks from a named procfile, assumed to be in 'stat' format then. */
);
}
/**
* Return the number of ticks spent in any of the processes belonging
* to the JVM on any CPU.
*/
return -1;
}
// get the total
return -1;
}
return 0;
}
/**
* This method must be called first, before any data can be gathererd.
*/
int perfInit() {
if (!initialized) {
int i;
int n = sysconf(_SC_NPROCESSORS_ONLN);
if (n <= 0) {
n = 1;
}
// For the CPU load
for (i = 0; i < n; i++) {
}
// For JVM load
initialized = 1;
}
}
return initialized ? 0 : -1;
}
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
/**
* Return the load of the CPU as a double. 1.0 means the CPU process uses all
* available time for user or system processes, 0.0 means the CPU uses all time
* being idle.
*
* Returns a negative value if there is a problem in determining the CPU load.
*/
int failed = 0;
*pkernelLoad = 0.0;
if(perfInit() == 0) {
if (target == CPU_LOAD_VM_ONLY) {
} else if (which == -1) {
} else {
}
if (target == CPU_LOAD_VM_ONLY) {
if (get_jvmticks(pticks) != 0) {
failed = 1;
}
failed = 1;
}
if(!failed) {
// seems like we sometimes end up with less kernel ticks when
kdiff = 0;
} else {
}
if (tdiff == 0) {
user_load = 0;
} else {
}
// BUG9044876, normalize return values to sane values
}
}
}
return user_load;
}
double u, s;
if (u < 0) {
return -1.0;
}
// Cap total systemload to 1.0
return MIN((u + s), 1.0);
}
double get_process_load() {
double u, s;
if (u < 0) {
return -1.0;
}
return u + s;
}
{
if(perfInit() == 0) {
return get_cpu_load(-1);
} else {
return -1.0;
}
}
{
if(perfInit() == 0) {
return get_process_load();
} else {
return -1.0;
}
}