Browse Source

TRACE() instead of ifdef/fprintf

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@305 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
3.0
Xuefer 15 years ago
parent
commit
1609bb2f30
  1. 40
      coverager.c
  2. 45
      mem.c
  3. 10
      mmap.c
  4. 28
      utils.c
  5. 18
      utils.h
  6. 9
      xc_malloc.c
  7. 3
      xc_shm.h
  8. 81
      xcache.c

40
coverager.c

@ -26,9 +26,7 @@ static zend_compile_file_t *origin_compile_file;
static void xc_destroy_coverage(void *pDest) /* {{{ */
{
coverager_t cov = *(coverager_t*) pDest;
#ifdef DEBUG
fprintf(stderr, "destroy %p\n", cov);
#endif
TRACE("destroy %p", cov);
zend_hash_destroy(cov);
efree(cov);
}
@ -38,9 +36,7 @@ void xcache_mkdirs_ex(char *root, int rootlen, char *path, int pathlen TSRMLS_DC
char *fullpath;
struct stat st;
#ifdef DEBUG
fprintf(stderr, "mkdirs %s %d %s %d\n", root, rootlen, path, pathlen);
#endif
TRACE("mkdirs %s %d %s %d", root, rootlen, path, pathlen);
fullpath = do_alloca(rootlen + pathlen + 1);
memcpy(fullpath, root, rootlen);
memcpy(fullpath + rootlen, path, pathlen);
@ -55,9 +51,7 @@ void xcache_mkdirs_ex(char *root, int rootlen, char *path, int pathlen TSRMLS_DC
xcache_mkdirs_ex(root, rootlen, path, chr - path TSRMLS_CC);
*chr = PHP_DIR_SEPARATOR;
}
#ifdef DEBUG
fprintf(stderr, "mkdir %s\n", fullpath);
#endif
TRACE("mkdir %s", fullpath);
#if PHP_MAJOR_VERSION > 5
php_stream_mkdir(fullpath, 0700, REPORT_ERRORS, NULL);
#else
@ -112,9 +106,7 @@ static void xc_coverager_save_cov(char *srcfile, char *outfilename, coverager_t
}
if (newfile) {
#ifdef DEBUG
fprintf(stderr, "new file\n");
#endif
TRACE("%s", "new file");
}
else if (outstat.st_size) {
len = outstat.st_size;
@ -122,9 +114,7 @@ static void xc_coverager_save_cov(char *srcfile, char *outfilename, coverager_t
if (read(fd, (void *) contents, len) != len) {
goto bailout;
}
#ifdef DEBUG
fprintf(stderr, "oldsize %d\n", (int) len);
#endif
TRACE("oldsize %d", (int) len);
do {
p = (long *) contents;
len -= sizeof(long);
@ -132,9 +122,7 @@ static void xc_coverager_save_cov(char *srcfile, char *outfilename, coverager_t
break;
}
if (*p++ != PCOV_HEADER_MAGIC) {
#ifdef DEBUG
fprintf(stderr, "wrong magic in file %s\n", outfilename);
#endif
TRACE("wrong magic in file %s", outfilename);
break;
}
@ -289,9 +277,7 @@ static void xc_coverager_autodump(TSRMLS_D) /* {{{ */
strcpy(outfilename + dumpdir_len, ZSTR_S(s));
strcpy(outfilename + dumpdir_len + size - 1, ".pcov");
#ifdef DEBUG
fprintf(stderr, "outfilename %s\n", outfilename);
#endif
TRACE("outfilename %s", outfilename);
xc_coverager_save_cov(ZSTR_S(s), outfilename, *pcov TSRMLS_CC);
zend_hash_move_forward_ex(XG(coverages), &pos);
}
@ -353,18 +339,14 @@ static coverager_t xc_coverager_get(char *filename TSRMLS_DC) /* {{{ */
coverager_t cov, *pcov;
if (zend_hash_find(XG(coverages), filename, len, (void **) &pcov) == SUCCESS) {
#ifdef DEBUG
fprintf(stderr, "got coverage %s %p\n", filename, *pcov);
#endif
TRACE("got coverage %s %p", filename, *pcov);
return *pcov;
}
else {
cov = emalloc(sizeof(HashTable));
zend_hash_init(cov, 0, NULL, NULL, 0);
zend_hash_add(XG(coverages), filename, len, (void **) &cov, sizeof(cov), NULL);
#ifdef DEBUG
fprintf(stderr, "new coverage %s %p\n", filename, cov);
#endif
TRACE("new coverage %s %p", filename, cov);
return cov;
}
}
@ -533,9 +515,7 @@ PHP_FUNCTION(xcache_coverager_decode)
return;
}
if (*p++ != PCOV_HEADER_MAGIC) {
#ifdef DEBUG
fprintf(stderr, "wrong magic in xcache_coverager_decode");
#endif
TRACE("%s", "wrong magic in xcache_coverager_decode");
return;
}

45
mem.c

@ -14,9 +14,9 @@
#include "align.h"
#ifdef TEST
# define ALLOC_DEBUG
# define DEBUG
#endif
#ifdef ALLOC_DEBUG
#ifdef DEBUG
# define ALLOC_DEBUG_BLOCK_CHECK
#endif
@ -90,19 +90,15 @@ static XC_MEM_MALLOC(xc_mem_malloc) /* {{{ */
/* realsize is ALIGNed so next block start at ALIGNed address */
realsize = ALIGN(realsize);
#ifdef ALLOC_DEBUG
fprintf(stderr, "avail: %d (%dKB). Allocate size: %d realsize: %d (%dKB)"
TRACE("avail: %d (%dKB). Allocate size: %d realsize: %d (%dKB)"
, mem->avail, mem->avail / 1024
, size
, realsize, realsize / 1024
);
#endif
do {
p = NULL;
if (mem->avail < realsize) {
#ifdef ALLOC_DEBUG
fprintf(stderr, " oom\n");
#endif
TRACE(" oom");
break;
}
@ -131,9 +127,7 @@ static XC_MEM_MALLOC(xc_mem_malloc) /* {{{ */
}
if (b == NULL) {
#ifdef ALLOC_DEBUG
fprintf(stderr, " no fit chunk\n");
#endif
TRACE(" no fit chunk");
break;
}
@ -148,9 +142,7 @@ static XC_MEM_MALLOC(xc_mem_malloc) /* {{{ */
/* perfect fit, just unlink */
if (cur->size == realsize) {
prev->next = cur->next;
#ifdef ALLOC_DEBUG
fprintf(stderr, " perfect fit. Got: %p\n", p);
#endif
TRACE(" perfect fit. Got: %p", p);
break;
}
@ -168,14 +160,12 @@ static XC_MEM_MALLOC(xc_mem_malloc) /* {{{ */
* `--^
*/
#ifdef ALLOC_DEBUG
fprintf(stderr, " -> avail: %d (%dKB). new next: %p offset: %d %dKB. Got: %p\n"
TRACE(" -> avail: %d (%dKB). new next: %p offset: %d %dKB. Got: %p"
, mem->avail, mem->avail / 1024
, newb
, PSUB(newb, mem), PSUB(newb, mem) / 1024
, p
);
#endif
prev->next = newb;
/* prev|cur|newb|next
* `-----^
@ -192,10 +182,7 @@ static XC_MEM_FREE(xc_mem_free) /* {{{ return block size freed */
int size;
cur = (xc_block_t *) (CHAR_PTR(p) - BLOCK_HEADER_SIZE());
#ifdef ALLOC_DEBUG
fprintf(stderr, "freeing: %p", p);
fprintf(stderr, ", size=%d", cur->size);
#endif
TRACE("freeing: %p, size=%d", p, cur->size);
xc_block_check(cur);
assert((char*)mem < (char*)cur && (char*)cur < (char*)mem + mem->size);
@ -210,9 +197,7 @@ static XC_MEM_FREE(xc_mem_free) /* {{{ return block size freed */
b->next = cur;
size = cur->size;
#ifdef ALLOC_DEBUG
fprintf(stderr, ", avail %d (%dKB)", mem->avail, mem->avail / 1024);
#endif
TRACE(" avail %d (%dKB)", mem->avail, mem->avail / 1024);
mem->avail += size;
/* combine prev|cur */
@ -220,9 +205,7 @@ static XC_MEM_FREE(xc_mem_free) /* {{{ return block size freed */
b->size += cur->size;
b->next = cur->next;
cur = b;
#ifdef ALLOC_DEBUG
fprintf(stderr, ", combine prev");
#endif
TRACE(" combine prev");
}
/* combine cur|next */
@ -230,13 +213,9 @@ static XC_MEM_FREE(xc_mem_free) /* {{{ return block size freed */
if (PADD(cur, cur->size) == (char *)b) {
cur->size += b->size;
cur->next = b->next;
#ifdef ALLOC_DEBUG
fprintf(stderr, ", combine next");
#endif
TRACE(" combine next");
}
#ifdef ALLOC_DEBUG
fprintf(stderr, " -> avail %d (%dKB)\n", mem->avail, mem->avail / 1024);
#endif
TRACE(" -> avail %d (%dKB)", mem->avail, mem->avail / 1024);
return size;
}
/* }}} */

