Results 1 to 6 of 6

Thread: Obtaining Millisecond Server Time

  1. #1
    Senior Member johndanter's Avatar
    Join Date
    Sep 2003
    Location
    Cork, Ireland
    Posts
    1,347

    Obtaining Millisecond Server Time

    Hi folks,

    I have an issue where I am trying to write the duration a transaction occurred and just use get start and end time BSFNs and work out the difference
    Issue is, when it's really fast the difference is ZERO as the seconds are the same

    So BSFN GetSystemUTime is not good enough as I need the millsecond element

    IN->[ 5] <Item>: TimeDateStart <type>: JDEUTIME <Value>: [12/06/18 17:58:59 (UTC)] (actually Dec 6 11:58:59.116550 in the log)
    IN->[ 6] <Item>: TimeDateEnd <type>: JDEUTIME <Value>: [12/06/18 17:58:59 (UTC)] (actually Dec 6 11:58:59.989770 in the log)

    So this actually took 80000 nanoseconds but the overall second difference is ZERO

    Any ideas folks? What DD items store milliseconds and what BSFNs can retrieve and store this. CPUS?
    I can't see any BSFN on F9862

    Thanks

    John
    Last edited by johndanter; 12-12-2018 at 10:28 AM.

  2. #2
    Senior Member
    Join Date
    Mar 2004
    Location
    Fort Worth, Texas
    Posts
    1,529
    If on windows (just need to find the equivalent for linux/as400):

    Code:
    /************************************************************************** 
     *  Business Function:  AcmeElapsedMillisecondsStart 
     * 
     *        Description:  AcmeElapsedMillisecondsStart 
     * 
     *         Parameters: 
     *           LPBHVRCOM           lpBhvrCom    Business Function Communications 
     *           LPVOID              lpVoid       Void Parameter - DO NOT USE! 
     *           LPDSD5800           lpDS         Parameter Data Structure Pointer   
     * 
     *************************************************************************/ 
     
    JDEBFRTN (ID) JDEBFWINAPI AcmeElapsedMillisecondsStart (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5800032A lpDS)  
     
    { 
       /************************************************************************ 
        *  Variable declarations 
        ************************************************************************/ 
    
       /************************************************************************ 
        * Check for NULL pointers 
        ************************************************************************/ 
       if ((lpBhvrCom == (LPBHVRCOM) NULL) || 
           (lpVoid    == (LPVOID)    NULL) || 
           (lpDS      == (LPDSD5800032A)	NULL)) 
       { 
         jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("4363"), (LPVOID) NULL); 
         return ER_ERROR; 
       } 
     
       /************************************************************************ 
        * Main Processing 
        ************************************************************************/ 
    
    	//lpDS->idPtrHndStartTime = timeGetTime();
    	lpDS->idPtrHndStartTime = GetTickCount();
     
       /************************************************************************ 
        * Function Clean Up 
        ************************************************************************/ 
    //FunctionCleanUp:
    
    	return ER_SUCCESS;
    } 
    
    
    /************************************************************************** 
     *  Business Function:  AcmeElapsedMillisecondsEnd 
     * 
     *        Description:  AcmeElapsedMillisecondsEnd 
     * 
     *         Parameters: 
     *           LPBHVRCOM           lpBhvrCom    Business Function Communications 
     *           LPVOID              lpVoid       Void Parameter - DO NOT USE! 
     *           LPDSD5800           lpDS         Parameter Data Structure Pointer   
     * 
     *************************************************************************/ 
     
    JDEBFRTN (ID) JDEBFWINAPI AcmeElapsedMillisecondsEnd (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5800032B lpDS)  
     
    { 
       /************************************************************************ 
        *  Variable declarations 
        ************************************************************************/ 
    	ID			endTime = 0, diff = 0;
    
       /************************************************************************ 
        * Check for NULL pointers 
        ************************************************************************/ 
       if ((lpBhvrCom == (LPBHVRCOM) NULL) || 
           (lpVoid    == (LPVOID)    NULL) || 
           (lpDS      == (LPDSD5800032B)	NULL)) 
       { 
         jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("4363"), (LPVOID) NULL); 
         return ER_ERROR; 
       } 
     
       /************************************************************************ 
        * Main Processing 
        ************************************************************************/ 
    
    	//endTime = timeGetTime();
    	endTime = GetTickCount();
    
    	if(lpDS->idPtrHndStartTime > endTime)
    	{
    		jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("018Y"), (LPVOID) NULL); 
    		return ER_ERROR; 
    	}
    
    	diff = endTime - lpDS->idPtrHndStartTime;
    	LongToMathNumeric(diff, &lpDS->mnElapsedMilliseconds);
    
    
       /************************************************************************ 
        * Function Clean Up 
        ************************************************************************/ 
    //FunctionCleanUp:
    
    	return ER_SUCCESS;
    }
    I use this all the time and have some other complimentary functions to convert to hh:mm:ss, etc.

    Btw, I name the parameter idPtrHndStartTime in the event I had some struct I need to store time in... perhaps on Linux???? If that was the case I could just jdeAlloc the struct, pass address via jdeStoreDataPtr, etc. When I went to implement on Windows it was just a DWORD so I stored the value directly in idPtrHndStartTime. All that to say, if you are on AS400 or Linux the implementation might not be as simple.

    Oh.... and one other thing I may have to look at for JDE 64bit....
    Last edited by BOster; 12-12-2018 at 03:22 PM.
    Brian Oster
    Application Development Manager
    E1: 9.0 (TR9.1.5.1) / 9.2 (TR9.2.2.2)
    JAS/BSSV: Weblogic 12.1.2 / Weblogic 12.2
    ES: Win2008 / Win2016
    DB: MSSQL 2014 / 2016
    WebDev Client: Win7Pro / Win10Pro

  3. #3
    Had the same problem recently. I used jdeGetDateTimeAndMilliSecCouter - that's not a typo, it really ends with "Couter". If you need an example, look at B9312

  4. #4
    Senior Member johndanter's Avatar
    Join Date
    Sep 2003
    Location
    Cork, Ireland
    Posts
    1,347
    Thanks folks.

    I am on 9.0 TR 9.1.5.3, so I can't see these BSFNs or APIs
    John Danter
    You don't go out looking for a job dressed like that do you, on a weekday?

    E900 TR 9.1.5.3 Unix

  5. #5
    Confirmed that jdeGetDateTimeAndMilliSecCouter was introduced after 9.1.5x.

    You can use clock_gettime in Unix. It is in time.h, which is included in JDE.h, but I am not sure if it was included specifically for Windows. If not you can include it in your business function.
    Regards,

    Hari Sharma
    Aellius
    EnterpriseOne: Integration (.Net, Web Services) | Output Management | Monitoring

  6. #6
    Member
    Join Date
    Jun 2001
    Location
    Colorful Colorado
    Posts
    469
    In the past, I've rolled my own:

    Code:
    #ifdef _WIN32
    #include <sys/timeb.h>
    #else
    #include <sys/time.h>
    #endif
    #include <time.h>
    
    /* returns time in seconds since midnight (00:00:00), January 1, 1970, coordinated universal time (UTC)
     * as a double, with fractional seconds as:
     * - Windows: 
     *      fractional microseconds (0.001 sec resolution)
     * - POSIX(UNIX/IBMi/etc): 
     *      fractional milliseconds (0.000001 sec resolution)
     */
    double getTimeInSecDbl(void) 
    {
    # ifdef _WIN32
      struct _timeb tb;
      _ftime(&tb);
      return (double)tb.time + (0.001 * (double)tb.millitm);
    # else
      struct timeval tv;
      /* Yes, I know,gettimeofday is deprecated since POSIX 2008.  
       * Convert to use clock_gettime() and nanoseconds on UNIX if you wish. */
      gettimeofday(&tv, 0); 
      return (double)tv.tv_sec + (0.000001 * (double)tv.tv_usec);
    # endif
    }
    ...And send the return value through DoubleToMathNumeric() to stick it into E1 data.

    Note:
    The real reason I used gettimeofday() is that the function clock_gettime() is only available if the macro _POSIX_TIMERS is defined in <unistd.h> to a value greater than 0 -- and it isn't available on all POSIX environments I work on (including some embedded ones) while gettimeofday() always seems to be present.
    Last edited by Segfault; 12-13-2018 at 04:28 PM.
    --john

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
The legal restrictions and terms of use applicable to this site are available here.
Use of this site signifies your agreement to the terms of use.
JDELIST is NOT affiliated with JD Edwards® & Company, Oracle or Peoplesoft. Contents of this site are neither endorsed nor approved by JD Edwards® & Company and, or Oracle.