[svn:parrot] r40532 - in branches/pluggable_runcore: compilers/imcc include/parrot src src/interp src/runcore

cotto at svn.parrot.org cotto at svn.parrot.org
Thu Aug 13 22:59:48 UTC 2009


Author: cotto
Date: Thu Aug 13 22:59:44 2009
New Revision: 40532
URL: https://trac.parrot.org/parrot/changeset/40532

Log:
[profiling] make the profiling runcore work with the new interface
change "profile_core" to the more grammatical "profiling_core" where applicable
first attempt to make calls and returns explicit in the profile

Modified:
   branches/pluggable_runcore/compilers/imcc/main.c
   branches/pluggable_runcore/include/parrot/interpreter.h
   branches/pluggable_runcore/include/parrot/runcore_api.h
   branches/pluggable_runcore/src/embed.c
   branches/pluggable_runcore/src/interp/inter_misc.c
   branches/pluggable_runcore/src/runcore/cores.c
   branches/pluggable_runcore/src/runcore/main.c

Modified: branches/pluggable_runcore/compilers/imcc/main.c
==============================================================================
--- branches/pluggable_runcore/compilers/imcc/main.c	Thu Aug 13 22:05:57 2009	(r40531)
+++ branches/pluggable_runcore/compilers/imcc/main.c	Thu Aug 13 22:59:44 2009	(r40532)
@@ -389,9 +389,10 @@
                     core |= PARROT_SWITCH_JIT_CORE;
                 else if (STREQ(opt.opt_arg, "exec"))
                     core |= PARROT_EXEC_CORE;
-                else if (STREQ(opt.opt_arg, "trace")) {
+                else if (STREQ(opt.opt_arg, "trace"))
                     core |= PARROT_SLOW_CORE;
-                }
+                else if (STREQ(opt.opt_arg, "profiling"))
+                    core |= PARROT_PROFILING_CORE;
                 else if (STREQ(opt.opt_arg, "gcdebug"))
                     core |= PARROT_GC_DEBUG_CORE;
                 else

Modified: branches/pluggable_runcore/include/parrot/interpreter.h
==============================================================================
--- branches/pluggable_runcore/include/parrot/interpreter.h	Thu Aug 13 22:05:57 2009	(r40531)
+++ branches/pluggable_runcore/include/parrot/interpreter.h	Thu Aug 13 22:59:44 2009	(r40532)
@@ -73,7 +73,7 @@
     PARROT_EXEC_CORE        = 0x20,         /* TODO Parrot_exec_run variants */
     PARROT_GC_DEBUG_CORE    = 0x40,         /* run GC before each op */
     PARROT_DEBUGGER_CORE    = 0x80,         /* used by parrot debugger */
-    PARROT_PROFILE_CORE     = 0x160         /* used by parrot debugger */
+    PARROT_PROFILING_CORE   = 0x160         /* used by parrot debugger */
 } Parrot_Run_core_t;
 /* &end_gen */
 

Modified: branches/pluggable_runcore/include/parrot/runcore_api.h
==============================================================================
--- branches/pluggable_runcore/include/parrot/runcore_api.h	Thu Aug 13 22:05:57 2009	(r40531)
+++ branches/pluggable_runcore/include/parrot/runcore_api.h	Thu Aug 13 22:59:44 2009	(r40532)
@@ -211,6 +211,9 @@
 void Parrot_runcore_jit_init(PARROT_INTERP)
         __attribute__nonnull__(1);
 
+void Parrot_runcore_profiling_init(PARROT_INTERP)
+        __attribute__nonnull__(1);
+
 void Parrot_runcore_slow_init(PARROT_INTERP)
         __attribute__nonnull__(1);
 
@@ -248,6 +251,8 @@
        PARROT_ASSERT_ARG(interp)
 #define ASSERT_ARGS_Parrot_runcore_jit_init __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp)
+#define ASSERT_ARGS_Parrot_runcore_profiling_init __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+       PARROT_ASSERT_ARG(interp)
 #define ASSERT_ARGS_Parrot_runcore_slow_init __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp)
 #define ASSERT_ARGS_Parrot_runcore_switch_init __attribute__unused__ int _ASSERT_ARGS_CHECK = \

Modified: branches/pluggable_runcore/src/embed.c
==============================================================================
--- branches/pluggable_runcore/src/embed.c	Thu Aug 13 22:05:57 2009	(r40531)
+++ branches/pluggable_runcore/src/embed.c	Thu Aug 13 22:59:44 2009	(r40532)
@@ -381,6 +381,9 @@
         case PARROT_DEBUGGER_CORE:
             Parrot_runcore_switch(interp, Parrot_str_new_constant(interp, "debugger"));
             break;
