VirtualBox

儲存庫 vbox 的更動 18406


忽略:
時間撮記:
2009-3-27 下午03:31:21 (16 年 以前)
作者:
vboxsync
訊息:

Main: add IProgress::GetTimeRemaining()

位置:
trunk/src/VBox
檔案:
修改 4 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp

    r18396 r18406  
    127127               )
    128128            {
    129                 RTPrintf("(%ld/%ld) %ls %ld%% => %ld%%\n", ulOperation + 1, cOperations, bstrOperationDescription.raw(), ulCurrentOperationPercent, ulCurrentPercent);
     129                LONG lSecsRem;
     130                progress->COMGETTER(TimeRemaining)(&lSecsRem);
     131
     132                RTPrintf("(%ld/%ld) %ls %ld%% => %ld%% (%d s remaining)\n", ulOperation + 1, cOperations, bstrOperationDescription.raw(), ulCurrentOperationPercent, ulCurrentPercent, lSecsRem);
    130133                ulLastPercent = ulCurrentPercent;
    131134                ulLastOperationPercent = ulCurrentOperationPercent;
  • trunk/src/VBox/Main/ProgressImpl.cpp

    r18394 r18406  
    6666    m_ulCurrentOperationWeight =
    6767    m_ulOperationPercent = 0;
     68
     69    // get creation timestamp
     70    m_ullTimestamp = RTTimeMilliTS();
    6871
    6972    return S_OK;
     
    258261}
    259262
     263/**
     264 * Internal helper to compute the total percent value based on the member values and
     265 * returns it as a "double". This is used both by GetPercent (which returns it as a
     266 * rounded ULONG) and GetTimeRemaining().
     267 *
     268 * Requires locking by the caller!
     269 *
     270 * @return fractional percentage as a double value.
     271 */
     272double ProgressBase::calcTotalPercent()
     273{
     274    // avoid division by zero
     275    if (m_ulTotalOperationsWeight == 0)
     276        return 0;
     277
     278    double dPercent = (    (double)m_ulOperationsCompletedWeight                                              // weight of operations that have been completed
     279                         + ((double)m_ulOperationPercent * (double)m_ulCurrentOperationWeight / (double)100)  // plus partial weight of the current operation
     280                      ) * (double)100 / (double)m_ulTotalOperationsWeight;
     281
     282    return dPercent;
     283}
     284
     285STDMETHODIMP ProgressBase::COMGETTER(TimeRemaining)(LONG *aTimeRemaining)
     286{
     287    CheckComArgOutPointerValid(aTimeRemaining);
     288
     289    AutoCaller autoCaller(this);
     290    CheckComRCReturnRC(autoCaller.rc());
     291
     292    AutoReadLock alock(this);
     293
     294    if (mCompleted)
     295        *aTimeRemaining = 0;
     296    else
     297    {
     298        double dPercentDone = calcTotalPercent();
     299        if (dPercentDone < 1)
     300            *aTimeRemaining = -1;       // unreliable, or avoid division by 0 below
     301        else
     302        {
     303            uint64_t ullTimeNow = RTTimeMilliTS();
     304            uint64_t ullTimeElapsed = ullTimeNow - m_ullTimestamp;
     305            uint64_t ullTimeTotal = (uint64_t)(ullTimeElapsed / dPercentDone * 100);
     306            uint64_t ullTimeRemaining = ullTimeTotal - ullTimeElapsed;
     307
     308//             Log(("ProgressBase::GetTimeRemaining: dPercentDone %RI32, ullTimeNow = %RI64, ullTimeElapsed = %RI64, ullTimeTotal = %RI64, ullTimeRemaining = %RI64\n",
     309//                         (uint32_t)dPercentDone, ullTimeNow, ullTimeElapsed, ullTimeTotal, ullTimeRemaining));
     310
     311            *aTimeRemaining = (LONG)(ullTimeRemaining / 1000);
     312        }
     313    }
     314
     315    return S_OK;
     316}
     317
    260318STDMETHODIMP ProgressBase::COMGETTER(Percent)(ULONG *aPercent)
    261319{
     
    271329    else
    272330    {
    273         ULONG ulPercent = (ULONG)(    (    (double)m_ulOperationsCompletedWeight                                              // weight of operations that have been completed
    274                                          + ((double)m_ulOperationPercent * (double)m_ulCurrentOperationWeight / (double)100)  // plus partial weight of the current operation
    275                                       ) * (double)100 / (double)m_ulTotalOperationsWeight
    276                                  );
     331        ULONG ulPercent = (ULONG)calcTotalPercent();
    277332        // do not report 100% until we're really really done with everything as the Qt GUI dismisses progress dialogs in that case
    278333        if (    ulPercent == 100
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r18388 r18406  
    78217821  <interface
    78227822     name="IProgress" extends="$unknown"
    7823      uuid="ee1aa091-fda8-47a9-8f1c-4bba002a3229"
     7823     uuid="c4f94e6b-2273-446b-9539-4c05bb416fe7"
    78247824     wsmap="managed"
    78257825     >
    78267826    <desc>
    7827         The IProgress interface allows for monitoring the progress of
    7828         an asynchronous tasks within VirtualBox.
     7827        The IProgress interface is used to track and control
     7828        asynchronous tasks within VirtualBox.
    78297829
    78307830        An instance of this is returned every time VirtualBox starts
     
    78447844        cancel the task by calling <link to="#cancel" />.
    78457845
    7846         A task represented by IProgress can consist of one or more
    7847         sub-operations that run sequentially, one by one (see
     7846        A task represented by IProgress consists of either one or
     7847        several sub-operations that run sequentially, one by one (see
    78487848        <link to="#operation" /> and <link to="#operationCount" />).
    78497849        Every operation is identified by a number (starting from 0)
     
    78547854        percentage of completion of the task as a whole
    78557855        in <link to="#percent" />.
     7856
    78567857        Similarly, you can wait for the completion of a particular
    78577858        operation via <link to="#waitForOperationCompletion" /> or
     
    78827883        Returns 100 if <link to="#completed" /> is true.
    78837884      </desc>
     7885    </attribute>
     7886
     7887    <attribute name="timeRemaining" type="long" readonly="yes">
     7888        <desc>
     7889            Estimated remaining time until the operation completes, in
     7890            seconds.
     7891
     7892            Returns 0 if the task is complete.
     7893
     7894            Returns -1 if the time cannot be computed, in
     7895            particular if the current progress is 0.
     7896
     7897            The estimate will be unreliable for low progress
     7898            values. It will become more reliable as the task progresses;
     7899            it is not recommended to display an ETA before 10% of
     7900            a task have completed.
     7901        </desc>
    78847902    </attribute>
    78857903
  • trunk/src/VBox/Main/include/ProgressImpl.h

    r18269 r18406  
    7373    STDMETHOD(COMGETTER(Cancelable)) (BOOL *aCancelable);
    7474    STDMETHOD(COMGETTER(Percent)) (ULONG *aPercent);
     75    STDMETHOD(COMGETTER(TimeRemaining)) (LONG *aTimeRemaining);
    7576    STDMETHOD(COMGETTER(Completed)) (BOOL *aCompleted);
    7677    STDMETHOD(COMGETTER(Canceled)) (BOOL *aCanceled);
     
    9192    BOOL completed() const { return mCompleted; }
    9293    HRESULT resultCode() const { return mResultCode; }
     94    double calcTotalPercent();
    9395
    9496protected:
     
    103105    const Guid mId;
    104106    const Bstr mDescription;
     107
     108    uint64_t m_ullTimestamp;                        // progress object creation timestamp, for ETA computation
    105109
    106110    /* The fields below are to be properly initalized by subclasses */
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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