[svn:parrot] r41198 - trunk/src/runcore

chromatic at svn.parrot.org chromatic at svn.parrot.org
Fri Sep 11 01:13:29 UTC 2009


Author: chromatic
Date: Fri Sep 11 01:13:28 2009
New Revision: 41198
URL: https://trac.parrot.org/parrot/changeset/41198

Log:
[runcore] Tidied code in the profiling runcore; no functional changes.

Modified:
   trunk/src/runcore/profiling.c

Modified: trunk/src/runcore/profiling.c
==============================================================================
--- trunk/src/runcore/profiling.c	Fri Sep 11 00:25:57 2009	(r41197)
+++ trunk/src/runcore/profiling.c	Fri Sep 11 01:13:28 2009	(r41198)
@@ -77,13 +77,14 @@
 
     Parrot_profiling_runcore_t *coredata =
                                  mem_allocate_typed(Parrot_profiling_runcore_t);
-    coredata->name             = CONST_STRING(interp, "profiling");
-    coredata->id               = PARROT_PROFILING_CORE;
-    coredata->opinit           = PARROT_CORE_OPLIB_INIT;
-    coredata->runops           = (Parrot_runcore_runops_fn_t) init_profiling_core;
-    coredata->destroy          = NULL;
-    coredata->prepare_run      = NULL;
-    coredata->flags            = 0;
+
+    coredata->name        = CONST_STRING(interp, "profiling");
+    coredata->id          = PARROT_PROFILING_CORE;
+    coredata->opinit      = PARROT_CORE_OPLIB_INIT;
+    coredata->runops      = (Parrot_runcore_runops_fn_t) init_profiling_core;
+    coredata->destroy     = NULL;
+    coredata->prepare_run = NULL;
+    coredata->flags       = 0;
 
     PARROT_RUNCORE_FUNC_TABLE_SET(coredata);
 
@@ -114,7 +115,6 @@
     profile_output_var = Parrot_getenv("PARROT_PROFILING_OUTPUT", &free_env_var);
 
     if (profile_output_var) {
-
         STRING  *lc_filename;
         runcore->profile_filename = Parrot_str_new(interp, profile_output_var, 0);
         profile_filename          = Parrot_str_to_cstring(interp, runcore->profile_filename);
@@ -128,9 +128,8 @@
             runcore->profile_fd       = stdout;
             runcore->profile_filename = lc_filename;
         }
-        else {
+        else
             runcore->profile_fd = fopen(profile_filename, "w");
-        }
 
         if (free_env_var)
             mem_sys_free(profile_output_var);
@@ -152,7 +151,8 @@
     runcore->runloop_count   = 0;
     runcore->level           = 0;
     runcore->time_size       = 32;
-    runcore->time            = mem_allocate_n_typed(runcore->time_size, UHUGEINTVAL);
+    runcore->time            = mem_allocate_n_typed(runcore->time_size,
+                                                    UHUGEINTVAL);
     Profiling_first_loop_SET(runcore);
 
     if (!runcore->profile_fd) {
@@ -166,6 +166,7 @@
     return runops_profiling_core(interp, runcore, pc);
 }
 
+
 /*
 
 =item C<static opcode_t * runops_profiling_core(PARROT_INTERP,
@@ -186,11 +187,11 @@
 {
     ASSERT_ARGS(runops_profiling_core)
 
-    Parrot_Context_info preop_info, postop_info;
     PMC                *preop_sub, *argv;
     opcode_t           *preop_pc;
-    UHUGEINTVAL         op_time;
     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();
 
@@ -200,12 +201,14 @@
         if (runcore->level >= runcore->time_size) {
             runcore->time_size *= 2;
             runcore->time =
-                mem_realloc_n_typed(runcore->time, runcore->time_size+1, UHUGEINTVAL);
+                mem_realloc_n_typed(runcore->time, runcore->time_size + 1,
+                                    UHUGEINTVAL);
         }
 
         /* store the time between DO_OP and the start of this runcore in this
          * op's running total */
