removed profiler stuff

This commit is contained in:
Georg Richter 2003-12-13 00:46:48 +00:00
parent 8b3b1c192b
commit bef6368dee
4 changed files with 0 additions and 875 deletions

View File

@ -1,496 +0,0 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2003 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_0.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Georg Richter <georg@php.net> |
+----------------------------------------------------------------------+
$Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_mysqli.h"
#include "mysqli_profiler_com.h"
/* {{{ PR_COMMON *php_mysqli_profiler_new_object(PR_COMMON *parent, unsigned int type, unsigned int settime) */
PR_COMMON *php_mysqli_profiler_new_object(PR_COMMON *parent, unsigned int type, unsigned int settime)
{
PR_COMMON *prnew, *child;
TSRMLS_FETCH();
switch (type) {
case MYSQLI_PR_MYSQL:
prnew = (PR_COMMON *)ecalloc(1, sizeof(PR_MYSQL));
break;
case MYSQLI_PR_QUERY:
prnew = (PR_COMMON *)ecalloc(1, sizeof(PR_QUERY));
break;
case MYSQLI_PR_STMT:
prnew = (PR_COMMON *)ecalloc(1, sizeof(PR_STMT));
break;
case MYSQLI_PR_COMMAND:
prnew = (PR_COMMON *)ecalloc(1, sizeof(PR_COMMAND));
break;
case MYSQLI_PR_RESULT:
prnew = (PR_COMMON *)ecalloc(1, sizeof(PR_RESULT));
break;
default:
return NULL;
}
prnew->header.type = type;
prnew->header.filename = estrdup(zend_get_executed_filename(TSRMLS_C));
prnew->header.lineno = zend_get_executed_lineno(TSRMLS_C);
prnew->header.functionname = estrdup(get_active_function_name(TSRMLS_C));
if (settime) {
gettimeofday(&prnew->header.starttime, NULL);
}
if (!parent) {
return prnew;
}
if (!parent->header.child) {
parent->header.child = (void *)prnew;
return (prnew);
}
child = parent->header.child;
while (child->header.next != NULL) {
child = child->header.next;
}
child->header.next = (void *)prnew;
return (prnew);
}
/* }}} */
/* {{{ int *php_mysqli_profiler_explain(PR_EXPLAIN *, PR_HEADER *, MYSQL *, char *) */
int php_mysqli_profiler_explain(PR_EXPLAIN *explain, PR_HEADER *header, MYSQL *mysql, char *query)
{
MYSQL_RES *res;
unsigned int i,j;
MYSQL_FIELD *fields;
MYSQL_ROW row;
char *newquery = (char *)emalloc(strlen(query) + 10);
sprintf (newquery, "EXPLAIN %s", query);
mysql_real_query(mysql, newquery, strlen(newquery));
efree (newquery);
if (mysql_errno(mysql)) {
header->error = mysql_errno(mysql);
header->errormsg = my_estrdup(mysql_error(mysql));
return 0;
}
res = mysql_store_result(mysql);
if (!(explain->exp_cnt = mysql_num_rows(res))) {
return 0;
}
explain->columns = mysql_num_fields(res);
explain->row = (PR_ROW *)safe_emalloc(sizeof(PR_ROW), explain->exp_cnt, 0);
explain->fields = (char **)safe_emalloc(sizeof(char *), explain->columns, 0);
fields = mysql_fetch_fields(res);
for (j=0; j < explain->columns; j++) {
explain->fields[j] = estrdup(fields[j].name);
}
for (i=0; i < explain->exp_cnt; i++) {
explain->row[i].value = (char **)safe_emalloc(sizeof(char *), explain->columns, 0);
row = mysql_fetch_row(res);
for (j=0; j < explain->columns; j++) {
explain->row[i].value[j] = my_estrdup(row[j]);
}
}
mysql_free_result(res);
return 1;
}
/* }}} */
/* {{{ void php_mysqli_profiler_timediff(struct timeval, struct timeval *) */
void php_mysqli_profiler_timediff(struct timeval starttime, struct timeval *elapsed)
{
struct timeval end;
gettimeofday(&end, NULL);
elapsed->tv_sec = end.tv_sec - starttime.tv_sec;
elapsed->tv_usec = end.tv_usec - starttime.tv_usec;
if (elapsed->tv_usec < 0) {
--(elapsed->tv_sec);
elapsed->tv_usec = 1000000;
}
return;
}
/* }}} */
/* {{{ char *php_mysqli_profiler_indent(int) */
char *php_mysqli_profiler_indent(int i)
{
char *ret = (char *)ecalloc(i*4+1, sizeof(char));
memset(ret, 0x20, i*4);
return ret;
}
/* }}} */
/* {{{ void php_mysqli_profiler_report_header(PR_HEADER, char *, char *) */
void php_mysqli_profiler_report_header(PR_HEADER header, char *ident)
{
char buffer[8192];
switch (header.type) {
case MYSQLI_PR_MYSQL:
php_mysqli_profiler_timediff(header.starttime, &header.lifetime);
break;
case MYSQLI_PR_STMT:
php_mysqli_profiler_timediff(header.starttime, &header.lifetime);
break;
case MYSQLI_PR_RESULT:
php_mysqli_profiler_timediff(header.starttime, &header.lifetime);
break;
}
MYSQLI_PROFILER_ADD_ATTR_STRING(buffer, "functionname", header.functionname);
MYSQLI_PROFILER_ADD_STARTTAG(buffer, "fileinfo",0);
MYSQLI_PROFILER_ADD_ATTR_STRING(buffer, "filename", header.filename);
MYSQLI_PROFILER_ADD_ATTR_LONG(buffer, "line", header.lineno);
MYSQLI_PROFILER_ADD_ENDTAG(buffer, "fileinfo");
MYSQLI_PROFILER_ADD_STARTTAG(buffer, "timeinfo",0);
MYSQLI_PROFILER_ADD_ATTR_TIME(buffer, "execution_time", header.elapsedtime.tv_sec, header.elapsedtime.tv_usec);
if (header.lifetime.tv_sec + header.lifetime.tv_usec) {
MYSQLI_PROFILER_ADD_ATTR_TIME(buffer, "life_time", header.lifetime.tv_sec, header.lifetime.tv_usec);
}
MYSQLI_PROFILER_ADD_ENDTAG(buffer, "timeinfo");
if (header.error) {
MYSQLI_PROFILER_ADD_STARTTAG(buffer, "errors",0);
MYSQLI_PROFILER_ADD_ATTR_LONG(buffer, "errno", header.error);
MYSQLI_PROFILER_ADD_ATTR_STRING(buffer, "errmsg", header.errormsg);
MYSQLI_PROFILER_ADD_ENDTAG(buffer, "errors");
}
/* free header */
my_efree(header.functionname);
my_efree(header.filename);
my_efree(header.errormsg);
}
/* }}} */
/* {{{ void php_mysqli_profiler_report_explain(PR_EXPLAIN, char *, char *) */
void php_mysqli_profiler_report_explain(PR_EXPLAIN explain, char *ident)
{
int i, j;
char buffer[8192];
if (explain.query) {
MYSQLI_PROFILER_ADD_ATTR_STRING(buffer, "query_string", explain.query);
}
if (explain.exp_cnt) {
MYSQLI_PROFILER_ADD_STARTTAG(buffer, "explain", 1);
for (i=0; i < explain.exp_cnt; i++) {
for (j=0; j < explain.columns; j++) {
MYSQLI_PROFILER_ADD_ATTR_STRING(buffer, explain.fields[j], explain.row[i].value[j]);
my_efree(explain.row[i].value[j]);
}
efree(explain.row[i].value);
}
MYSQLI_PROFILER_ADD_ENDTAG(buffer, "explain");
}
efree(explain.row);
for (j=0; j < explain.columns; j++) {
my_efree(explain.fields[j]);
}
efree(explain.fields);
/* free explain */
my_efree(explain.query);
}
/* }}} */
/* {{{ php_mysqli_profiler_report_mysql(PR_MYSQL *, int) */
void php_mysqli_profiler_report_mysql(PR_MYSQL *prmysql, int depth)
{
char *ident = php_mysqli_profiler_indent(depth);
char buffer[8192];
php_mysqli_profiler_report_header(prmysql->header, ident);
MYSQLI_PROFILER_ADD_ATTR_STRING(buffer, "hostname", prmysql->hostname);
MYSQLI_PROFILER_ADD_ATTR_STRING(buffer, "user", prmysql->username);
MYSQLI_PROFILER_ADD_ATTR_LONG(buffer, "thread_id", prmysql->thread_id);
if (!prmysql->closed) {
MYSQLI_PROFILER_ADD_STARTTAG(buffer, "warnings",0);
MYSQLI_PROFILER_ADD_ATTR_STRING(buffer, "warning", "connection wasn't closed by mysqli_close()");
MYSQLI_PROFILER_ADD_ENDTAG(buffer, "warnings");
}
my_efree(prmysql->hostname);
my_efree(prmysql->username);
efree(ident);
}
/* }}} */
/* {{{ void php_mysqli_profiler_report_query(PR_QUERY *, int) */
void php_mysqli_profiler_report_query(PR_QUERY *prquery, int depth)
{
char buffer[8192];
char *ident = php_mysqli_profiler_indent(depth);
php_mysqli_profiler_report_header(prquery->header, ident);
php_mysqli_profiler_report_explain(prquery->explain, ident);
if (prquery->affectedrows > 0) {
MYSQLI_PROFILER_ADD_ATTR_LONG(buffer, "affected_rows", prquery->affectedrows);
}
if (prquery->insertid) {
MYSQLI_PROFILER_ADD_ATTR_LONG(buffer, "insert_id", prquery->insertid);
}
efree(ident);
}
/* }}} */
/* {{{ void php_mysqli_profiler_report_stmt(PR_STMT *, int) */
void php_mysqli_profiler_report_stmt(PR_STMT *prstmt, int depth)
{
char *ident = php_mysqli_profiler_indent(depth);
char buffer[8192];
buffer[0] = '\0';
php_mysqli_profiler_report_header(prstmt->header, ident);
php_mysqli_profiler_report_explain(prstmt->explain, ident);
printf("\n");
MYSQLI_PROFILER_OUT(buffer);
efree(ident);
}
/* }}} */
/* {{{ void php_mysqli_profiler_report_result(PR_RESULT *, int) */
void php_mysqli_profiler_report_result(PR_RESULT *prresult, int depth)
{
char *ident = php_mysqli_profiler_indent(depth);
char buffer[8192];
buffer[0] = '\0';
php_mysqli_profiler_report_header(prresult->header, ident);
MYSQLI_PROFILER_ADD_ATTR_LONG(buffer, "columns", prresult->columns);
MYSQLI_PROFILER_ADD_ATTR_LONG(buffer, "rows", prresult->rows);
MYSQLI_PROFILER_ADD_ATTR_LONG(buffer, "fetched_rows", prresult->fetched_rows);
if (!prresult->closed || prresult->fetched_rows != prresult->rows) {
MYSQLI_PROFILER_ADD_STARTTAG(buffer, "warnings",0);
if (!prresult->closed) {
MYSQLI_PROFILER_ADD_ATTR_STRING(buffer, "warning", "resultset wasn't closed by mysqli_free_result()");
}
if (prresult->fetched_rows != prresult->rows) {
MYSQLI_PROFILER_ADD_ATTR_STRING(buffer, "warning", "Not all rows from resultset were fetched.");
}
MYSQLI_PROFILER_ADD_ENDTAG(buffer, "warnings");
}
efree(ident);
}
/* }}} */
/* {{{ void php_mysqli_profiler_report_command(PR_COMMAND *, int) */
void php_mysqli_profiler_report_command(PR_COMMAND *prcommand, int depth)
{
char *ident = php_mysqli_profiler_indent(depth);
char buffer[8192];
buffer[0] = '\0';
php_mysqli_profiler_report_header(prcommand->header, ident);
if (prcommand->returnvalue) {
MYSQLI_PROFILER_ADD_ATTR_STRING(buffer, "return_value", prcommand->returnvalue);
efree(prcommand->returnvalue);
}
efree(ident);
}
/* }}} */
/* {{{ php_mysqli_profiler_report(PR_COMMON *, int) */
void php_mysqli_profiler_report(PR_COMMON *current, int depth)
{
PR_COMMON *child;
PR_COMMON *next;
char buffer[8192];
char tag[50];
char *ident = php_mysqli_profiler_indent(depth);
buffer[0] = '\0';
switch (current->header.type) {
case MYSQLI_PR_MAIN:
{
MYSQLI_PROFILER_ADD_STARTTAG(buffer,"?xml version=\"1.0\" ?", 0);
sprintf((char *)&tag, "protocol origin='PHP5' version='%2.1f'", MYSQLI_PROFILER_PROTOCOL_VERSION);
MYSQLI_PROFILER_ADD_STARTTAG(buffer, tag, 0);
strcpy (tag, "protocol");
}
break;
case MYSQLI_PR_MYSQL:
{
PR_MYSQL *prmysql = (PR_MYSQL *)current;
strcpy(tag, "connection");
MYSQLI_PROFILER_ADD_STARTTAG(buffer, tag, 1);
php_mysqli_profiler_report_mysql(prmysql, depth);
}
break;
case MYSQLI_PR_COMMAND:
{
PR_COMMAND *prcommand = (PR_COMMAND *)current;
strcpy(tag, "command");
MYSQLI_PROFILER_ADD_STARTTAG(buffer, tag, 1);
php_mysqli_profiler_report_command(prcommand, depth);
}
break;
case MYSQLI_PR_RESULT:
{
PR_RESULT *prresult = (PR_RESULT *)current;
strcpy(tag, "resultset");
MYSQLI_PROFILER_ADD_STARTTAG(buffer, tag, 1);
php_mysqli_profiler_report_result(prresult, depth);
}
break;
case MYSQLI_PR_STMT:
case MYSQLI_PR_STMT_RESULT:
{
PR_STMT *prstmt = (PR_STMT *)current;
strcpy(tag, "statement");
MYSQLI_PROFILER_ADD_STARTTAG(buffer, tag, 1);
php_mysqli_profiler_report_stmt(prstmt, depth);
}
break;
case MYSQLI_PR_QUERY:
case MYSQLI_PR_QUERY_RESULT:
{
PR_QUERY *prquery = (PR_QUERY *)current;
strcpy(tag, "query");
MYSQLI_PROFILER_ADD_STARTTAG(buffer, tag, 1);
php_mysqli_profiler_report_query(prquery, depth);
}
break;
}
child = current->header.child;
if (child) {
php_mysqli_profiler_report(child, depth+1);
}
MYSQLI_PROFILER_ADD_ENDTAG(buffer, tag);
next = (current->header.next) ? current->header.next : NULL;
if (next) {
php_mysqli_profiler_report(next, depth);
}
if (current->header.type == MYSQLI_PR_MAIN) {
PR_MAIN *prmain = (PR_MAIN *)current;
my_efree(prmain->name);
}
efree(current);
efree(ident);
return;
}
/* }}} */
/* {{{ proto bool mysqli_profiler (int flags, string info, int port)
*/
PHP_FUNCTION(mysqli_profiler)
{
int flag;
char *name;
int name_len = 0, port = 0;
int connection;
if (MyG(profiler)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Profiler was already started.");
RETURN_FALSE;
}
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|sl", &flag, &name, &name_len, &port) == FAILURE) {
return;
}
switch (flag) {
case MYSQLI_PR_REPORT_STDERR:
prmain = ecalloc(1, sizeof(PR_MAIN));
prmain->mode = flag;
break;
case MYSQLI_PR_REPORT_PORT:
if (!name_len) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Hostname not specified.");
RETURN_FALSE;
}
if (!port) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Portnumber not specified.");
RETURN_FALSE;
}
if (!(connection = php_mysqli_create_socket(name, port))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to host %s on port %d", name, port);
RETURN_FALSE;
}
prmain = ecalloc(1, sizeof(PR_MAIN));
prmain->mode = flag;
prmain->port = port;
prmain->name = my_estrdup(name);
prmain->connection = connection;
break;
case MYSQLI_PR_REPORT_FILE:
if (!name_len) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Filename not specified.");
RETURN_FALSE;
}
prmain = ecalloc(1, sizeof(PR_MAIN));
if (!(prmain->fp = fopen(name, "w"))){
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't write to file %s.", name);
efree(prmain);
RETURN_FALSE;
}
prmain->mode = flag;
prmain->name = my_estrdup(name);
break;
default:
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported flag: %d", flag);
RETURN_FALSE;
}
/* PR_SSEND(port,"<application>");
php_mysqli_close_socket(prmain.connection);
*/
MyG(profiler) = flag;
RETURN_TRUE;
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/

