Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (中文) » MobiLink - 服务器管理 » MobiLink 事件 » 同步事件

 

time_statistics 连接事件

为用户和事件跟踪时间统计信息。

参数

在下表中,说明部分提供 SQL 数据类型。如果您使用 Java 或 .NET 编写脚本,则应该使用相应的数据类型。请参见SQL-Java 数据类型SQL-.NET 数据类型

在 SQL 脚本中,可以使用名称或问号指定事件参数,但不能在一个脚本中混合使用名称和问号。如果使用问号,则参数必须按照如下所示的顺序并且仅当没有指定任何后继参数时才是可选的(例如,如果您想使用参数 2,则必须使用参数 1)。如果使用命名参数,则可以按照任何顺序指定任意参数子集。

SQL 脚本的参数名称

说明

顺序

s.remote_id VARCHAR(128)。MobiLink 远程 ID。只有在使用命名参数时才能引用远程 ID。 不适用

s.username

VARCHAR(128)。MobiLink 用户名。

1

s.event_name

VARCHAR(128)

2

s.num_of_calls

INTEGER。调用该脚本的次数。

3

s.minimum_time

INTEGER。以毫秒为单位。此同步过程中执行一个脚本花费的最短时间。

4

s.maximum_time

INTEGER。以毫秒为单位。此同步过程中执行一个脚本花费的最长时间。

5

s.total_time

INTEGER。以毫秒为单位。同步过程中执行所有脚本花费的总时间。(这与同步的时间长度不同。)

6

缺省操作

无。

注释

time_statistics 事件可用于在同步过程中为任何用户收集时间统计信息。并且仅为有相应脚本的事件收集统计信息。该脚本在某一事件发生多次时收集汇总数据。它在进行用户、事件、表之间的时间比较时非常有用。

另请参见
SQL 示例

以下示例将统计信息插入到 time_statistics 表中。

CALL ml_add_connection_script(
  'ver1',
  'time_statistics',
  'INSERT INTO time_statistics (
    id, 
    ml_user, 
    table,
    event_name, 
    number_of_calls, 
    minimum_time, 
    maximum_time, 
    total_time)
   VALUES (
    ts_id.nextval,
    {ml s.username}, 
    {ml s.event_name}, 
    {ml s.number_of_calls}, 
    {ml s.minimum_time}, 
    {ml s.maximum_time}, 
    {ml s.total_time} ) ' )
Java 示例

以下对 MobiLink 系统过程的调用在同步脚本版本 ver1 时将名为 timeStatisticsConnection 的 Java 方法注册为 time_statistics 连接事件的脚本。

CALL ml_add_java_connection_script(
  'ver1',
  'time_statistics',
  'ExamplePackage.ExampleClass.timeStatisticsConnection' )

以下是 Java 方法 timeStatisticsConnection 示例。它输出 prepare_for_download 事件的统计信息。(请注意:将统计信息输出到 MobiLink 消息日志在开发时可能会有帮助,但会降低生产服务器的性能。)

public String timeStatisticsConnection(
  String username,
  String tableName,
  String eventName,
  int numberOfCalls, 
  int minimumTime, 
  int maximumTime,
  int totalTime ) {
  if( eventName.equals( "prepare_for_download") ) {
    java.lang.System.out.println(
     "prepare_for_download num_calls: " + numCalls +
     "total_time: " + totalTime ); 
  }
  return ( null );
}
.NET 示例

以下对 MobiLink 系统过程的调用在同步脚本版本 ver1 时将名为 TimeStats 的 .NET 方法注册为 time_statistics 连接事件的脚本。

CALL ml_add_dnet_connection_script(
  'ver1',
  'time_statistics',
  'TestScripts.Test.TimeStats'
)

以下是 .NET 方法 TimeStats 示例。它输出 prepare_for_download 事件的统计信息。(请注意:将统计信息输出到 MobiLink 消息日志在开发时可能会有帮助,但会降低生产服务器的性能。)

public string TimeStats(
  string user,
  string eventName,
  int numberOfCalls,
  int minimumTime,
  int maximumTime,
  int totTime ) {
  if( event_name=="prepare_for_download") {
    System.Console.WriteLine(
     "prepare_for_download num_calls: " + num_calls +
     "total_time: " + total_time ); 
  } 
  return ( null );
}