-        runcore->time[runcore->level] = runcore->runcore_start - runcore->op_start;
+        runcore->time[runcore->level] =
+             runcore->runcore_start - runcore->op_start;
     }
 
     Parrot_Context_get_info(interp, CURRENT_CONTEXT(interp), &postop_info);
@@ -213,18 +216,19 @@
     argv = VTABLE_get_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_ARGV_LIST);
 
     if (argv && !Profiling_have_printed_cli_TEST(runcore)) {
-
         /* silly way to avoid line length codingstds nit */
         PMC    *iglobals     = interp->iglobals;
-        PMC    *executable   = VTABLE_get_pmc_keyed_int(interp, iglobals, IGLOBALS_EXECUTABLE);
+        PMC    *executable   = VTABLE_get_pmc_keyed_int(interp, iglobals,
+                                                        IGLOBALS_EXECUTABLE);
         STRING *command_line = Parrot_str_join(interp, CONST_STRING(interp, " "), argv);
 
         char   *exec_cstr, *command_line_cstr;
 
-        exec_cstr         = Parrot_str_to_cstring(interp, VTABLE_get_string(interp, executable));
+        exec_cstr         = Parrot_str_to_cstring(interp,
+                                 VTABLE_get_string(interp, executable));
         command_line_cstr = Parrot_str_to_cstring(interp, command_line);
 
-        /* The CLI line won't reflect any options passed to the parrot binary. */
+        /* CLI line won't reflect any options passed to the parrot binary. */
         fprintf(runcore->profile_fd, "CLI:%s %s\n", exec_cstr, command_line_cstr);
 
         Parrot_str_free_cstring(exec_cstr);
@@ -233,32 +237,31 @@
         Profiling_have_printed_cli_SET(runcore);
     }
 
-
     if (Profiling_first_loop_TEST(runcore)) {
-
         fprintf(runcore->profile_fd, "VERSION:1\n");
-        /* silly hack to make all separate runloops appear to come from a single source */
-        /* NOTE: yes, {x{ foo:bar }x} is ugly an inefficient.  Escaping would
+
+        /* silly hack to make all separate runloops appear to come from a
+         * single source
+         * NOTE: yes, {x{ foo:bar }x} is ugly an inefficient.  Escaping would
          * be more effort but the priority right now is to get the runcore
          * working correctly.  Once all the bugs are ironed out we'll switch to
          * a nice efficient compressed binary format. */
         fprintf(runcore->profile_fd,
-                "CS:{x{ns:main}x}{x{file:no_file}x}{x{sub:0x1}x}{x{ctx:0x1}x}\n");
-        fprintf(runcore->profile_fd,
-                "OP:{x{line:%d}x}{x{time:0}x}{x{op:noop}x}\n", (int) runcore->runloop_count);
+            "CS:{x{ns:main}x}{x{file:no_file}x}{x{sub:0x1}x}{x{ctx:0x1}x}\n"
+            "OP:{x{line:%d}x}{x{time:0}x}{x{op:noop}x}\n",
+             (int) runcore->runloop_count);
+
         runcore->runloop_count++;
         Profiling_first_loop_CLEAR(runcore);
     }
 
     while (pc) {
-
         STRING         *postop_file_name;
         Parrot_Context *preop_ctx;
 
-        if (pc < code_start || pc >= code_end) {
+        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));
@@ -266,13 +269,14 @@
         Parrot_Context_get_info(interp, CURRENT_CONTEXT(interp), &postop_info);
 
         CONTEXT(interp)->current_pc = pc;
-        preop_sub = CONTEXT(interp)->current_sub;
-        preop_pc = pc;
-        preop_ctx = CONTEXT(interp);
+        preop_sub                   = CONTEXT(interp)->current_sub;
+        preop_pc                    = pc;
+        preop_ctx                   = CONTEXT(interp);
 
         runcore->level++;
         Profiling_exit_check_CLEAR(runcore);
-        runcore->op_start = Parrot_hires_get_time();
+
+        runcore->op_start  = Parrot_hires_get_time();
         DO_OP(pc, interp);
         runcore->op_finish = Parrot_hires_get_time();
 
