VirtualBox

Changeset 69987 in vbox


Ignore:
Timestamp:
Dec 7, 2017 4:02:40 PM (7 years ago)
Author:
vboxsync
Message:

VBoxService: Added "/VirtualBox/GuestAdd/VBoxService/--timesync-verbosity" guest property to make the time syncing service more verbose. Untested.

Location:
trunk/src/VBox/Additions/common/VBoxService
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp

    r69779 r69987  
    334334
    335335
     336/**
     337 * Logs a verbose message.
     338 *
     339 * @param   pszFormat   The message text.
     340 * @param   ...         Format arguments.
     341 */
     342void VGSvcLog(const char *pszFormat, ...)
     343{
     344#ifdef DEBUG
     345    int rc = RTCritSectEnter(&g_csLog);
     346    if (RT_SUCCESS(rc))
     347    {
     348#endif
     349        va_list args;
     350        va_start(args, pszFormat);
     351        char *psz = NULL;
     352        RTStrAPrintfV(&psz, pszFormat, args);
     353        va_end(args);
     354
     355        AssertPtr(psz);
     356        LogRel(("%s", psz));
     357
     358        RTStrFree(psz);
     359#ifdef DEBUG
     360        RTCritSectLeave(&g_csLog);
     361    }
     362#endif
     363}
     364
     365
     366/**
     367 * Destroys the currently active logging instance.
     368 */
    336369void VGSvcLogDestroy(void)
    337370{
     
    415448
    416449/**
    417  * Displays a verbose message.
     450 * Displays a verbose message based on the currently
     451 * set global verbosity level.
    418452 *
    419453 * @param   iLevel      Minimum log level required to display this message.
     
    425459    if (iLevel <= g_cVerbosity)
    426460    {
    427 #ifdef DEBUG
    428         int rc = RTCritSectEnter(&g_csLog);
    429         if (RT_SUCCESS(rc))
    430         {
    431 #endif
    432             va_list args;
    433             va_start(args, pszFormat);
    434             char *psz = NULL;
    435             RTStrAPrintfV(&psz, pszFormat, args);
    436             va_end(args);
    437 
    438             AssertPtr(psz);
    439             LogRel(("%s", psz));
    440 
    441             RTStrFree(psz);
    442 #ifdef DEBUG
    443             RTCritSectLeave(&g_csLog);
    444         }
    445 #endif
     461        va_list args;
     462        va_start(args, pszFormat);
     463
     464        VGSvcLog(pszFormat, args);
     465
     466        va_end(args);
    446467    }
    447468}
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h

    r69500 r69987  
    185185extern void                     VGSvcVerbose(unsigned iLevel, const char *pszFormat, ...);
    186186extern int                      VGSvcLogCreate(const char *pszLogFile);
     187extern void                     VGSvcLog(const char *pszFormat, ...);
    187188extern void                     VGSvcLogDestroy(void);
    188189extern int                      VGSvcArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32,
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceTimeSync.cpp

    r69953 r69987  
    131131/** Whether to set the time when the VM was restored. */
    132132static bool             g_fTimeSyncSetOnRestore = true;
     133/** The logging verbosity.
     134 *  This uses the global verbosity level by default. */
     135static unsigned         g_uTimeSyncVerbosity = 0;
    133136
    134137/** Current error count. Used to knowing when to bitch and when not to. */
     
    158161static DECLCALLBACK(int) vgsvcTimeSyncPreInit(void)
    159162{
     163    /* Use global verbosity as default. */
     164    g_uTimeSyncVerbosity = g_cVerbosity;
     165
    160166#ifdef VBOX_WITH_GUEST_PROPS
    161167    /** @todo Merge this function with vgsvcTimeSyncOption() to generalize
     
    219225                g_fTimeSyncSetOnRestore = !!value;
    220226        }
    221 
     227        if (   RT_SUCCESS(rc)
     228            || rc == VERR_NOT_FOUND)
     229        {
     230            uint32_t value;
     231            rc = VGSvcReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-verbosity",
     232                                     &value, 0, 255);
     233            if (RT_SUCCESS(rc))
     234                g_uTimeSyncVerbosity = (unsigned)value;
     235        }
    222236        VbglR3GuestPropDisconnect(uGuestPropSvcClientID);
    223237    }
     
    230244    return VINF_SUCCESS;
    231245#endif
     246}
     247
     248
     249/**
     250 * Displays a verbose message based on the currently
     251 * set timesync verbosity level.
     252 *
     253 * @param   iLevel      Minimum log level required to display this message.
     254 * @param   pszFormat   The message text.
     255 * @param   ...         Format arguments.
     256 */
     257static void vgsvcTimeSyncLog(unsigned iLevel, const char *pszFormat, ...)
     258{
     259    if (iLevel <= g_uTimeSyncVerbosity)
     260    {
     261        va_list args;
     262        va_start(args, pszFormat);
     263
     264        VGSvcLog(pszFormat, args);
     265
     266        va_end(args);
     267    }
    232268}
    233269
     
    336372
    337373    if (GetSystemTimeAdjustment(&g_dwWinTimeAdjustment, &g_dwWinTimeIncrement, &g_bWinTimeAdjustmentDisabled))
    338         VGSvcVerbose(3, "vgsvcTimeSyncInit: Initially %ld (100ns) units per %ld (100 ns) units interval, disabled=%d\n",
    339                      g_dwWinTimeAdjustment, g_dwWinTimeIncrement, g_bWinTimeAdjustmentDisabled ? 1 : 0);
     374        vgsvcTimeSyncLog(3, "vgsvcTimeSyncInit: Initially %ld (100ns) units per %ld (100 ns) units interval, disabled=%d\n",
     375                         g_dwWinTimeAdjustment, g_dwWinTimeIncrement, g_bWinTimeAdjustmentDisabled ? 1 : 0);
    340376    else
    341377    {
     
    394430        }
    395431
    396         VGSvcVerbose(3, "vgsvcTimeSyncAdjust: Drift=%lldms\n", RTTimeSpecGetMilli(pDrift));
    397         VGSvcVerbose(3, "vgsvcTimeSyncAdjust: OrgTA=%ld, CurTA=%ld, NewTA=%ld, DiffNew=%ld, DiffMax=%ld\n",
    398                      g_dwWinTimeAdjustment, dwWinTimeAdjustment, dwWinNewTimeAdjustment, dwDiffNew, dwDiffMax);
     432        vgsvcTimeSyncLog(3, "vgsvcTimeSyncAdjust: Drift=%lldms\n", RTTimeSpecGetMilli(pDrift));
     433        vgsvcTimeSyncLog(3, "vgsvcTimeSyncAdjust: OrgTA=%ld, CurTA=%ld, NewTA=%ld, DiffNew=%ld, DiffMax=%ld\n",
     434                         g_dwWinTimeAdjustment, dwWinTimeAdjustment, dwWinNewTimeAdjustment, dwDiffNew, dwDiffMax);
    399435        if (SetSystemTimeAdjustment(dwWinNewTimeAdjustment, FALSE /* Periodic adjustments enabled. */))
    400436        {
     
    421457    {
    422458        if (g_cVerbosity >= 1)
    423             VGSvcVerbose(1, "vgsvcTimeSyncAdjust: adjtime by %RDtimespec\n", pDrift);
     459            vgsvcTimeSyncLog(1, "vgsvcTimeSyncAdjust: adjtime by %RDtimespec\n", pDrift);
    424460        g_cTimeSyncErrors = 0;
    425461        return true;
     
    445481        return;
    446482    if (SetSystemTimeAdjustment(0, TRUE /* Periodic adjustments disabled. */))
    447         VGSvcVerbose(3, "vgsvcTimeSyncCancelAdjust: Windows Time Adjustment is now disabled.\n");
     483        vgsvcTimeSyncLog(3, "vgsvcTimeSyncCancelAdjust: Windows Time Adjustment is now disabled.\n");
    448484    else if (g_cTimeSyncErrors++ < 10)
    449485        VGSvcError("vgsvcTimeSyncCancelAdjust: SetSystemTimeAdjustment(,disable) failed, error=%u\n", GetLastError());
     
    475511            char        sz[64];
    476512            RTTIME      Time;
    477             VGSvcVerbose(1, "time set to %s\n", RTTimeToString(RTTimeExplode(&Time, &NewGuestTime), sz, sizeof(sz)));
     513            vgsvcTimeSyncLog(1, "time set to %s\n", RTTimeToString(RTTimeExplode(&Time, &NewGuestTime), sz, sizeof(sz)));
    478514#ifdef DEBUG
    479515            RTTIMESPEC  Tmp;
    480516            if (g_cVerbosity >= 3)
    481                 VGSvcVerbose(3, "        now %s\n", RTTimeToString(RTTimeExplode(&Time, RTTimeNow(&Tmp)), sz, sizeof(sz)));
     517                vgsvcTimeSyncLog(3, "        now %s\n", RTTimeToString(RTTimeExplode(&Time, RTTimeNow(&Tmp)), sz, sizeof(sz)));
    482518#endif
    483519        }
     
    556592                    && idNewSession != g_idTimeSyncSession)
    557593                {
    558                     VGSvcVerbose(3, "vgsvcTimeSyncWorker: The VM session ID changed, forcing resync.\n");
     594                    vgsvcTimeSyncLog(3, "vgsvcTimeSyncWorker: The VM session ID changed, forcing resync.\n");
    559595                    g_idTimeSyncSession  = idNewSession;
    560596                    TimeSyncSetThreshold = 0;
     
    577613                if (g_cVerbosity >= 3)
    578614                {
    579                     VGSvcVerbose(3, "vgsvcTimeSyncWorker: Host:    %s    (MinAdjust: %RU32 ms)\n",
    580                                  RTTimeToString(RTTimeExplode(&Time, &HostNow), sz, sizeof(sz)), MinAdjust);
    581                     VGSvcVerbose(3, "vgsvcTimeSyncWorker: Guest: - %s => %RDtimespec drift\n",
    582                                  RTTimeToString(RTTimeExplode(&Time, &GuestNow), sz, sizeof(sz)), &Drift);
     615                    vgsvcTimeSyncLog(3, "vgsvcTimeSyncWorker: Host:    %s    (MinAdjust: %RU32 ms)\n",
     616                                     RTTimeToString(RTTimeExplode(&Time, &HostNow), sz, sizeof(sz)), MinAdjust);
     617                    vgsvcTimeSyncLog(3, "vgsvcTimeSyncWorker: Guest: - %s => %RDtimespec drift\n",
     618                                     RTTimeToString(RTTimeExplode(&Time, &GuestNow), sz, sizeof(sz)), &Drift);
    583619                }
    584620
     
    605641                    int64_t cNsHostDelta = RTTimeSpecGetNano(&HostNow) - RTTimeSpecGetNano(&HostLast);
    606642                    if ((uint64_t)RT_ABS(cNsHostDelta) > RT_NS_1HOUR / 2)
    607                         VGSvcVerbose(0, "vgsvcTimeSyncWorker: Radical host time change: %'RI64ns (HostNow=%RDtimespec HostLast=%RDtimespec)\n",
    608                                      cNsHostDelta, &HostNow, &HostLast);
     643                        vgsvcTimeSyncLog(0, "vgsvcTimeSyncWorker: Radical host time change: %'RI64ns (HostNow=%RDtimespec HostLast=%RDtimespec)\n",
     644                                         cNsHostDelta, &HostNow, &HostLast);
    609645                }
    610646                else
     
    613649                break;
    614650            }
    615             VGSvcVerbose(3, "vgsvcTimeSyncWorker: %RDtimespec: latency too high (%RDtimespec, max %ums) sleeping 1s\n",
    616                          &GuestNow, &GuestElapsed, g_cMsTimeSyncMaxLatency);
     651            vgsvcTimeSyncLog(3, "vgsvcTimeSyncWorker: %RDtimespec: latency too high (%RDtimespec, max %ums) sleeping 1s\n",
     652                             &GuestNow, &GuestElapsed, g_cMsTimeSyncMaxLatency);
    617653            RTThreadSleep(1000);
    618654        } while (--cTries > 0);
Note: See TracChangeset for help on using the changeset viewer.

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