View File

@ -1,228 +0,0 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2003 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_0.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Georg Richter <georg@php.net> |
+----------------------------------------------------------------------+
*/
#ifndef __HAVE_MYSQLI_PROFILER_H__
#define __HAVE_MYSQLI_PROFILER_H__
#ifdef PHP_WIN32
#include "win32/time.h"
#else
#include "sys/time.h"
#endif
#define MYSQLI_PROFILER_PROTOCOL_VERSION 1.0
/* common profiler header struct */
typedef struct {
unsigned int type;
void *child;
void *next;
char *filename;
unsigned int lineno;
char *functionname;
struct timeval starttime;
struct timeval elapsedtime;
struct timeval lifetime;
char *errormsg;
ulong error;
} PR_HEADER;
typedef struct {
char **value;
} PR_ROW;
/* explain output */
typedef struct {
char *query;
unsigned int exp_cnt;
unsigned int columns;
char **fields;
PR_ROW *row;
} PR_EXPLAIN;
/* main profiler */
typedef struct {
PR_HEADER header;
unsigned int mode;
char *name;
int port;
char *info;
int connection;
FILE *fp;
} PR_MAIN;
/* common */
typedef struct {
PR_HEADER header;
} PR_COMMON;
/* connection */
typedef struct {
PR_HEADER header;
unsigned int thread_id;
char *hostname;
char *username;
unsigned int closed;
} PR_MYSQL;
/* resultset */
typedef struct {
PR_HEADER header;
unsigned int columns;
ulong rows;
ulong fields;
ulong fetched_rows;
unsigned int closed;
} PR_RESULT;
/* command */
/* TODO: return values */
typedef struct {
PR_HEADER header;
ulong returntype;
char *returnvalue;
} PR_COMMAND;
/* query */
typedef struct {
PR_HEADER header;
PR_EXPLAIN explain;
ulong affectedrows;
ulong insertid;
} PR_QUERY;
/* statement */
typedef struct {
PR_HEADER header;
PR_EXPLAIN explain;
unsigned int param_cnt;
unsigned int field_cnt;
} PR_STMT;
/* Profiler protofypes */
extern void php_mysqli_profiler_report(PR_COMMON *, int);
extern PR_COMMON *php_mysqli_profiler_new_object(PR_COMMON *parent, unsigned int type, unsigned int settime);
extern void php_mysqli_profiler_result_info(MYSQL_RES *res);
extern int php_mysqli_profiler_explain(PR_EXPLAIN *explain, PR_HEADER *header, MYSQL *mysql, char *query);
extern void php_mysqli_profiler_timediff(struct timeval start, struct timeval *elapsed);
extern PR_MAIN *prmain;
/*** PROFILER MODES ***/
#define MYSQLI_PR_REPORT_STDERR 1
#define MYSQLI_PR_REPORT_PORT 2
#define MYSQLI_PR_REPORT_FILE 3
/*** PROFILER CONSTANTS ***/
#define MYSQLI_PR_MAIN 0
#define MYSQLI_PR_MYSQL 1
#define MYSQLI_PR_QUERY 2
#define MYSQLI_PR_QUERY_RESULT 3
#define MYSQLI_PR_STMT 4
#define MYSQLI_PR_STMT_RESULT 5
#define MYSQLI_PR_RESULT 6
/*** PROFILER MACROS ***/
#define MYSQLI_PROFILER_STARTTIME(ptr) gettimeofday(&ptr->header.starttime, NULL)
#define MYSQLI_PROFILER_ELAPSEDTIME(ptr) php_mysqli_profiler_timediff(ptr->header.starttime, &ptr->header.elapsedtime)
#define MYSQLI_PROFILER_LIFETIME(ptr) php_mysqli_profiler_timediff((ptr)->starttime, &(ptr)->lifetime)
#define MYSQLI_PROFILER_NEW(parent, type, time) php_mysqli_profiler_new_object((PR_COMMON *)parent, type, time)
#define MYSQLI_PROFILER_COMMAND_START(cmd,parent)\
if (MyG(profiler))\
{\
cmd = (PR_COMMAND *)php_mysqli_profiler_new_object((PR_COMMON *)parent, MYSQLI_PR_COMMAND,1);\
} else {\
cmd = NULL;\
}
#define MYSQLI_PROFILER_COMMAND_RETURNLONG(cmd, value)\
if (MyG(profiler))\
{\
char tmp[30];\
sprintf ((char *)&tmp, "%ld", value);\
MYSQLI_PROFILER_ELAPSEDTIME(cmd);\
cmd->returnvalue = my_estrdup(tmp);\
}
#define MYSQLI_PROFILER_COMMAND_RETURNSTRING(cmd, value)\
if (MyG(profiler))\
{\
MYSQLI_PROFILER_ELAPSEDTIME(cmd);\
cmd->returnvalue = my_estrdup(value);\
}
#define MYSQLI_PROFILER_EXPLAIN(explain,header,mysql,query) php_mysqli_profiler_explain(explain,header, mysql, query)
#define MYSQLI_PROFILER_OUT(buffer)\
switch (prmain->mode) {\
case MYSQLI_PR_REPORT_STDERR:\
fprintf(stderr, "%s", buffer);\
break;\
case MYSQLI_PR_REPORT_FILE:\
fprintf(prmain->fp, "%s", buffer);\
break;\
case MYSQLI_PR_REPORT_PORT:\
PR_SSEND(prmain->port,buffer);\
break;\
}\
buffer[0] = '\0';
#define MYSQLI_PROFILER_ADD_STARTTAG(buffer, str, out)\
if (prmain->mode == MYSQLI_PR_REPORT_STDERR) {\
if (out) { \
sprintf((char *)&buffer, "%s[%s]\n", ident, str);\
} \
}\
else {\
sprintf((char *)&buffer, "<%s>\n", str);\
}\
MYSQLI_PROFILER_OUT(buffer);
#define MYSQLI_PROFILER_ADD_ATTR_STRING(buffer, tag, value)\
if (prmain->mode == MYSQLI_PR_REPORT_STDERR) {\
sprintf((char *)&buffer, "%s%s: %s\n", ident, tag, value);\
}\
else {\
sprintf((char *)&buffer, "<%s>%s</%s>\n", tag, value, tag);\
}\
MYSQLI_PROFILER_OUT(buffer);
#define MYSQLI_PROFILER_ADD_ATTR_LONG(buffer, tag, value)\
if (prmain->mode == MYSQLI_PR_REPORT_STDERR) {\
sprintf((char *)&buffer, "%s%s: %ld\n", ident, tag, (long)value);\
}\
else {\
sprintf((char *)&buffer, "<%s>%ld</%s>\n", tag, (long)value, tag);\
}\
MYSQLI_PROFILER_OUT(buffer);
#define MYSQLI_PROFILER_ADD_ATTR_TIME(buffer, tag, sec, usec)\
if (prmain->mode == MYSQLI_PR_REPORT_STDERR) {\
sprintf((char *)&buffer, "%s%s: %ld.%06ld\n", ident, tag, sec, usec);\
}\
else {\
sprintf((char *)&buffer, "<%s>%ld.%06ld</%s>\n", tag, sec, usec, tag);\
}\
MYSQLI_PROFILER_OUT(buffer);
#define MYSQLI_PROFILER_ADD_ENDTAG(buffer, tag)\
if (prmain->mode == MYSQLI_PR_REPORT_STDERR) {\
fprintf(stderr, "\n"); \
} else { \
sprintf((char *)&buffer, "</%s>\n", tag);\
}\
MYSQLI_PROFILER_OUT(buffer);
#endif

