loadrunner监控mysql数据库_使用LoadRunner监测MySQL数据库的性能

// 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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值