[svn:parrot] r41213 - in trunk: include/parrot src src/runcore

cotto at svn.parrot.org cotto at svn.parrot.org
Fri Sep 11 15:17:49 UTC 2009


Author: cotto
Date: Fri Sep 11 15:17:49 2009
New Revision: 41213
URL: https://trac.parrot.org/parrot/changeset/41213

Log:
[profiling] start using Parrot_Sub_get_x_from_pc, clean some code and add notes on what doesn't dtrt yet

Modified:
   trunk/include/parrot/sub.h
   trunk/src/runcore/profiling.c
   trunk/src/sub.c

Modified: trunk/include/parrot/sub.h
==============================================================================
--- trunk/include/parrot/sub.h	Fri Sep 11 15:12:29 2009	(r41212)
+++ trunk/include/parrot/sub.h	Fri Sep 11 15:17:49 2009	(r41213)
@@ -250,18 +250,14 @@
 
 PARROT_CANNOT_RETURN_NULL
 STRING * Parrot_Sub_get_filename_from_pc(PARROT_INTERP,
-    ARGIN(PMC *subpmc),
-    ARGIN(opcode_t *pc))
-        __attribute__nonnull__(1)
-        __attribute__nonnull__(2)
-        __attribute__nonnull__(3);
+    ARGIN_NULLOK(PMC *subpmc),
+    ARGIN_NULLOK(opcode_t *pc))
+        __attribute__nonnull__(1);
 
 INTVAL Parrot_Sub_get_line_from_pc(PARROT_INTERP,
-    ARGIN(PMC *subpmc),
-    ARGIN(opcode_t *pc))
-        __attribute__nonnull__(1)
-        __attribute__nonnull__(2)
-        __attribute__nonnull__(3);
+    ARGIN_NULLOK(PMC *subpmc),
+    ARGIN_NULLOK(opcode_t *pc))
+        __attribute__nonnull__(1);
 
 #define ASSERT_ARGS_new_ret_continuation_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp)
@@ -305,13 +301,9 @@
     || PARROT_ASSERT_ARG(ctx)
 #define ASSERT_ARGS_Parrot_Sub_get_filename_from_pc \
      __attribute__unused__ int _ASSERT_ARGS_CHECK = \
-       PARROT_ASSERT_ARG(interp) \
-    || PARROT_ASSERT_ARG(subpmc) \
-    || PARROT_ASSERT_ARG(pc)
+       PARROT_ASSERT_ARG(interp)
 #define ASSERT_ARGS_Parrot_Sub_get_line_from_pc __attribute__unused__ int _ASSERT_ARGS_CHECK = \
-       PARROT_ASSERT_ARG(interp) \
-    || PARROT_ASSERT_ARG(subpmc) \
-    || PARROT_ASSERT_ARG(pc)
+       PARROT_ASSERT_ARG(interp)
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 /* HEADERIZER END: src/sub.c */
 

Modified: trunk/src/runcore/profiling.c
==============================================================================
--- trunk/src/runcore/profiling.c	Fri Sep 11 15:12:29 2009	(r41212)
+++ trunk/src/runcore/profiling.c	Fri Sep 11 15:17:49 2009	(r41213)
@@ -191,7 +191,6 @@
     opcode_t           *preop_pc;
     STRING             *unknown_file = CONST_STRING(interp, "<unknown file>");
     UHUGEINTVAL         op_time;
-    Parrot_Context_info preop_info, postop_info;
 
     runcore->runcore_start = Parrot_hires_get_time();
 
@@ -211,8 +210,6 @@
              runcore->runcore_start - runcore->op_start;
     }
 