+        case PARROT_PROFILING_CORE:
+            Parrot_runcore_switch(interp, Parrot_str_new_constant(interp, "profiling"));
+            break;
         default:
             Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED,
                 "Invalid runcore requested\n");

Modified: branches/pluggable_runcore/src/interp/inter_misc.c
==============================================================================
--- branches/pluggable_runcore/src/interp/inter_misc.c	Thu Aug 13 22:05:57 2009	(r40531)
+++ branches/pluggable_runcore/src/interp/inter_misc.c	Thu Aug 13 22:59:44 2009	(r40532)
@@ -281,8 +281,8 @@
                 ret = PARROT_GC_DEBUG_CORE;
             else if (Parrot_str_equal(interp, name, CONST_STRING(interp, "debugger")))
                 ret = PARROT_DEBUGGER_CORE;
-            else if (Parrot_str_equal(interp, name, CONST_STRING(interp, "profile")))
-                ret = PARROT_PROFILE_CORE;
+            else if (Parrot_str_equal(interp, name, CONST_STRING(interp, "profiling")))
+                ret = PARROT_PROFILING_CORE;
             break;
         }
         default:        /* or a warning only? */

Modified: branches/pluggable_runcore/src/runcore/cores.c
==============================================================================
--- branches/pluggable_runcore/src/runcore/cores.c	Thu Aug 13 22:05:57 2009	(r40531)
+++ branches/pluggable_runcore/src/runcore/cores.c	Thu Aug 13 22:59:44 2009	(r40532)
@@ -328,7 +328,7 @@
 
 PARROT_WARN_UNUSED_RESULT
 PARROT_CAN_RETURN_NULL
