Ticket #1939: fix-profiler-corruption-recovery.patch

File fix-profiler-corruption-recovery.patch, 2.7 KB (added by Markus, 11 years ago)

The output is filtered and normally not displayed. As its an error, removed the filtering.

  • trunk/source/ps/Profile.h

    diff -Nur a/trunk/source/ps/Profile.h b/trunk/source/ps/Profile.h
    a b  
    150150{
    151151public:
    152152    CProfileSample(const char* name)
     153        : n(name)
    153154    {
    154155        if (CProfileManager::IsInitialised())
    155156        {
     
    161162    }
    162163    ~CProfileSample()
    163164    {
    164         if (CProfileManager::IsInitialised())
    165             g_Profiler.Stop();
     165        if (!CProfileManager::IsInitialised() || !ThreadUtil::IsMainThread())
     166            return;
     167        if (n != g_Profiler.GetCurrent()->GetName())
     168        {
     169            debug_printf(L"PROFILER: Current not right: Should be \"%s\" but is \"%s\"\n", n, g_Profiler.GetCurrent()->GetName());
     170
     171            do {
     172                debug_printf(L"PROFILER: Skip \"%s\". This profiler was not stopped correctly!\n", g_Profiler.GetCurrent()->GetName());
     173                g_Profiler.Stop();
     174            }
     175            while (n != g_Profiler.GetCurrent()->GetName() && g_Profiler.GetCurrent() != g_Profiler.GetRoot());
     176
     177            if (g_Profiler.GetCurrent() == g_Profiler.GetRoot() && n != g_Profiler.GetRoot()->GetName())
     178            {
     179                // This should only happen when stop is called more often than start was called.
     180                debug_printf(L"PROFILER: Did not find the right callee in the stack but reached root: Performing reset.\n");
     181                g_Profiler.StructuralReset();
     182            }
     183        }
     184        g_Profiler.Stop();
    166185    }
     186private:
     187    const char *n;
    167188};
    168189
    169190class CProfileSampleScript
    170191{
    171192public:
    172     CProfileSampleScript( const char* name )
     193    CProfileSampleScript(const char* name)
     194        : n(name)
    173195    {
    174196        if (CProfileManager::IsInitialised())
    175197        {
     
    184206    }
    185207    ~CProfileSampleScript()
    186208    {
    187         if (CProfileManager::IsInitialised())
    188             if (ThreadUtil::IsMainThread())
     209        if (!CProfileManager::IsInitialised() || !ThreadUtil::IsMainThread())
     210            return;
     211        if (n != g_Profiler.GetCurrent()->GetName())
     212        {
     213            debug_printf(L"PROFILER: Current not right: Should be \"%s\" but is \"%s\"\n", n, g_Profiler.GetCurrent()->GetName());
     214
     215            do {
     216                debug_printf(L"PROFILER: Skip \"%s\". This profiler was not stopped correctly!\n", g_Profiler.GetCurrent()->GetName());
    189217                g_Profiler.Stop();
     218            }
     219            while (n != g_Profiler.GetCurrent()->GetName() && g_Profiler.GetCurrent() != g_Profiler.GetRoot());
     220
     221            if (g_Profiler.GetCurrent() == g_Profiler.GetRoot() && n != g_Profiler.GetRoot()->GetName())
     222            {
     223                // This should only happen when stop is called more often than start was called.
     224                debug_printf(L"PROFILER: Did not find the right callee in the stack but reached root: Performing reset.\n");
     225                g_Profiler.StructuralReset();
     226            }
     227        }
     228        g_Profiler.Stop();
    190229    }
     230private:
     231    const char *n;
     232
    191233};
    192234
    193235// Put a PROFILE("xyz") block at the start of all code to be profiled.