Logo Search packages:      
Sourcecode: virtualbox-ose version File versions  Download package

int kPrfInitialize ( void   ) 

Initializes and start the profiling.

This should typically be called from some kind of module init function, so we can start profiling upon/before entering main().

Returns:
0 on success

-1 on failure.

Definition at line 1426 of file kProfileR3.cpp.

References g_dwThreadTLS, KPRF_GET_HDR, KPRF_NAME, KPRF_TYPE, kPrfAllocMem(), kPrfFreeMem(), kPrfGetEnvValue(), kPrfMutexDelete(), kPrfMutexInit(), kPrfRWLockDelete(), and kPrfRWLockInit().

Referenced by DllMain().

{
    /*
     * Only initialize once.
     */
    if (KPRF_GET_HDR())
        return 0;

    /*
     * Initial suggestions.
     */
    KU32    cbModSegs  = kPrfGetEnvValue("KPRF2_CBMODSEGS",  128*1024);
    KU32    cFunctions = kPrfGetEnvValue("KPRF2_CFUNCTIONS", 8192);
    KU32    cThreads   = kPrfGetEnvValue("KPRF2_CTHREADS",   256);
    KU32    cStacks    = kPrfGetEnvValue("KPRF2_CSTACKS",    48);
    KU32    cFrames    = kPrfGetEnvValue("KPRF2_CFRAMES",    448);
    KU32    fAffinity  = kPrfGetEnvValue("KPRF2_AFFINITY",   0);

    KU32    cb = KPRF_NAME(CalcSize)(cFunctions, cbModSegs, cThreads, cStacks, cFrames);

    /*
     * Allocate and initialize the data set.
     */
    void *pvBuf = kPrfAllocMem(cb);
    if (!pvBuf)
        return -1;

    KPRF_TYPE(P,HDR) pHdr = KPRF_NAME(Init)(pvBuf, cb, cFunctions, cbModSegs, cThreads, cStacks, cFrames);
    if (pHdr)
    {
        /*
         * Initialize semaphores.
         */
        if (!kPrfMutexInit(&g_ThreadsMutex))
        {
            if (!kPrfMutexInit(&g_ModSegsMutex))
            {
                if (!kPrfRWLockInit(&g_FunctionsRWLock))
                {
                    /*
                     * Allocate the TLS entry.
                     */
#if K_OS == K_OS_WINDOWS
                    g_dwThreadTLS = TlsAlloc();
                    if (g_dwThreadTLS != TLS_OUT_OF_INDEXES)

#elif defined(KPRF_USE_PTHREAD)
                    int rc = pthread_key_create(&g_ThreadKey, kPrfPThreadKeyDtor);
                    if (!rc)

#elif K_OS == K_OS_OS2
                    int rc = DosAllocThreadLocalMemory(sizeof(void *), (PULONG*)&g_ppThread); /** @todo check if this is a count or a size. */
                    if (!rc)

#endif
                    {
                        /*
                         * Apply the affinity mask, if specified.
                         */
                        if (fAffinity)
                        {
#if K_OS == K_OS_WINDOWS
                            SetProcessAffinityMask(GetCurrentProcess(), fAffinity);
#endif
                        }

                        g_pHdr = pHdr;
                        g_fEnabled = true;
                        return 0;
                    }
                    kPrfRWLockDelete(&g_FunctionsRWLock);
                }
                kPrfMutexDelete(&g_ModSegsMutex);
            }
            kPrfMutexDelete(&g_ThreadsMutex);
        }
    }
    kPrfFreeMem(pvBuf);
    return -1;
}


Generated by  Doxygen 1.6.0   Back to index