View File

@ -1,98 +0,0 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2003 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_0.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Georg Richter <georg@php.net> |
+----------------------------------------------------------------------+
*/
#include <string.h>
#include <sys/types.h>
#include <errno.h>
#ifndef PHP_WIN32
#include <unistd.h>
#endif
#ifdef PHP_WIN32
# include <winsock.h>
# include <process.h>
# include <direct.h>
# include "win32/time.h"
#define PATH_MAX MAX_PATH
#else
# include <sys/socket.h>
# include <netinet/in.h>
# include <arpa/inet.h>
# include <netdb.h>
#endif
#include "mysqli_profiler_com.h"
#ifdef PHP_WIN32
int inet_aton(const char *cp, struct in_addr *inp)
{
inp->s_addr = inet_addr(cp);
if (inp->s_addr == INADDR_NONE) {
return 0;
}
return 1;
}
#endif
/*
* Converts a host name to an IP address. */
static int lookup_hostname (const char *addr, struct in_addr *in)
{
struct hostent *host_info;
if (!inet_aton(addr, in)) {
host_info = gethostbyname(addr);
if (host_info == 0) {
/* Error: unknown host */
return -1;
}
*in = *((struct in_addr *) host_info->h_addr);
}
return 0;
}
/* }}} */
int php_mysqli_create_socket(const char *hostname, int dport)
{
struct sockaddr_in address;
int err = -1;
int sockfd;
memset(&address, 0, sizeof(address));
lookup_hostname(hostname, &address.sin_addr);
address.sin_family = AF_INET;
address.sin_port = htons((unsigned short)dport);
sockfd = socket(address.sin_family, SOCK_STREAM, 0);
if (sockfd == SOCK_ERR) {
return -1;
}
while ((err = connect(sockfd, (struct sockaddr *) &address,
sizeof(address))) == SOCK_ERR && errno == EAGAIN);
if (err < 0) {
PR_SCLOSE(sockfd);
return -1;
}
return sockfd;
}
void php_mysqli_close_socket(int socket)
{
PR_SCLOSE(socket);
}

