使用LoadRunner监测MySQL数据库的性能

发表于:2010-3-03 14:09

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:ymsunshine(部分)    来源:51Testing软件测试博客

  方法二:通过编写脚本来进行监控

// mysql_dll.cpp : Defines the entry point for the DLL application.

#include "stdafx.h"
#include "stdlib.h"

MYSQL *conn=NULL;
MYSQL_RES *p_res_ptr=NULL;
MYSQL_ROW sqlrows;


BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
      )
{
    return TRUE;
}

extern "C" int _declspec(dllexport) init_mysql_connection(char *str_server,char *str_username,char *str_pwd,char *str_Table)
{
conn=mysql_init(NULL);

    if(!conn)
{
  printf("\nFailed to initate MySQL connection");
  return 1;
  exit(0);
}
    else
{
  printf("\nSuccess to initate MySQL connection");
  if (!mysql_real_connect(conn,str_server,str_username,str_pwd,str_Table,0,NULL,0))
  {
   printf( "Failed to connect to MySQL: Error: %s\n", mysql_error(conn));
  }
  else
  {
   printf("\nLogged on to %s sucessfully",str_server);
   return 0;
  }
  return 0;
}
}

extern "C" int _declspec(dllexport) close_mysql_connection()
{
if(conn=NULL)
{
  printf("\nConnection is Null");
  return 1;
  exit(0);
}
else
{
     mysql_free_result(p_res_ptr);
  printf("\nClose connection");
  mysql_close(conn);  
  return 0;
}
}

//"show status like \'qcache%\'"

extern "C" int _declspec(dllexport) get_mysql_table_query(char *str_query)
{
int res=0;
res=mysql_query(conn,str_query);
if(res)
{
  printf("Failed to mysql query: Error: %s\n", mysql_error(conn));
  return 1;
}
else
{
  printf("\nSucess in Mysql Query");
  return 0;

}

}

 

extern "C" int _declspec(dllexport) get_mysql_query_data(char *str_query,char *str_data)
{
    unsigned long u1_numrow=0;
    unsigned int i_index = 0;
p_res_ptr=mysql_use_result(conn);

if(p_res_ptr){

  while((sqlrows=mysql_fetch_row(p_res_ptr))){
 
   if(*sqlrows[0]=*str_query)
   {
    strcpy(str_data,sqlrows[1]);
  
  
   }
  }
}

return NULL;

}

 

lr 9.1中代码:
Action()
{

        int i=0;
        double x;
        char *str_data;


        str_data=(char *)malloc(20*sizeof(char));
        lr_load_dll("D:\\vc\\mysql_dll\\Debug\\mysql_dll.dll");
        i= init_mysql_connection("localhost","root","123456","mysql");
        lr_output_message("%d",i);
  
       for(;;)
       {
            get_mysql_query_data("Qcache_hits",str_data);
            i=get_mysql_table_query("show status like \'qcache%\'");
            lr_output_message("%d",i);
            x = atof(str_data);
            lr_user_data_point("hits",x);
            lr_think_time(5);
       }
        lr_output_message("%d",x);
     close_mysql_connection();
return 0;
}

22/2<12
《2023软件测试行业现状调查报告》独家发布~

精彩评论

  • judy_xia
    2015-8-12 16:32:54

    同谢,比较完整,

  • luhaibao
    2010-3-05 09:45:29

    感谢每个这样用心的人......

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号