-static opcode_t * runops_profile_core(PARROT_INTERP,
+static opcode_t * runops_profiling_core(PARROT_INTERP,
     ARGIN(Parrot_runcore_t *runcore),
     ARGIN(opcode_t *pc))
         __attribute__nonnull__(1)
@@ -390,7 +390,7 @@
        PARROT_ASSERT_ARG(interp) \
     || PARROT_ASSERT_ARG(runcore) \
     || PARROT_ASSERT_ARG(pc)
-#define ASSERT_ARGS_runops_profile_core __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+#define ASSERT_ARGS_runops_profiling_core __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp) \
     || PARROT_ASSERT_ARG(runcore) \
     || PARROT_ASSERT_ARG(pc)
@@ -730,6 +730,34 @@
 
 /*
 
+=item C<void Parrot_runcore_profiling_init(PARROT_INTERP)>
+
+Registers the profiling runcore with Parrot.
+
+=cut
+
+*/
+
+void
+Parrot_runcore_profiling_init(PARROT_INTERP)
+{
+    ASSERT_ARGS(Parrot_runcore_profiling_init)
+
+    Parrot_runcore_t *coredata = mem_allocate_typed(Parrot_runcore_t);
+    coredata->name             = CONST_STRING(interp, "profiling");
+    coredata->opinit           = PARROT_CORE_OPLIB_INIT;
+    coredata->runops           = runops_profiling_core;
+    coredata->prepare_run      = NULL;
+    coredata->destroy          = NULL;
+
+    PARROT_RUNCORE_FUNC_TABLE_SET(coredata);
+
+    Parrot_runcore_register(interp, coredata);
+}
+
+
+/*
+
 =item C<static opcode_t * runops_fast_core(PARROT_INTERP, Parrot_runcore_t
 *runcore, opcode_t *pc)>
 
@@ -971,7 +999,7 @@
 
 /*
 
-=item C<static opcode_t * runops_profile_core(PARROT_INTERP, Parrot_runcore_t
+=item C<static opcode_t * runops_profiling_core(PARROT_INTERP, Parrot_runcore_t
 *runcore, opcode_t *pc)>
 
 Runs the Parrot operations starting at C<pc> until there are no more
@@ -984,11 +1012,10 @@
 PARROT_WARN_UNUSED_RESULT
 PARROT_CAN_RETURN_NULL
 static opcode_t *
-runops_profile_core(PARROT_INTERP, ARGIN(Parrot_runcore_t *runcore), ARGIN(opcode_t *pc))
+runops_profiling_core(PARROT_INTERP, ARGIN(Parrot_runcore_t *runcore), ARGIN(opcode_t *pc))
 {
-    ASSERT_ARGS(runops_profile_core)
-
-    Parrot_Context_info prev_info, curr_info;
+    ASSERT_ARGS(runops_profiling_core)
+            Parrot_Context_info prev_info, curr_info;
     Parrot_Context     *prev_ctx;
     struct timespec     preop, postop;
     opcode_t           *prev_pc;
@@ -1010,7 +1037,7 @@
     }
 
     interp_counter++;
-    fprintf(prof_fd, "NEW RUNLOOP (%d)\n", interp_counter);
+    fprintf(prof_fd, "#NEW RUNLOOP (%d)\n", interp_counter);
 
     prev_ctx = CONTEXT(interp);
     Parrot_Context_get_info(interp, CONTEXT(interp), &curr_info);
@@ -1037,8 +1064,8 @@
         sub_preop  = prev_info.subname->strstart;
 
         CONTEXT(interp)->current_pc = pc;
-        prev_ctx                    = CONTEXT(interp);
-        prev_pc                     = pc;
+        prev_ctx = CONTEXT(interp);
+        prev_pc = pc;
         clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &preop);
         DO_OP(pc, interp);
         clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &postop);
@@ -1055,26 +1082,75 @@
         if (!sub_postop)  sub_postop  = unknown_sub;
 
         if (prev_pc) {
+
+            PMC                 *invoked;
+            Parrot_Context_info  info;
+
             if (strcmp(file_preop, file_postop))
                 fprintf(prof_fd, "F:%s\n", file_postop);
             if (strcmp(sub_preop, sub_postop))
                 fprintf(prof_fd, "S:%s;%s\n",
                         VTABLE_get_string(interp, prev_ctx->current_namespace)->strstart,
                         sub_postop);
-            fprintf(prof_fd, "%d:%lli:%d:%s\n",
-                    curr_info.line, op_time, (int)CONTEXT(interp)->recursion_depth,
-                    (interp->op_info_table)[*prev_pc].name);
+
+            /* if an invokable thing was invoked, note which namespace we're in now */
+            switch (*prev_pc) {
+                case PARROT_OP_invokecc_p:
+                case PARROT_OP_invoke_p_p:
+
+                case PARROT_OP_callmethod_p_s_p:
+                case PARROT_OP_callmethod_p_sc_p:
+                case PARROT_OP_callmethod_p_p_p:
+
+                case PARROT_OP_callmethodcc_p_s:
+                case PARROT_OP_callmethodcc_p_sc:
+                case PARROT_OP_callmethodcc_p_p:
+
+                    Parrot_Context_get_info(interp, CONTEXT(interp), &info);
+
+                    if (info.subname->strstart && strcmp(sub_postop, info.subname->strstart)) {
+                        fprintf(prof_fd, "%d:%lli:%s calls to %s\n",
+                                curr_info.line, op_time,
+                                (interp->op_info_table)[*prev_pc].name,
+                                info.fullname->strstart);
+                        break;
+                    }
+                    /* intentional fallthrough if we're not in a new sub */
+
+                case PARROT_OP_returncc:
+                case PARROT_OP_yield:
+                case PARROT_OP_tailcall_p:
+                case PARROT_OP_tailcallmethod_p_s:
+                case PARROT_OP_tailcallmethod_p_sc:
+                case PARROT_OP_tailcallmethod_p_p:
+
+                    Parrot_Context_get_info(interp, CONTEXT(interp), &info);
+
+                    if (info.subname->strstart && strcmp(sub_postop, info.subname->strstart)) {
+                        fprintf(prof_fd, "%d:%lli:%s returns to %s\n",
+                                curr_info.line, op_time,
+                                (interp->op_info_table)[*prev_pc].name,
+                                info.fullname->strstart);
+                        break;
+                    }
+                    /* intentional fallthrough if we're not in a new sub */
+
+                default:
+                    fprintf(prof_fd, "%d:%lli:%s\n",
+                            curr_info.line, op_time,
+                            (interp->op_info_table)[*prev_pc].name);
+            }
+
         }
     }
 
-    fprintf(prof_fd, "END OF RUNLOOP (%d)\n", interp_counter);
+    fprintf(prof_fd, "#END OF RUNLOOP (%d)\n", interp_counter);
     interp_counter--;
 
     if (interp_counter == 0)
         fclose(prof_fd);
     return pc;
 
-
 }
 
 #undef code_start

Modified: branches/pluggable_runcore/src/runcore/main.c
==============================================================================
--- branches/pluggable_runcore/src/runcore/main.c	Thu Aug 13 22:05:57 2009	(r40531)
+++ branches/pluggable_runcore/src/runcore/main.c	Thu Aug 13 22:59:44 2009	(r40532)
@@ -139,6 +139,8 @@
     Parrot_runcore_gc_debug_init(interp);
     Parrot_runcore_debugger_init(interp);
 
+    Parrot_runcore_profiling_init(interp);
+
 #ifdef HAVE_COMPUTED_GOTO
     Parrot_runcore_cgp_init(interp);
     Parrot_runcore_cgoto_init(interp);


More information about the parrot-commits mailing list