Commits

Mark Shannon committed 55d7b56 Draft

Improve logging info

  • Participants
  • Parent commits c4b2d65

Comments (0)

Files changed (7)

File Include/optimiser.h

     HotPyContext*(*prepare_call2)(HotPyOptimiser*);
     HotPyContext*(*call_object)(HotPyOptimiser*);
     void (*clear)(HotPyOptimiser*);
-    int (*start)(HotPyOptimiser*, HotPyTraceObject*, PyFrameObject*, HotPyContext*);
+    int (*start)(HotPyOptimiser*, HotPyTraceObject*, PyFrameObject*, HotPyContext*, char *reason);
     void (*finish)(HotPyOptimiser*);
     void (*fail)(HotPyOptimiser*, int, char*);
     void (*unrolling)(HotPyOptimiser*);
 int HotPyGuard_AddTraceToSet(PyObject *, PyObject *);
 void HotPyGuard_InvalidateSet(PyObject *);
 
+HotPyReturnValue _HotPy_TraceExcecuteCold(PyThreadState *, HotPyTraceObject *, char *);
+
 #endif /* _HOTPY_OPTIMSER_H */
 

File Python/trace_D_O_C.c

 
 static int
 start(HotPyOptimiser *x, HotPyTraceObject *trace,
-      PyFrameObject *f, HotPyContext *c)
+      PyFrameObject *f, HotPyContext *c, char *reason)
 {
     int i, n;
     HotPy_DOC *opt = (HotPy_DOC *)x;
     else
         create_state_from_frozen(x, c);
     SHOW_FRAME();
-    return x->next->start(x->next, trace, f, c);
+    return x->next->start(x->next, trace, f, c, reason);
 }
 
 static void

File Python/trace_interpreter.c

         else {
             _HotPy_Stats.invalid_exits++;
             Py_DECREF(trace);
-            return HotPyTrace_Execute(tstate, exit_trace);
+            return _HotPy_TraceExcecuteCold(tstate, exit_trace, "trace transfer");
         }
     }
     LOG_FMT("Cold simple or binary exit. Count=%d\n", exit->execution_count);
             if (poly_exit->entries[i].value == value) {
                 exit_trace = poly_exit->entries[i].trace;
                 poly_exit->entries[i].execution_count++;
-                /* XXX - Move up list? */
                 Py_DECREF(value);
                 if (exit_trace)
                     goto execute_trace;
             TRANSFER_TO(exit_trace, exit->exit_context);
         }
         else {
-            _HotPy_Stats.invalid_exits++;
+#ifdef Py_DEBUG
+            char buf[100];
+            sprintf(buf, "Poly object = %lx", (long)value);
             Py_DECREF(trace);
-            return HotPyTrace_Execute(tstate, exit_trace);
+            return _HotPy_TraceExcecuteCold(tstate, exit_trace, buf);
+#else
+            Py_DECREF(trace);
+            return _HotPy_TraceExcecuteCold(tstate, exit_trace, "poly");
+#endif
         }
     }
 rare_exit:

File Python/trace_logger.c

 #define OUT (((HotPyTraceLogger *)x)->out)
 #define INDENT (((HotPyTraceLogger *)x)->indent)
 
-static char *indent_str = "........................";
+static char *indent_str = ".........................................";
 
 static void
 print_str(FILE *out, PyObject *value)
 static HotPyContext *
 require_code(HotPyOptimiser *x, PyObject* v)
 {
-    fprintf(OUT, "%sRequire code: ", INDENT);
-    print_str(OUT, v);
+    PyObject *code;
+    char *kind;
+    if (PyFunction_Check(v)) {
+        kind = "function";
+        code = PyFunction_GET_CODE(v);
+    }
+    else {
+        kind = "generator";
+        code = ((PyGenObject *)v)->gi_code;
+    }
+    fprintf(OUT, "%sRequire (%s) code: ", INDENT, kind);
+    print_str(OUT, code);
     fprintf(OUT, "\n");
     return x->next->require_code(x->next, v);
 }
 }
 
 static int
