Skip to content

Commit

Permalink
add pinba_schema_set()
Browse files Browse the repository at this point in the history
  • Loading branch information
tony2001 committed May 28, 2013
1 parent 5b6111c commit 8ea22bd
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ Makefile
*.lo
*.o
*.la
pinba-pb.*
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Pinba 1.1.0 ?? ??? ????
- Reimplemented the extension using protobuf-c instead of C++ Protobuf lib.
- Added memory_footprint field to the data (uses mallinfo() where available).
- Added pinba_timers_get() function.
- Added pinba_schema_set() function.
- Added error message on hostname resolution failure.
- Fixed issue #9 (php segfault on shutdown)

Expand Down
1 change: 1 addition & 0 deletions php_pinba.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ ZEND_BEGIN_MODULE_GLOBALS(pinba) /* {{{ */
char *server_port;
int (*old_sapi_ub_write) (const char *, unsigned int TSRMLS_DC);
char host_name[128];
char schema[17];
char *server_name;
char *script_name;
double request_time;
Expand Down
26 changes: 26 additions & 0 deletions pinba.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,9 @@ static inline int php_pinba_req_data_send(pinba_req_data record, long flags TSRM
request->has_status = 1;
request->memory_footprint = record.memory_footprint;
request->has_memory_footprint = 1;
if (PINBA_G(schema)[0] != '\0') {
request->schema = strdup(PINBA_G(schema));
}

n = zend_hash_num_elements(&dict);

Expand Down Expand Up @@ -1486,6 +1489,28 @@ static PHP_FUNCTION(pinba_hostname_set)
}
/* }}} */

/* {{{ proto bool pinba_schema_set(string custom_schema)
Set custom schema */
static PHP_FUNCTION(pinba_schema_set)
{
char *schema;
int schema_len;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &schema, &schema_len) != SUCCESS) {
return;
}

if (schema_len < sizeof(PINBA_G(schema))) {
memcpy(PINBA_G(schema), schema, schema_len);
PINBA_G(schema)[schema_len] = '\0';
} else {
memcpy(PINBA_G(schema), schema, sizeof(PINBA_G(schema)) - 1);
PINBA_G(schema)[sizeof(PINBA_G(schema))] = '\0';
}
RETURN_TRUE;
}
/* }}} */

/* {{{ proto bool pinba_request_time_set(float time)
Set custom request time */
static PHP_FUNCTION(pinba_request_time_set)
Expand Down Expand Up @@ -1607,6 +1632,7 @@ zend_function_entry pinba_functions[] = {
PHP_FE(pinba_timers_get, NULL)
PHP_FE(pinba_script_name_set, NULL)
PHP_FE(pinba_hostname_set, NULL)
PHP_FE(pinba_schema_set, NULL)
PHP_FE(pinba_request_time_set, NULL)
PHP_FE(pinba_tag_set, NULL)
PHP_FE(pinba_tag_get, NULL)
Expand Down
3 changes: 3 additions & 0 deletions pinba.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ message Request {
optional uint32 status = 16;
optional uint32 memory_footprint = 17;
repeated Request requests = 18;
optional string schema = 19;
repeated uint32 tag_name = 20;
repeated uint32 tag_value = 21;
}

0 comments on commit 8ea22bd

Please sign in to comment.