@@ -281,19 +285,21 @@
             op_time += runcore->time[runcore->level];
             runcore->time[runcore->level] = 0;
         }
-        else {
+        else
             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;
+        if (!postop_file_name)
+            postop_file_name = unknown_file;
 
-        /* if current context changed since the last time a CS line was printed... */
+        /* if current context changed since the last printing of a CS line... */
         /* Occasionally the ctx stays the same while the sub changes, possible
          * with a call to a subclass' method. */
-        if ((runcore->prev_ctx != preop_ctx) || runcore->prev_sub != preop_ctx->current_sub) {
+
+        if ((runcore->prev_ctx != preop_ctx)
+        ||   runcore->prev_sub != preop_ctx->current_sub) {
 
             if (preop_ctx->current_sub) {
                 STRING *sub_name;
@@ -303,13 +309,13 @@
                 sub_cstr      = Parrot_str_to_cstring(interp, sub_name);
                 filename_cstr = Parrot_str_to_cstring(interp, postop_file_name);
                 ns_cstr       = Parrot_str_to_cstring(interp,
-                                  VTABLE_get_string(interp, preop_ctx->current_namespace));
+                                    VTABLE_get_string(interp,
+                                        preop_ctx->current_namespace));
 
                 fprintf(runcore->profile_fd,
-                        "CS:{x{ns:%s;%s}x}{x{file:%s}x}{x{sub:0x%p}x}{x{ctx:0x%p}x}\n",
-                        ns_cstr, sub_cstr, filename_cstr,
-                        preop_ctx->current_sub,
-                        preop_ctx);
+                    "CS:{x{ns:%s;%s}x}{x{file:%s}x}{x{sub:0x%p}x}{x{ctx:0x%p}x}\n",
+                    ns_cstr, sub_cstr, filename_cstr,
+                    preop_ctx->current_sub, preop_ctx);
 
                 Parrot_str_free_cstring(sub_cstr);
                 Parrot_str_free_cstring(filename_cstr);
@@ -324,20 +330,23 @@
          * 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. */
-        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,
-                (interp->op_info_table)[*preop_pc].name);
-
-    } /* while (pc) */
+        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,
+            (interp->op_info_table)[*preop_pc].name);
+    }
 
     /* make it easy to tell separate runloops apart */
     if (runcore->level == 0) {
         fprintf(runcore->profile_fd, "END_OF_RUNLOOP\n");
-        /* silly hack to make all separate runloops appear to come from a single source */
-        fprintf(runcore->profile_fd,
-                "CS:{x{ns:main}x}{x{file:no_file}x}{x{sub:0x1}x}{x{ctx:0x1}x}\n");
+
+        /* silly hack to make all separate runloops appear to come from a
+         * single source */
         fprintf(runcore->profile_fd,
-                "OP:{x{line:%d}x}{x{time:0}x}{x{op:noop}x}\n", (int) runcore->runloop_count);
+            "CS:{x{ns:main}x}{x{file:no_file}x}{x{sub:0x1}x}{x{ctx:0x1}x}\n"
+            "OP:{x{line:%d}x}{x{time:0}x}{x{op:noop}x}\n",
+            (int) runcore->runloop_count);
+
         runcore->runloop_count++;
     }
 
@@ -365,9 +374,11 @@
     ASSERT_ARGS(destroy_profiling_core)
 
     char *filename_cstr = Parrot_str_to_cstring(interp, runcore->profile_filename);
-    fprintf(stderr, "\nPROFILING RUNCORE: wrote profile to %s\n", filename_cstr);
-    fprintf(stderr, "Use tools/dev/pprof2cg.pl to generate Callgrind-compatible "
-            "output from this file.\n");
+
+    fprintf(stderr, "\nPROFILING RUNCORE: wrote profile to %s\n"
+        "Use tools/dev/pprof2cg.pl to generate Callgrind-compatible "
+        "output from this file.\n", filename_cstr);
+
     Parrot_str_free_cstring(filename_cstr);
 
     fclose(runcore->profile_fd);


More information about the parrot-commits mailing list