[svn:parrot] r40919 - in branches/pluggable_runcore: include/parrot src/runcore

cotto at svn.parrot.org cotto at svn.parrot.org
Wed Sep 2 08:16:39 UTC 2009


Author: cotto
Date: Wed Sep  2 08:16:36 2009
New Revision: 40919
URL: https://trac.parrot.org/parrot/changeset/40919

Log:
[profiling] update runcore to what's likely to be the format pprof2cg can use
It's terribly inefficient for now.  Efficiency can come once it's working and well-tested.

Modified:
   branches/pluggable_runcore/include/parrot/runcore_api.h
   branches/pluggable_runcore/src/runcore/cores.c

Modified: branches/pluggable_runcore/include/parrot/runcore_api.h
==============================================================================
--- branches/pluggable_runcore/include/parrot/runcore_api.h	Wed Sep  2 07:29:37 2009	(r40918)
+++ branches/pluggable_runcore/include/parrot/runcore_api.h	Wed Sep  2 08:16:36 2009	(r40919)
@@ -39,9 +39,9 @@
 
 
 typedef enum Parrot_profiling_flags {
-    PROFILING_EXIT_CHECK_FLAG = 1 << 0,
-    PROFILING_FIRST_OP_FLAG   = 1 << 1,
-    PROFILING_NEW_FILE_FLAG   = 1 << 2
+    PROFILING_EXIT_CHECK_FLAG  = 1 << 0,
+    PROFILING_FIRST_OP_FLAG    = 1 << 1,
+    PROFILING_NEW_CONTEXT_FLAG = 1 << 2
 } Parrot_profiling_flags;
 
 struct profiling_runcore_t {
@@ -60,7 +60,7 @@
     Parrot_profiling_flags   profiling_flags;
     FILE                    *profile_fd;
     STRING                  *profile_filename;
-    STRING                  *prev_runloop_filename;
+    Parrot_Context          *prev_ctx;
     UINTVAL                  level;      /* how many nested runloops */
     UINTVAL                  time_size;  /* how big is the following array */
     UHUGEINTVAL             *time;       /* time spent between DO_OP and start/end of a runcore */
@@ -92,10 +92,9 @@
 #define Profiling_first_op_SET(o)   Profiling_flag_SET(FIRST_OP, o)
 #define Profiling_first_op_CLEAR(o) Profiling_flag_CLEAR(FIRST_OP, o)
 
-#define Profiling_new_file_TEST(o)  Profiling_flag_TEST(NEW_FILE, o)
-#define Profiling_new_file_SET(o)   Profiling_flag_SET(NEW_FILE, o)
-#define Profiling_new_file_CLEAR(o) Profiling_flag_CLEAR(NEW_FILE, o)
-
+#define Profiling_new_context_TEST(o)  Profiling_flag_TEST(NEW_CONTEXT, o)
+#define Profiling_new_context_SET(o)   Profiling_flag_SET(NEW_CONTEXT, o)
+#define Profiling_new_context_CLEAR(o) Profiling_flag_CLEAR(NEW_CONTEXT, o)
 
 #define Runcore_flag_SET(runcore, flag) \
     ((runcore)->flags |= flag)

Modified: branches/pluggable_runcore/src/runcore/cores.c
==============================================================================
--- branches/pluggable_runcore/src/runcore/cores.c	Wed Sep  2 07:29:37 2009	(r40918)
+++ branches/pluggable_runcore/src/runcore/cores.c	Wed Sep  2 08:16:36 2009	(r40919)
@@ -1048,7 +1048,6 @@
     runcore->runops  = (Parrot_runcore_runops_fn_t)  runops_profiling_core;
     runcore->destroy = (Parrot_runcore_destroy_fn_t) destroy_profiling_core;
 
-    runcore->prev_runloop_filename = NULL;
     runcore->profiling_flags       = 0;
     runcore->level                 = 0;
     runcore->time_size             = 32;
@@ -1109,10 +1108,10 @@
 
     Parrot_Context_get_info(interp, CONTEXT(interp), &postop_info);
 
-    /* detect if the current file has changed while entering an inner runloop */
-    if (Parrot_str_compare(interp, runcore->prev_runloop_filename, postop_info.file))
-        Profiling_new_file_SET(runcore);
-    runcore->prev_runloop_filename = postop_info.file;
+    /* detect if the current context has changed while entering an inner runloop */
+    if (runcore->prev_ctx && runcore->prev_ctx != CONTEXT(interp))
+        Profiling_new_context_SET(runcore);
+    runcore->prev_ctx = CONTEXT(interp);
 
     if (Profiling_first_op_TEST(runcore)) {
 
@@ -1123,12 +1122,13 @@
         STRING *command_line = Parrot_str_join(interp, CONST_STRING(interp, " "), argv);
 
         /* The CLI line won't reflect any options passed to the parrot binary. */
+        fprintf(runcore->profile_fd, "VERSION:1\n");
         fprintf(runcore->profile_fd, "CLI:%s %s\n",
                 VTABLE_get_string(interp, executable)->strstart, command_line->strstart);
-        fprintf(runcore->profile_fd, "F:%s\n", postop_info.file->strstart);
-        fprintf(runcore->profile_fd, "CS:%s;%s at 0x%X,0x%X\n",
+        fprintf(runcore->profile_fd, "CS:{ns:%s;%s}{file:%s}{sub:0x%X}{ctx:0x%X}\n",
                 VTABLE_get_string(interp, CONTEXT(interp)->current_namespace)->strstart,
                 VTABLE_get_string(interp, CONTEXT(interp)->current_sub)->strstart,
+                postop_info.file->strstart,
                 (unsigned int) CONTEXT(interp)->current_sub,
                 (unsigned int) CONTEXT(interp));
 
@@ -1175,30 +1175,27 @@
         if (!preop_file_name)  preop_file_name  = unknown_file;
         if (!postop_file_name) postop_file_name = unknown_file;
 
-        if (Profiling_new_file_TEST(runcore) ||
-            Parrot_str_compare(interp, preop_file_name, postop_file_name)) {
-            Profiling_new_file_CLEAR(runcore);
-            fprintf(runcore->profile_fd, "F:%s\n", postop_file_name->strstart);
-        }
-
-        fprintf(runcore->profile_fd, "%d:%lli:%s\n",
+        fprintf(runcore->profile_fd, "OP:{line:%d}{time:%lli}{op:%s}\n",
                 postop_info.line, op_time,
                 (interp->op_info_table)[*preop_pc].name);
 
-        /* if the active sub changed while the previous op was executed... */
-        if (preop_sub != CONTEXT(interp)->current_sub) {
+        /* if current context changed during the previous op... */
+        if (Profiling_new_context_TEST(runcore) || preop_sub != CONTEXT(interp)->current_sub) {
 
             /* if the current_sub is null, Parrot's probably done executing */
+            Profiling_new_context_CLEAR(runcore);
             if (CONTEXT(interp)->current_sub) {
                 STRING *sub_name;
                 GETATTR_Sub_name(interp, CONTEXT(interp)->current_sub, sub_name);
-                fprintf(runcore->profile_fd, "CS:%s;%s at 0x%X,0x%X\n",
+                fprintf(runcore->profile_fd, "CS:{ns:%s;%s}{file:%s}{sub:0x%X}{ctx:0x%X}\n",
                         VTABLE_get_string(interp, CONTEXT(interp)->current_namespace)->strstart,
                         sub_name->strstart,
+                        postop_file_name->strstart,
                         (unsigned int) CONTEXT(interp)->current_sub,
                         (unsigned int) CONTEXT(interp));
             }
         }
+
     } /* while (pc) */
 
     if (runcore->level == 0) {


More information about the parrot-commits mailing list