View File

@ -1,53 +0,0 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2003 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_0.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Georg Richter <georg@php.net> |
+----------------------------------------------------------------------+
*/
#ifndef __HAVE_MYSQLI_PROFILER_COM_H__
#define __HAVE_MYSQLI_PROFILER_COM_H__
#ifdef PHP_WIN32
int inet_aton(const char *cp, struct in_addr *inp);
#endif
#if WIN32|WINNT
# define SOCK_ERR INVALID_SOCKET
# define SOCK_CONN_ERR SOCKET_ERROR
# define SOCK_RECV_ERR SOCKET_ERROR
#else
# define SOCK_ERR -1
# define SOCK_CONN_ERR -1
# define SOCK_RECV_ERR -1
#endif
#if WIN32|WINNT
#define PR_SREAD(a,b,c) recv(a,b,c,0)
#define PR_SCLOSE(a) closesocket(a)
#define PR_SSENDL(a,b,c) send(a,b,c,0)
#define PR_SSEND(a,b) send(a,b,strlen(b),0)
#else
#define PR_SREAD(a,b,c) read(a,b,c)
#define PR_SCLOSE(a) close(a)
#define PR_SSENDL(a,b,c) write(a,b,c)
#define PR_SSEND(a,b) write(a,b,strlen(b))
#endif
/* function prototypes */
int php_mysqli_create_socket(const char *hostname, int dport);
void php_mysqli_close_socket(int socket);
#endif