Revision: 1098
Author: [email protected]
Date: Mon Mar  8 01:45:42 2010
Log: Abstract writing string attribute values into NYTP_write_attribute_string().
http://code.google.com/p/perl-devel-nytprof/source/detail?r=1098

Modified:
 /trunk/FileHandle.h
 /trunk/FileHandle.xs
 /trunk/NYTProf.xs

=======================================
--- /trunk/FileHandle.h Mon Mar  8 01:45:27 2010
+++ /trunk/FileHandle.h Mon Mar  8 01:45:42 2010
@@ -46,3 +46,6 @@
 void NYTProf_croak_if_not_stdio(NYTP_file file, const char *function);

 size_t NYTP_write_comment(NYTP_file ofile, const char *format, ...);
+size_t NYTP_write_attribute_string(NYTP_file ofile,
+                                   const char *key, size_t key_len,
+                                   const char *value, size_t value_len);
=======================================
--- /trunk/FileHandle.xs        Mon Mar  8 01:45:35 2010
+++ /trunk/FileHandle.xs        Mon Mar  8 01:45:42 2010
@@ -649,6 +649,37 @@

     return retval + 2;
 }
+
+size_t
+NYTP_write_attribute_string(NYTP_file ofile,
+                            const char *key, size_t key_len,
+                            const char *value, size_t value_len)
+{
+    size_t total;
+    size_t retval;
+
+    total = retval = NYTP_write(ofile, ":", 1);
+    if (retval != 1)
+        return retval;
+
+    total += retval = NYTP_write(ofile, key, key_len);
+    if (retval != key_len)
+        return retval;
+
+    total += retval = NYTP_write(ofile, "=", 1);
+    if (retval != 1)
+        return retval;
+
+    total += retval = NYTP_write(ofile, value, value_len);
+    if (retval != value_len)
+        return retval;
+
+    total += retval = NYTP_write(ofile, "\n", 1);
+    if (retval != 1)
+        return retval;
+
+    return total;
+}

MODULE = Devel::NYTProf::FileHandle PACKAGE = Devel::NYTProf::FileHandle PREFIX = NYTP_

=======================================
--- /trunk/NYTProf.xs   Mon Mar  8 01:45:27 2010
+++ /trunk/NYTProf.xs   Mon Mar  8 01:45:42 2010
@@ -432,11 +432,16 @@
 static void
 output_header(pTHX)
 {
-    SV *sv;
+    /* $0 - application name */
+    SV *const sv = get_sv("0",GV_ADDWARN);
     time_t basetime = PL_basetime;
     /* This comes back with a terminating \n, and we don't want that.  */
     const char *const basetime_str = ctime(&basetime);
     const STRLEN basetime_str_len = strlen(basetime_str);
+    const char version[] = STRINGIFY(PERL_REVISION) "."
+        STRINGIFY(PERL_VERSION) "." STRINGIFY(PERL_SUBVERSION);
+    STRLEN len;
+    const char *argv0 = SvPV(sv, len);

     assert(out != NULL);
/* File header with "magic" string, with file major and minor version */
@@ -452,15 +457,13 @@
     /* XXX would be good to adopt a proper charset & escaping for these */
     /* $^T */
NYTP_printf(out, ":%s=%lu\n", "basetime", (unsigned long)PL_basetime);
-    NYTP_printf(out, ":%s=%s\n",       "xs_version",    XS_VERSION);
- NYTP_printf(out, ":%s=%d.%d.%d\n", "perl_version", PERL_REVISION, PERL_VERSION, PERL_SUBVERSION); + NYTP_write_attribute_string(out, STR_WITH_LEN("xs_version"), STR_WITH_LEN(XS_VERSION)); + NYTP_write_attribute_string(out, STR_WITH_LEN("perl_version"), version, sizeof(version) - 1);
     NYTP_printf(out, ":%s=%d\n",       "clock_id",      profile_clock);
     NYTP_printf(out, ":%s=%u\n",       "ticks_per_sec", ticks_per_sec);
     NYTP_printf(out, ":%s=%d\n",       "nv_size",       (int)sizeof(NV));
NYTP_printf(out, ":%s=%lu\n", "PL_perldb", (long unsigned int)PL_perldb);
-    /* $0 - application name */
-    sv = get_sv("0",GV_ADDWARN);
-    NYTP_printf(out, ":%s=%s\n",       "application", SvPV_nolen(sv));
+ NYTP_write_attribute_string(out, STR_WITH_LEN("application"), argv0, len);

 #ifdef HAS_ZLIB
     if (compression_level) {

--
You've received this message because you are subscribed to
the Devel::NYTProf Development User group.

Group hosted at:  http://groups.google.com/group/develnytprof-dev
Project hosted at:  http://perl-devel-nytprof.googlecode.com
CPAN distribution:  http://search.cpan.org/dist/Devel-NYTProf

To post, email:  [email protected]
To unsubscribe, email:  [email protected]

Reply via email to