stas 2003/09/03 21:34:05
Modified: t/response/TestAPR perlio.pm
xs/APR/PerlIO apr_perlio.c
Log:
add proper tracing calls
Revision Changes Path
1.24 +4 -0 modperl-2.0/t/response/TestAPR/perlio.pm
Index: perlio.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/t/response/TestAPR/perlio.pm,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -u -r1.23 -r1.24
--- perlio.pm 28 Aug 2003 01:58:32 -0000 1.23
+++ perlio.pm 4 Sep 2003 04:34:05 -0000 1.24
@@ -1,5 +1,9 @@
package TestAPR::perlio;
+# to see what happens inside the io layer, assuming that you built
+# mod_perl with MP_TRACE=1, run:
+# env MOD_PERL_TRACE=o t/TEST -v -trace=debug apr/perlio
+
use strict;
use warnings FATAL => 'all';
1.32 +31 -41 modperl-2.0/xs/APR/PerlIO/apr_perlio.c
Index: apr_perlio.c
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -u -r1.31 -r1.32
--- apr_perlio.c 4 Sep 2003 03:31:50 -0000 1.31
+++ apr_perlio.c 4 Sep 2003 04:34:05 -0000 1.32
@@ -112,11 +112,9 @@
rc = apr_file_open(&st->file, path, apr_flag, APR_OS_DEFAULT, st->pool);
-#ifdef PERLIO_APR_DEBUG
- Perl_warn(aTHX_ "PerlIOAPR_open obj=0x%lx, file=0x%lx, name=%s, rc=%d\n",
- (unsigned long)f, (unsigned long)st->file,
- path ? path : "(UNKNOWN)", rc);
-#endif
+ MP_TRACE_o(MP_FUNC, "obj=0x%lx, file=0x%lx, name=%s, rc=%d",
+ (unsigned long)f, (unsigned long)st->file,
+ path ? path : "(UNKNOWN)", rc);
if (rc != APR_SUCCESS) {
PerlIO_pop(aTHX_ f);
@@ -145,14 +143,11 @@
PerlIOAPR *ost = PerlIOSelf(o, PerlIOAPR);
rc = apr_file_dup(&fst->file, ost->file, ost->pool);
-
-#ifdef PERLIO_APR_DEBUG
- Perl_warn(aTHX_ "PerlIOAPR_dup obj=0x%lx, "
- "file=0x%lx => 0x%lx, rc=%d\n",
- (unsigned long)f,
- (unsigned long)ost->file,
- (unsigned long)fst->file, rc);
-#endif
+
+ MP_TRACE_o(MP_FUNC, "obj=0x%lx, "
+ "file=0x%lx => 0x%lx, rc=%d",
+ (unsigned long)f, (unsigned long)ost->file,
+ (unsigned long)fst->file, rc);
if (rc == APR_SUCCESS) {
fst->pool = ost->pool;
@@ -169,20 +164,24 @@
apr_status_t rc;
rc = apr_file_read(st->file, vbuf, &count);
+
+#ifdef MP_TRACE
+ {
+ const char *trace_buf = (char *)apr_pcalloc(st->pool,
+ sizeof(char*)*count);
+ memcpy((void*)trace_buf, vbuf, count);
+ trace_buf[count] = '\0';
+ MP_TRACE_o(MP_FUNC, "count %d, [%s]", (int)count, (char*) trace_buf);
+ }
+#endif
+
if (rc == APR_EOF) {
PerlIOBase(f)->flags |= PERLIO_F_EOF;
return count;
}
else if (rc != APR_SUCCESS) {
-#ifdef PERLIO_APR_DEBUG
- /* XXX: need to figure way to map APR errno to normal errno,
- * so we can use SETERRNO to make the apr errors available to
- * Perl's $! */
Perl_croak(aTHX_ "failed to read from file: %s",
modperl_apr_strerror(rc));
-#endif
- PerlIOBase(f)->flags |= PERLIO_F_ERROR;
- return -1;
}
return count;
@@ -193,10 +192,7 @@
PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR);
apr_status_t rc;
-#if 0
- Perl_warn(aTHX_ "in write: count %d, %s\n",
- (int)count, (char*) vbuf);
-#endif
+ MP_TRACE_o(MP_FUNC, "count %d, [%s]", (int)count, (char*) vbuf);
rc = apr_file_write(st->file, vbuf, &count);
if (rc == APR_SUCCESS) {
@@ -283,7 +279,7 @@
IV code = PerlIOBase_close(aTHX_ f);
apr_status_t rc;
-#ifdef PERLIO_APR_DEBUG
+#ifdef MP_TRACE
const char *new_path = NULL;
apr_os_file_t os_file;
@@ -297,9 +293,9 @@
Perl_croak(aTHX_ "filedes retrieval failed!");
}
- Perl_warn(aTHX_ "PerlIOAPR_close obj=0x%lx, file=0x%lx, fd=%d, name=%s\n",
- (unsigned long)f, (unsigned long)st->file, os_file,
- new_path ? new_path : "(UNKNOWN)");
+ MP_TRACE_o(MP_FUNC, "obj=0x%lx, file=0x%lx, fd=%d, name=%s",
+ (unsigned long)f, (unsigned long)st->file, os_file,
+ new_path ? new_path : "(UNKNOWN)");
#endif
if (PL_dirty) {
@@ -337,9 +333,7 @@
PerlIO_get_base(f); /* allocate via vtable */
}
-#if 0
- Perl_warn(aTHX_ "ask to fill %d chars\n", count);
-#endif
+ MP_TRACE_o(MP_FUNC, "asked to fill %d chars", count);
rc = apr_file_read(st->file, st->base.ptr, &count);
if (rc != APR_SUCCESS) {
@@ -347,9 +341,7 @@
return -1;
}
-#if 0
- Perl_warn(aTHX_ "got to fill %d chars\n", count);
-#endif
+ MP_TRACE_o(MP_FUNC, "got to fill %d chars", count);
avail = count; /* apr_file_read() sets how many chars were read in count */
if (avail <= 0) {
@@ -468,7 +460,7 @@
st = PerlIOSelf(f, PerlIOAPR);
-#ifdef PERLIO_APR_DEBUG
+#ifdef MP_TRACE
{
apr_status_t rc;
apr_os_file_t os_file;
@@ -479,8 +471,8 @@
croak("filedes retrieval failed!");
}
- Perl_warn(aTHX_ "converting to PerlIO fd %d, mode '%s'\n",
- os_file, mode);
+ MP_TRACE_o(MP_FUNC, "converting to PerlIO fd %d, mode '%s'",
+ os_file, mode);
}
#endif
@@ -550,14 +542,12 @@
Perl_croak(aTHX_ "filedes retrieval failed!");
}
-#ifdef PERLIO_APR_DEBUG
- Perl_warn(aTHX_ "converting fd %d\n", os_file);
-#endif
+ MP_TRACE_o(MP_FUNC, "converting fd %d", os_file);
/* let's try without the dup, it seems to work fine:
fd = PerlLIO_dup(os_file);
- Perl_warn(aTHX_ "fd old: %d, new %d\n", os_file, fd);
+ MP_TRACE_o(MP_FUNC, "fd old: %d, new %d\n", os_file, fd);
if (!(retval = PerlIO_fdopen(fd, mode))) {
...
}