Skip to main content

Notifications

Community site session details

Community site session details

Session Id :

X++ code to calculate time consumed for a process in Ax2012

Chaitanya Golla Profile Picture Chaitanya Golla 17,225

Hi,

We can use methods getTickCount & getTickCount64 of class WinAPI & WinAPIServer and method timeConsumed of Global class to calculate time consumed for a specific process in AX2012.  Below is the job that helps to know the usage of each.

static void CG_TimeElapsed(Args _args)
{
    int         startTime, endTime;
    int64       start64Time, end64Time;
    FromTime    timeConsumedStartTime;
    ToTime      timeConsumedEndTime;
    int         timeConsumedInMin;

    startTime = WinAPI::getTickCount();
    start64Time = WinAPI::getTickCount64();
    timeConsumedStartTime = timeNow();

    sleep(3000);

    // Using method getTickCount
    endTime = WinAPI::getTickCount(); // WinApI executes on client and same method is available on WinAPI server which executes on server
    info(strFmt('Captured time %1 minutes using method getTickCount', ((endTime - startTime)/1000)/60));

    // Using method getTickCount64 - Provides time consumed information more precisely compared to getTickCount
    end64Time = WinAPI::getTickCount64(); // WinApI executes on client and same method is available on WinAPI server which executes on server
    info(strFmt('Captured time %1 minutes using method getTickCount64', ((endTime - startTime)/1000)/60));

    // Using method Time consumed
    timeConsumedEndTime = timeNow();
    timeConsumedInMin = str2int(Global::timeConsumed(timeConsumedStartTime, timeConsumedEndTime));

    info(strFmt('Captured time %1 minutes using method timeConsumed', timeConsumedInMin / 60));
}

Output:
Timing.png


Comments

*This post is locked for comments