10
mmap.c

@ -1,6 +1,4 @@
#undef ALLOC_DEBUG
#include <stdio.h>
#include <assert.h>
#include <limits.h>
@ -33,6 +31,7 @@
#include "php.h"
#define XC_SHM_IMPL
#include "xc_shm.h"
#include "utils.h"
#ifndef max
#define max(a, b) ((a) < (b) ? (b) : (a))
@ -54,13 +53,6 @@ struct _xc_shm_t {
#endif
};
#undef NDEBUG
#ifdef ALLOC_DEBUG
# define inline
#else
# define NDEBUG
#endif
#include <assert.h>
/* }}} */
#define CHECK(x, e) do { if ((x) == NULL) { zend_error(E_ERROR, "XCache: " e); goto err; } } while (0)
#define PTR_ADD(ptr, v) (((char *) (ptr)) + (v))

28
utils.c

@ -330,9 +330,7 @@ static int xc_do_early_binding(zend_op_array *op_array, HashTable *class_table,
{
zend_op *opline;
#ifdef DEBUG
fprintf(stderr, "binding %d\n", oplineno);
#endif
TRACE("binding %d", oplineno);
assert(oplineno >= 0);
/* do early binding */
@ -351,9 +349,7 @@ static int xc_do_early_binding(zend_op_array *op_array, HashTable *class_table,
}
parent_name = &(opline - 1)->op2.u.constant;
# ifdef DEBUG
fprintf(stderr, "binding with parent %s\n", Z_STRVAL_P(parent_name));
# endif
TRACE("binding with parent %s", Z_STRVAL_P(parent_name));
if (zend_lookup_class(Z_STRVAL_P(parent_name), Z_STRLEN_P(parent_name), &pce TSRMLS_CC) == FAILURE) {
return FAILURE;
}
@ -368,9 +364,7 @@ static int xc_do_early_binding(zend_op_array *op_array, HashTable *class_table,
&& (opline - 1)->opcode == ZEND_FETCH_CLASS) {
zend_op *fetch_class_opline = opline - 1;
# ifdef DEBUG
fprintf(stderr, "%s %p\n", Z_STRVAL(fetch_class_opline->op2.u.constant), Z_STRVAL(fetch_class_opline->op2.u.constant));
# endif
TRACE("%s %p", Z_STRVAL(fetch_class_opline->op2.u.constant), Z_STRVAL(fetch_class_opline->op2.u.constant));
OP_ZVAL_DTOR(fetch_class_opline->op2);
fetch_class_opline->opcode = ZEND_NOP;
ZEND_VM_SET_OPCODE_HANDLER(fetch_class_opline);
@ -706,3 +700,19 @@ void xc_sandbox_free(xc_sandbox_t *sandbox, int install TSRMLS_DC) /* {{{ */
}
}
/* }}} */
int xc_vtrace(const char *fmt, va_list args) /* {{{ */
{
vfprintf(stderr, fmt, args);
return 0;
}
/* }}} */
int xc_trace(const char *fmt, ...) /* {{{ */
{
va_list args;
va_start(args, fmt);
xc_vtrace(fmt, args);
va_end(args);
return 0;
}
/* }}} */

18
utils.h

@ -1,4 +1,22 @@
#include "php.h"
#include "xcache.h"
#ifdef DEBUG
# define IFDEBUG(x) (x)
# define TRACE(fmt, ...) \
xc_trace("%s:%d: " fmt "\r\n", __FILE__, __LINE__, __VA_ARGS__)
int xc_trace(const char *fmt, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);
# undef NDEBUG
# undef inline
# define inline
#else
# define TRACE(fmt, ...) do { } while (0)
# define IFDEBUG(x) do { } while (0)
# ifndef NDEBUG
# define NDEBUG
# endif
#endif
#include <assert.h>
typedef struct {
int alloc;

9
xc_malloc.c

@ -6,6 +6,7 @@
#include "xc_shm.h"
#include "php.h"
#include "align.h"
#include "utils.h"
struct _xc_mem_t {
const xc_mem_handlers_t *handlers;
@ -111,14 +112,6 @@ struct _xc_shm_t {
xc_shmsize_t size;
xc_shmsize_t memoffset;
};
#undef NDEBUG
#ifdef ALLOC_DEBUG
# define inline
#else
# define NDEBUG
#endif
#include <assert.h>
/* }}} */
static XC_SHM_CAN_READONLY(xc_malloc_can_readonly) /* {{{ */

3
xc_shm.h

@ -1,3 +1,5 @@
#ifndef XC_SHM_H
#define XC_SHM_H
typedef struct _xc_shm_t xc_shm_t;
typedef size_t xc_shmsize_t;
@ -62,3 +64,4 @@ const char *xc_shm_scheme_name(xc_shm_scheme_t *scheme);
xc_shm_t *xc_shm_init(const char *type, xc_shmsize_t size, int readonly_protection, const void *arg1, const void *arg2);
void xc_shm_destroy(xc_shm_t *shm);
#endif

81
xcache.c

@ -29,20 +29,9 @@
#include "stack.h"
#include "xcache_globals.h"
#include "processor.h"
#include "utils.h"
#include "const_string.h"
#include "opcode_spec.h"
#ifdef DEBUG
# undef NDEBUG
# undef inline
# define inline
#else
# ifndef NDEBUG
# define NDEBUG
# endif
#endif
#include <assert.h>
#include "utils.h"
#define VAR_ENTRY_EXPIRED(pentry) ((pentry)->ttl && XG(request_time) > pentry->ctime + (pentry)->ttl)
#define CHECK(x, e) do { if ((x) == NULL) { zend_error(E_ERROR, "XCache: " e); goto err; } } while (0)
@ -242,9 +231,7 @@ static xc_entry_t *xc_entry_find_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */
/* }}} */
static void xc_entry_hold_php_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */
{
#ifdef DEBUG
fprintf(stderr, "hold %s\n", xce->name.str.val);
#endif
TRACE("hold %s", xce->name.str.val);
xce->refcount ++;
xc_stack_push(&XG(php_holds)[xce->cache->cacheid], (void *)xce);
}
@ -289,9 +276,7 @@ static void xc_entry_apply_dmz(xc_cache_t *cache, cache_apply_dmz_func_t apply_f
*/
static XC_ENTRY_APPLY_FUNC(xc_gc_expires_php_entry_dmz) /* {{{ */
{
#ifdef DEBUG
fprintf(stderr, "ttl %lu, %lu %lu\n", (zend_ulong) XG(request_time), (zend_ulong) entry->atime, xc_php_ttl);
#endif
TRACE("ttl %lu, %lu %lu", (zend_ulong) XG(request_time), (zend_ulong) entry->atime, xc_php_ttl);
if (XG(request_time) > entry->atime + xc_php_ttl) {
return 1;
}
@ -308,9 +293,7 @@ static XC_ENTRY_APPLY_FUNC(xc_gc_expires_var_entry_dmz) /* {{{ */
/* }}} */
static void xc_gc_expires_one(xc_cache_t *cache, zend_ulong gc_interval, cache_apply_dmz_func_t apply_func TSRMLS_DC) /* {{{ */
{
#ifdef DEBUG
fprintf(stderr, "interval %lu, %lu %lu\n", (zend_ulong) XG(request_time), (zend_ulong) cache->last_gc_expires, gc_interval);
#endif
TRACE("interval %lu, %lu %lu", (zend_ulong) XG(request_time), (zend_ulong) cache->last_gc_expires, gc_interval);
if (XG(request_time) - cache->last_gc_expires >= gc_interval) {
ENTER_LOCK(cache) {
if (XG(request_time) - cache->last_gc_expires >= gc_interval) {
@ -622,17 +605,13 @@ static inline void xc_entry_unholds_real(xc_stack_t *holds, xc_cache_t **caches,
for (i = 0; i < cachecount; i ++) {
s = &holds[i];
#ifdef DEBUG
fprintf(stderr, "holded %d\n", xc_stack_size(s));
#endif
TRACE("holded %d", xc_stack_size(s));
if (xc_stack_size(s)) {
cache = ((xc_entry_t *)xc_stack_top(s))->cache;
ENTER_LOCK(cache) {
while (xc_stack_size(s)) {
xce = (xc_entry_t*) xc_stack_pop(s);
#ifdef DEBUG
fprintf(stderr, "unhold %s\n", xce->name.str.val);
#endif
TRACE("unhold %s", xce->name.str.val);
xce->refcount --;
assert(xce->refcount >= 0);
}
@ -810,9 +789,7 @@ static void xc_cache_early_binding_class_cb(zend_op *opline, int oplineno, void
if (zend_hash_find(CG(class_table), class_name, class_len, (void **) &cest) == FAILURE) {
assert(0);
}
#ifdef DEBUG
fprintf(stderr, "got ZEND_DECLARE_INHERITED_CLASS: %s\n", class_name + 1);
#endif
TRACE("got ZEND_DECLARE_INHERITED_CLASS: %s", class_name + 1);
/* let's see which class */
for (i = 0; i < php->classinfo_cnt; i ++) {
if (memcmp(ZSTR_S(php->classinfos[i].key), class_name, class_len) == 0) {
@ -890,9 +867,7 @@ static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) /
stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC);
/* found */
if (stored_xce) {
#ifdef DEBUG
fprintf(stderr, "found %s, catch it\n", stored_xce->name.str.val);
#endif
TRACE("found %s, catch it", stored_xce->name.str.val);
xc_entry_hold_php_dmz(stored_xce TSRMLS_CC);
cache->hits ++;
break;
@ -919,9 +894,7 @@ static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) /
/* }}} */
/* {{{ compile */
#ifdef DEBUG
fprintf(stderr, "compiling %s\n", filename);
#endif
TRACE("compiling %s", filename);
/* make compile inside sandbox */
xc_sandbox_init(&sandbox, filename TSRMLS_CC);
@ -1087,9 +1060,7 @@ static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) /
stored_xce = xc_entry_store_dmz(&xce TSRMLS_CC);
} LEAVE_LOCK_EX(cache);
/* }}} */
#ifdef DEBUG
fprintf(stderr, "stored\n");
#endif
TRACE("%s", "stored");
#define X_FREE(var) \
if (xce.data.php->var) { \
@ -1145,9 +1116,7 @@ restore:
CG(in_compilation) = 1;
CG(compiled_filename) = stored_xce->name.str.val;
CG(zend_lineno) = 0;
#ifdef DEBUG
fprintf(stderr, "restoring %s\n", stored_xce->name.str.val);
#endif
TRACE("restoring %s", stored_xce->name.str.val);
xc_processor_restore_xc_entry_t(&xce, stored_xce, xc_readonly_protection TSRMLS_CC);
#ifdef SHOW_DPRINT
xc_dprint(&xce, 0 TSRMLS_CC);
@ -1180,9 +1149,7 @@ restore:
}
CG(in_compilation) = 0;
CG(compiled_filename) = NULL;
#ifdef DEBUG
fprintf(stderr, "restored %s\n", stored_xce->name.str.val);
#endif
TRACE("restored %s", stored_xce->name.str.val);
return op_array;
}
/* }}} */
@ -1874,14 +1841,10 @@ static inline void xc_var_inc_dec(int inc, INTERNAL_FUNCTION_PARAMETERS) /* {{{
ENTER_LOCK(xce.cache) {
stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC);
if (stored_xce) {
#ifdef DEBUG
fprintf(stderr, "incdec: gotxce %s\n", xce.name.str.val);
#endif
TRACE("incdec: gotxce %s", xce.name.str.val);
/* timeout */
if (VAR_ENTRY_EXPIRED(stored_xce)) {
#ifdef DEBUG
fprintf(stderr, "incdec: expired\n");
#endif
TRACE("%s", "incdec: expired");
xc_entry_remove_dmz(stored_xce TSRMLS_CC);
stored_xce = NULL;
}
@ -1891,9 +1854,7 @@ static inline void xc_var_inc_dec(int inc, INTERNAL_FUNCTION_PARAMETERS) /* {{{
if (Z_TYPE_P(stored_var->value) == IS_LONG) {
stored_xce->ctime = XG(request_time);
stored_xce->ttl = xce.ttl;
#ifdef DEBUG
fprintf(stderr, "incdec: islong\n");
#endif
TRACE("%s", "incdec: islong");
value = Z_LVAL_P(stored_var->value);
value += (inc == 1 ? count : - count);
RETVAL_LONG(value);
@ -1901,9 +1862,7 @@ static inline void xc_var_inc_dec(int inc, INTERNAL_FUNCTION_PARAMETERS) /* {{{
break; /* leave lock */
}
else {
#ifdef DEBUG
fprintf(stderr, "incdec: notlong\n");
#endif
TRACE("%s", "incdec: notlong");
xc_processor_restore_zval(&oldzval, stored_xce->data.var->value, stored_xce->have_references TSRMLS_CC);
convert_to_long(&oldzval);
value = Z_LVAL(oldzval);
@ -1911,11 +1870,9 @@ static inline void xc_var_inc_dec(int inc, INTERNAL_FUNCTION_PARAMETERS) /* {{{
}
}
}
#ifdef DEBUG
else {
fprintf(stderr, "incdec: %s not found\n", xce.name.str.val);
TRACE("incdec: %s not found", xce.name.str.val);
}
#endif
value += (inc == 1 ? count : - count);
RETVAL_LONG(value);
@ -2359,9 +2316,7 @@ static void xc_zend_extension_register(zend_extension *new_extension, DL_HANDLE
zend_extension_dispatch_message(ZEND_EXTMSG_NEW_EXTENSION, &extension);
zend_llist_prepend_element(&zend_extensions, &extension);
#ifdef DEBUG
fprintf(stderr, "registered\n");
#endif
TRACE("%s", "registered");
}
static int xc_zend_extension_startup(zend_extension *extension)

Loading…
Cancel
Save