-start(HotPyOptimiser *x, HotPyTraceObject *trace, PyFrameObject *f, HotPyContext *c)
+start(HotPyOptimiser *x, HotPyTraceObject *trace, PyFrameObject *f, HotPyContext *c, char *reason)
 {
     int i;
-    fprintf(OUT, "Starting Trace at line %d", PyFrame_GetLineNumber(f));
+    fprintf(OUT, "Starting Trace %lx at line %d", (long)trace,
+            PyFrame_GetLineNumber(f));
     fprintf(OUT, " of ");
     print_str(OUT, f->f_code->co_name);
-    fprintf(OUT, "\n--------------\n");
+    fprintf(OUT, "\nReason: %s\n--------------\n", reason);
     INDENT = indent_str + strlen(indent_str);
-    for (i = 0; i < 4; i++) {
-        if (c->cf_instrs[i].code)
-            INDENT -= 1;
+    assert(strlen(indent_str) > HOTPY_CONTEXT_DEPTH);
+    for (i = 0; i < HOTPY_CONTEXT_DEPTH; i++) {
+        if (c->cf_instrs[i].code == NULL)
+            break;
+        INDENT -= 1;
     }
-    return x->next->start(x->next, trace, f, c);
+    return x->next->start(x->next, trace, f, c, reason);
 }
 
 static void
 {
     fprintf(OUT, "%sgen enter\n", INDENT);
     x->next->gen_enter(x->next, code);
+    assert(INDENT > indent_str);
     --INDENT;
 }
 
 {
     fprintf(OUT, "%senter frame\n", INDENT);
     x->next->enter_frame(x->next, code);
+    assert(INDENT > indent_str);
     --INDENT;
 }
 
 {
     fprintf(OUT, "%sleave gen frame\n", INDENT);
     x->next->leave_gen_frame(x->next);
+    assert(INDENT < indent_str + strlen(indent_str));
     ++INDENT;
 }
 
 {
     fprintf(OUT, "%sleave frame\n", INDENT);
     x->next->leave_frame(x->next);
+    assert(INDENT < indent_str + strlen(indent_str));
     ++INDENT;
 }
 

File Python/trace_manager.c

 
 HotPyThresholds _HotPy_Thresholds = { 23, 47, 197 };
 
-static HotPyReturnValue trace_trace(PyThreadState *, HotPyTraceObject *);
-
-
 #ifdef Py_DEBUG
 int valid_ip_here(unsigned char *ip)
 {
 extern HotPyReturnValue _HotPy_TraceRegisterInterpreter(PyThreadState* , HotPyTraceObject *);
 extern HotPyReturnValue _HotPy_TraceInterpreter(PyThreadState* , HotPyTraceObject *);
 
-static HotPyReturnValue
-trace_trace(PyThreadState* ts, HotPyTraceObject *trace)
+HotPyReturnValue
+_HotPy_TraceExcecuteCold(PyThreadState* ts, HotPyTraceObject *trace, char *reason)
 {
     HotPyReturnValue ret;
+    assert(trace->status == TRACE_INVALID);
     trace->execution_count++;
     HotPy_RestoreThreadState(ts, trace->trace_context);
     if (ts->trace_recording > 0 || _Py_TracingPossible ||
     assert(trace->trace_context);
     ts->optimiser->start_context = trace->trace_context;
     ts->optimiser->instruction_count = 0;
-    ts->optimiser->start(ts->optimiser, trace, ts->real_frame, trace->trace_context);
+    ts->optimiser->start(ts->optimiser, trace, ts->real_frame, trace->trace_context, reason);
     ts->trace_recording++;
     assert(ts->real_frame->f_stacktop);
     ret = PyEval_RecordingEval(ts, trace->trace_context, ts->optimiser);
             result = _HotPy_TraceInterpreter(tstate, trace);
     }
     else {
-        assert(trace->status == TRACE_INVALID);
-        result = trace_trace(tstate, trace);
+        result = _HotPy_TraceExcecuteCold(tstate, trace, "top-level");
     }
     assert(tstate->execution_context == NULL);
     return result;
     /* Not expecting loops here */
     ts->optimiser->start_context = exit->exit_context;
     ts->optimiser->instruction_count = 0;
-    ts->optimiser->start(ts->optimiser, trace, ts->real_frame, trace->trace_context);
+    ts->optimiser->start(ts->optimiser, trace, ts->real_frame, trace->trace_context, "raise");
     PyErr_Restore(e_ty, e_ex, e_tb);
     ts->trace_recording++;
     res = _HotPy_RecordUnwinding(ts, ts->optimiser, trace->trace_context);
             /* Ensure decending order and all entries are valid */
             for (i = 0; i < HOTPY_POLYMORPHIC_LIMIT-1; i++)
                 assert(ep0[i].execution_count >= ep0[i+1].execution_count);
-            for (; i < HOTPY_POLYMORPHIC_LIMIT; i++) {
+            for (i = 0; i < HOTPY_POLYMORPHIC_LIMIT; i++) {
                 if (ep0[i].execution_count) {
                     assert(ep0[i].value);
-                    assert(ep0[i].trace);
                 }
                 else {
                     assert(ep0[i].trace == NULL);

File Python/trace_recorder_stack.c

     if (index < 0)
         return NULL;
     if (PyFunction_Check(obj)) {
+        PyObject *code = PyFunction_GET_CODE(obj);
         opcode_with_arg(x, LOAD_SLOT, func_code_def.offset);
-        push_constant(x, PyFunction_GET_CODE(obj));
+        push_constant(x, code);
     }
     else {
         assert(PyGen_Check(obj));

File Python/trace_specialiser.c

 
 static int
 start(HotPyOptimiser *x, HotPyTraceObject *trace,
-      PyFrameObject *f, HotPyContext* context)
+      PyFrameObject *f, HotPyContext* context, char *reason)
 {
     int i;
     HotPySpecialiser *opt = (HotPySpecialiser *)x;
         opt->top_frame = opt->frame_stack[opt->frames-1];
     }
     assert(opt->top_frame);
-    return x->next->start(x->next, trace, f, context);
+    return x->next->start(x->next, trace, f, context, reason);
 }
 
 /* 1 refers to TOS, 2 NOS, etc.