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

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

=======================================
--- /trunk/FileHandle.h Mon Mar  8 01:45:42 2010
+++ /trunk/FileHandle.h Mon Mar  8 01:45:56 2010
@@ -49,3 +49,5 @@
 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 NYTP_write_attribute_signed(NYTP_file ofile, const char *key,
+                                   size_t key_len, long value);
=======================================
--- /trunk/FileHandle.xs        Mon Mar  8 01:45:48 2010
+++ /trunk/FileHandle.xs        Mon Mar  8 01:45:56 2010
@@ -16,6 +16,7 @@

 #define NEED_newRV_noinc
 #define NEED_sv_2pvbyte
+#define NEED_my_snprintf
 #include "ppport.h"

 #ifdef HAS_ZLIB
@@ -680,6 +681,23 @@

     return total;
 }
+
+#ifndef CHAR_BIT
+#  define CHAR_BIT          8
+#endif
+#define LOG_2_OVER_LOG_10   0.30103
+
+size_t
+NYTP_write_attribute_signed(NYTP_file ofile, const char *key,
+                            size_t key_len, long value)
+{
+    /* 3: 1 for rounding errors, 1 for the sign, 1 for the '\0'  */
+    char buffer[(int)(sizeof (long) * CHAR_BIT * LOG_2_OVER_LOG_10 + 3)];
+    const size_t len = my_snprintf(buffer, sizeof(buffer), "%ld", value);
+
+    return NYTP_write_attribute_string(ofile, key, key_len, buffer, len);
+}
+

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

=======================================
--- /trunk/NYTProf.xs   Mon Mar  8 01:45:42 2010
+++ /trunk/NYTProf.xs   Mon Mar  8 01:45:56 2010
@@ -459,7 +459,7 @@
NYTP_printf(out, ":%s=%lu\n", "basetime", (unsigned long)PL_basetime); 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_write_attribute_signed(out, STR_WITH_LEN("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);

--
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