VirtualBox

Changeset 89696 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Jun 15, 2021 9:53:06 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
145144
Message:

Main/MachineDebugger: Implement API for taking a guest sample, bugref:10025

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r87278 r89696  
    2058420584    uuid="00ae6af4-00a7-4104-0009-49bc00b2da80"
    2058520585    wsmap="managed"
    20586     reservedMethods="16" reservedAttributes="16"
     20586    reservedMethods="15" reservedAttributes="16"
    2058720587    >
    2058820588    <method name="dumpGuestCore">
     
    2097220972      <param name="msInterval" type="long long" dir="return">
    2097320973        <desc>The interval the percentage was calculated over in milliseconds</desc>
     20974      </param>
     20975    </method>
     20976
     20977    <method name="takeGuestSample">
     20978      <desc>
     20979        Creates a sample report of the guest and emulated device activity.
     20980      </desc>
     20981      <param name="filename" type="wstring" dir="in">
     20982        <desc>The file to dump the report to.</desc>
     20983      </param>
     20984      <param name="usInterval" type="unsigned long" dir="in">
     20985        <desc>The sample interval.</desc>
     20986      </param>
     20987      <param name="usSampleTime" type="long long" dir="in">
     20988        <desc>The number of microseconds to sample.</desc>
     20989      </param>
     20990      <param name="progress" type="IProgress" dir="return">
     20991        <desc>The progress object on return.</desc>
    2097420992      </param>
    2097520993    </method>
  • trunk/src/VBox/Main/include/MachineDebuggerImpl.h

    r85121 r89696  
    2727
    2828class Console;
     29class Progress;
    2930
    3031class ATL_NO_VTABLE MachineDebugger :
     
    134135                     com::Utf8Str &aStats);
    135136    HRESULT getCPULoad(ULONG aCpuId, ULONG *aPctExecuting, ULONG *aPctHalted, ULONG *aPctOther, LONG64 *aMsInterval) RT_OVERRIDE;
     137    HRESULT takeGuestSample(const com::Utf8Str &aFilename, ULONG aUsInterval, LONG64 aUsSampleTime, ComPtr<IProgress> &pProgress);
    136138
    137139    // private methods
     
    145147    typedef FNLOGGETSTR *PFNLOGGETSTR;
    146148    HRESULT i_logStringProps(PRTLOGGER pLogger, PFNLOGGETSTR pfnLogGetStr, const char *pszLogGetStr, Utf8Str *pstrSettings);
     149
     150    static DECLCALLBACK(int) i_dbgfProgressCallback(void *pvUser, unsigned uPercentage);
    147151
    148152    Console * const mParent;
     
    160164    bool mFlushMode;
    161165    /** @}  */
     166
     167    /** @name Sample report related things.
     168     * @{ */
     169    /** Sample report handle. */
     170    DBGFSAMPLEREPORT        m_hSampleReport;
     171    /** Progress object for the currently taken guest sample. */
     172    ComObjPtr<Progress>     m_Progress;
     173    /** Filename to dump the report to. */
     174    com::Utf8Str            m_strFilename;
     175    /** @} */
    162176};
    163177
  • trunk/src/VBox/Main/src-client/MachineDebuggerImpl.cpp

    r82968 r89696  
    2727#include "Global.h"
    2828#include "ConsoleImpl.h"
     29#include "ProgressImpl.h"
    2930
    3031#include "AutoCaller.h"
     
    9495    mFlushMode = false;
    9596
     97    m_hSampleReport = NULL;
     98
    9699    /* Confirm a successful initialization */
    97100    autoInitSpan.setSucceeded();
     
    115118    unconst(mParent) = NULL;
    116119    mFlushMode = false;
     120}
     121
     122/**
     123 * @callback_method_impl{FNDBGFPROGRESS}
     124 */
     125/*static*/ DECLCALLBACK(int) MachineDebugger::i_dbgfProgressCallback(void *pvUser, unsigned uPercentage)
     126{
     127    MachineDebugger *pThis = (MachineDebugger *)pvUser;
     128
     129    int vrc = pThis->m_Progress->i_iprtProgressCallback(uPercentage, static_cast<Progress *>(pThis->m_Progress));
     130    if (   RT_SUCCESS(vrc)
     131        && uPercentage == 100)
     132    {
     133        vrc = DBGFR3SampleReportDumpToFile(pThis->m_hSampleReport, pThis->m_strFilename.c_str());
     134        DBGFR3SampleReportRelease(pThis->m_hSampleReport);
     135        pThis->m_hSampleReport = NULL;
     136        if (RT_SUCCESS(vrc))
     137            pThis->m_Progress->i_notifyComplete(S_OK);
     138        else
     139        {
     140            HRESULT hrc = pThis->setError(VBOX_E_IPRT_ERROR,
     141                                          tr("Writing the sample report to '%s' failed with %Rrc"),
     142                                          pThis->m_strFilename.c_str(), vrc);
     143            pThis->m_Progress->i_notifyComplete(hrc);
     144        }
     145        pThis->m_Progress.setNull();
     146    }
     147    else if (vrc == VERR_CANCELLED)
     148        vrc = VERR_DBGF_CANCELLED;
     149
     150    return vrc;
    117151}
    118152
     
    15921626
    15931627
     1628HRESULT MachineDebugger::takeGuestSample(const com::Utf8Str &aFilename, ULONG aUsInterval, LONG64 aUsSampleTime, ComPtr<IProgress> &pProgress)
     1629{
     1630    /*
     1631     * The prologue.
     1632     */
     1633    LogFlowThisFunc(("\n"));
     1634    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     1635    Console::SafeVMPtr ptrVM(mParent);
     1636    HRESULT hrc = ptrVM.rc();
     1637    if (SUCCEEDED(hrc))
     1638    {
     1639        if (!m_hSampleReport)
     1640        {
     1641            m_strFilename = aFilename;
     1642
     1643            int vrc = DBGFR3SampleReportCreate(ptrVM.rawUVM(), aUsInterval, DBGF_SAMPLE_REPORT_F_STACK_REVERSE, &m_hSampleReport);
     1644            if (RT_SUCCESS(vrc))
     1645            {
     1646                hrc = m_Progress.createObject();
     1647                if (SUCCEEDED(hrc))
     1648                {
     1649                    hrc = m_Progress->init(static_cast<IMachineDebugger*>(this),
     1650                                           tr("Creating guest sample report..."),
     1651                                           TRUE /* aCancelable */);
     1652                    if (SUCCEEDED(hrc))
     1653                    {
     1654                        vrc = DBGFR3SampleReportStart(m_hSampleReport, aUsSampleTime, i_dbgfProgressCallback, static_cast<MachineDebugger*>(this));
     1655                        if (RT_SUCCESS(vrc))
     1656                            hrc = m_Progress.queryInterfaceTo(pProgress.asOutParam());
     1657                        else
     1658                            hrc = setErrorVrc(vrc);
     1659                    }
     1660                }
     1661
     1662                if (FAILED(hrc))
     1663                {
     1664                    DBGFR3SampleReportRelease(m_hSampleReport);
     1665                    m_hSampleReport = NULL;
     1666                }
     1667            }
     1668            else
     1669                hrc = setErrorVrc(vrc);
     1670        }
     1671        else
     1672            hrc = setError(VBOX_E_INVALID_VM_STATE, "A sample report is already in progress");
     1673    }
     1674
     1675    return hrc;
     1676}
     1677
     1678
    15941679// public methods only for internal purposes
    15951680/////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette