$UsStat: Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (link repair)
m (clarify return value)
Line 15: Line 15:
<table>
<table>
<tr><th>%string</th>  
<tr><th>%string</th>  
<td>A string containing binary data, the first 4 bytes of which is an [[#Return codes|error code]].  
<td>A string containing binary data. If the string is exactly four bytes, it contains an [[#Return codes|error code]].  
<p>
<p>
If the error code is negative, <var class="term">%string</var> will only be 4 bytes long. If the error code is positive, it contains a number of milliseconds that the online has been up. This provides a convenient number for calculating rates for the statistics. </p>
Otherwise, the first four bytes contain the number of milliseconds that the Online has been up. This provides a convenient number for calculating rates for the statistics. </p>
<p>
<p>
If a positive error code is returned, the next 10 bytes contain the userid followed by 2 bytes containing the binary user number. This means that the actual data starts at offset 16 (byte number 17) in the result string.</p></td></tr>
The next ten bytes contain the user ID, then follows two bytes containing the binary user number. This means that the actual data starts at offset 16 (byte number 17) in the result string.</p></td></tr>


<tr><th>stat_list</th>
<tr><th>stat_list</th>
Line 31: Line 31:


===Return codes===
===Return codes===
<p class="code"> -5 - Required parameter not specified
<p class="code"> -5   Required parameter not specified
-12 - Invalid parameter (argument 2 > NUSERS)
-12   Invalid parameter (argument 2 > NUSERS)
-13 - STAT not linked in
-13   STAT not linked in
-14 - Result string would be longer than 255 bytes
-14   Result string would be longer than 255 bytes
-15 - User not logged on any more
-15   User not logged on any more
</p>
</p>



Revision as of 20:27, 3 October 2016

Retrieve user's statistics into string

Note: Many $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the $UsStat function is the UserStatistics class.

This function allows retrieval of a specific user's statistics into a string.

The $UsStat function accepts two argument and returns a string made up of an error code and returned statistics.

Syntax

%string = $UsStat(stat_list, user_num)

Syntax terms

%string A string containing binary data. If the string is exactly four bytes, it contains an error code.

Otherwise, the first four bytes contain the number of milliseconds that the Online has been up. This provides a convenient number for calculating rates for the statistics.

The next ten bytes contain the user ID, then follows two bytes containing the binary user number. This means that the actual data starts at offset 16 (byte number 17) in the result string.

stat_list A string of blank-delimited words indicating the statistics to be returned. The length of each returned statistic is always a multiple of 4 bytes. This facilitates the use of $StatD with the returned string.

For more information about available statistics, see the SirMon wiki pages.

user_num The user number of the user for which data is to be returned.

Return codes

-5 Required parameter not specified -12 Invalid parameter (argument 2 > NUSERS) -13 STAT not linked in -14 Result string would be longer than 255 bytes -15 User not logged on any more

Example

The following program displays some totals for user 0.

B %DATA IS STRING LEN 255 %DATA = $UsStat('CPU SVIO PNAME DKIO', 0) IF $LEN(%DATA) = 4 THEN PRINT '$USSTAT ERROR... RC = ' WITH - $UNBIN(%DATA) STOP END IF PRINT 'USERID = ' WITH $SUBSTR(%DATA, 5, 10) PRINT 'CPU = ' WITH $UNBIN( $SUBSTR(%DATA, 17, 4) ) PRINT 'SVIO = ' WITH $UNBIN( $SUBSTR(%DATA, 21, 4) ) PRINT 'PNAME = ' WITH SUBSTR(%DATA, 25, 16) ) PRINT 'DKIO = ' WITH $UNBIN( $SUBSTR(%DATA, 41, 4) ) END

Products authorizing $UsStat