src/windows/native/sun/management/OperatingSystemImpl.c
int
perfInit(void) {
    static HMODULE    h;
    static BOOL        running, inited;

    int error;

    if (running) {
        return CONFIG_SUCCESSFUL;
    }

    error = CONFIG_SUCCESSFUL;

    // this is double checked locking again, but we try to bypass the worst by
    // implicit membar at end of lock.
    EnterCriticalSection(&initializationLock); {
        if (!inited) {
            char         buf[64] = "";
            SYSTEM_INFO si;

            // CMH. But windows will not care about our affinity when giving
            // us measurements. Need the real, raw num cpus.

            GetSystemInfo(&si);
            num_cpus  = si.dwNumberOfProcessors;
            // Initialize the denominator for the jvm load calculations
            cpuFactor = num_cpus * 100;

            /**
             * Do this dynamically, so we don't fail to start on systems without pdh.
             */
            if ((h = LoadLibrary("pdh.dll")) == NULL) {
                /* printf("Could not load pdh.dll (%d)", GetLastError()); */
                error = -2;
            } else if (get_functions(h, buf, sizeof(buf)) < 0) {
                FreeLibrary(h);
                h = NULL;
                error = -2;
               /* printf("Failed to init pdh functions: %s.\n", buf); */
            } else {
                if (initProcessorCounters() != 0) {
                    /* printf("Failed to init system load counters.\n"); */
                } else if (initProcLoadCounter() != 0) {
                    /* printf("Failed to init process load counter.\n"); */
                } else if (initProcSystemLoadCounter() != 0) {
                    /* printf("Failed to init process system load counter.\n"); */
                } else {
                    inited = true;
                }
            }
        }
    } LeaveCriticalSection(&initializationLock);

    if (inited && error == CONFIG_SUCCESSFUL) {
        running = true;
    }

    return error;
}
/**
 * Helper to initialize the PDH library. Loads the library and sets up the functions.
 * Note that once loaded, we will never unload the PDH library.
 *
 * @return  CONFIG_SUCCESSFUL if successful, negative on failure.
 */
Helper to initialize the PDH library. Loads the library and sets up the functions.
Note that once loaded, we will never unload the PDH library.

@return  CONFIG_SUCCESSFUL if successful, negative on failure.
Helper to initialize the PDH library . Loads the library and sets up the functions . Note that once loaded we will never unload the PDH library . @return CONFIG_SUCCESSFUL if successful negative on failure .
int
perfInit(void) {
    static HMODULE    h;
    static BOOL        running, inited;
    int error;
    if (running) {
        return CONFIG_SUCCESSFUL;
    }
    error = CONFIG_SUCCESSFUL;
    EnterCriticalSection(&initializationLock); {
        if (!inited) {
            char         buf[64] = "";
            SYSTEM_INFO si;
            GetSystemInfo(&si);
            num_cpus  = si.dwNumberOfProcessors;
            cpuFactor = num_cpus * 100;
            if ((h = LoadLibrary("pdh.dll")) == NULL) {
                error = -2;
            } else if (get_functions(h, buf, sizeof(buf)) < 0) {
                FreeLibrary(h);
                h = NULL;
                error = -2;
            } else {
                if (initProcessorCounters() != 0) {
                } else if (initProcLoadCounter() != 0) {
                } else if (initProcSystemLoadCounter() != 0) {
                } else {
                    inited = true;
                }
            }
        }
    } LeaveCriticalSection(&initializationLock);
    if (inited && error == CONFIG_SUCCESSFUL) {
        running = true;
    }
    return error;
}
int perfInit ( void ) { static HMODULE h ; static BOOL running , inited ; int error ; if ( running ) { return CONFIG_SUCCESSFUL ; } error = CONFIG_SUCCESSFUL ; EnterCriticalSection ( & initializationLock ) ; { if ( ! inited ) { char buf [ 64 ] = " " ; SYSTEM_INFO si ; GetSystemInfo ( & si ) ; num_cpus = si . dwNumberOfProcessors ; cpuFactor = num_cpus * 100 ; if ( ( h = LoadLibrary ( " " ) ) == NULL ) { error = -2 ; } else if ( get_functions ( h , buf , sizeof ( buf ) ) < 0 ) { FreeLibrary ( h ) ; h = NULL ; error = -2 ; } else { if ( initProcessorCounters ( ) != 0 ) { } else if ( initProcLoadCounter ( ) != 0 ) { } else if ( initProcSystemLoadCounter ( ) != 0 ) { } else { inited = true ; } } } } LeaveCriticalSection ( & initializationLock ) ; if ( inited && error == CONFIG_SUCCESSFUL ) { running = true ; } return error ; }
Helper to initialize the PDH library.
Helper to initialize the PDH library .
// this is double checked locking again, but we try to bypass the worst by // implicit membar at end of lock. // CMH. But windows will not care about our affinity when giving // us measurements. Need the real, raw num cpus. // Initialize the denominator for the jvm load calculations /**
             * Do this dynamically, so we don't fail to start on systems without pdh.
             */ /* printf("Could not load pdh.dll (%d)", GetLastError()); */ /* printf("Failed to init pdh functions: %s.\n", buf); */ /* printf("Failed to init system load counters.\n"); */ /* printf("Failed to init process load counter.\n"); */ /* printf("Failed to init process system load counter.\n"); */