-    Parrot_Context_get_info(interp, CURRENT_CONTEXT(interp), &postop_info);
-
     argv = VTABLE_get_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_ARGV_LIST);
 
     if (argv && !Profiling_have_printed_cli_TEST(runcore)) {
@@ -256,17 +253,22 @@
     }
 
     while (pc) {
-        STRING         *postop_file_name;
-        Parrot_Context *preop_ctx;
+        STRING         		*postop_filename;
+        Parrot_Context 		*preop_ctx;
+        INTVAL              preop_line;
+        Parrot_Context_info preop_info;
 
         if (pc < code_start || pc >= code_end)
             Parrot_ex_throw_from_c_args(interp, NULL, 1,
                     "attempt to access code outside of current code segment");
 
-        /* avoid an extra call to Parrot_Context_get_info */
-        mem_sys_memcopy(&preop_info, &postop_info, sizeof (Parrot_Context_info));
+        /* Parrot_Sub_get_line_from_pc doesn't return the same line numbers as
+         * Parrot_Context_get_info, so keep both around to make it easy to see
+         * when they're equivalnet. */
+        Parrot_Context_get_info(interp, CURRENT_CONTEXT(interp), &preop_info);
+        preop_line = Parrot_Sub_get_line_from_pc(interp,
+                Parrot_pcc_get_sub(interp, CURRENT_CONTEXT(interp)), pc);
 
-        Parrot_Context_get_info(interp, CURRENT_CONTEXT(interp), &postop_info);
 
         CONTEXT(interp)->current_pc = pc;
         preop_sub                   = CONTEXT(interp)->current_sub;
@@ -289,10 +291,8 @@
             op_time = runcore->op_finish - runcore->op_start;
 
         runcore->level--;
-        postop_file_name = postop_info.file;
-
-        if (!postop_file_name)
-            postop_file_name = unknown_file;
+        postop_filename = Parrot_Sub_get_filename_from_pc(interp,
+                Parrot_pcc_get_sub(interp, CURRENT_CONTEXT(interp)), pc);
 
         /* if current context changed since the last printing of a CS line... */
         /* Occasionally the ctx stays the same while the sub changes, possible
@@ -307,7 +307,7 @@
 
                 GETATTR_Sub_name(interp, preop_ctx->current_sub, sub_name);
                 sub_cstr      = Parrot_str_to_cstring(interp, sub_name);
-                filename_cstr = Parrot_str_to_cstring(interp, postop_file_name);
+                filename_cstr = Parrot_str_to_cstring(interp, postop_filename);
                 ns_cstr       = Parrot_str_to_cstring(interp,
                                     VTABLE_get_string(interp,
                                         preop_ctx->current_namespace));
@@ -326,13 +326,11 @@
             runcore->prev_sub = preop_ctx->current_sub;
         }
 
-        /* I'd expect that preop_info.line would be the right thing to use here
-         * but it gives me obviously incorrect results while postop_info.line
-         * works.  It might be an imcc bug or it might just be me
-         * misunderstanding something. */
+        /* chnage preop_info.line to preop_line to check if
+         * Parrot_Sub_get_line_from_pc dtrt/ */
         fprintf(runcore->profile_fd,
             "OP:{x{line:%d}x}{x{time:%li}x}{x{op:%s}x}\n",
-            postop_info.line, (unsigned long)op_time,
+            (int)preop_info.line, (unsigned long)op_time,
             (interp->op_info_table)[*preop_pc].name);
     }
 

Modified: trunk/src/sub.c
==============================================================================
--- trunk/src/sub.c	Fri Sep 11 15:12:29 2009	(r41212)
+++ trunk/src/sub.c	Fri Sep 11 15:17:49 2009	(r41213)
@@ -282,12 +282,15 @@
 */
 
 INTVAL
-Parrot_Sub_get_line_from_pc(PARROT_INTERP, ARGIN(PMC *subpmc), ARGIN(opcode_t *pc))
+Parrot_Sub_get_line_from_pc(PARROT_INTERP, ARGIN_NULLOK(PMC *subpmc), ARGIN_NULLOK(opcode_t *pc))
 {
     ASSERT_ARGS(Parrot_Sub_get_line_from_pc)
     Parrot_Sub_attributes *sub;
     int                    position;
 
+    if (!subpmc || !pc)
+        return -1;
+
     PMC_get_sub(interp, subpmc, sub);
     position = pc - sub->seg->base.data;
 
@@ -309,13 +312,17 @@
 
 PARROT_CANNOT_RETURN_NULL
 STRING *
-Parrot_Sub_get_filename_from_pc(PARROT_INTERP, ARGIN(PMC *subpmc), ARGIN(opcode_t *pc))
+Parrot_Sub_get_filename_from_pc(PARROT_INTERP, ARGIN_NULLOK(PMC *subpmc),
+        ARGIN_NULLOK(opcode_t *pc))
 {
     ASSERT_ARGS(Parrot_Sub_get_filename_from_pc)
     Parrot_Sub_attributes *sub;
     PackFile_Debug        *debug;
     int                    position;
 
+    if (!subpmc || !pc)
+        return CONST_STRING(interp, "unknown file");
+
     PMC_get_sub(interp, subpmc, sub);
 
     debug    = sub->seg->debugs;


More information about the parrot-commits mailing list