// // Purpose: initialize trace module // void SB_Trace::trace_init3(char *pp_filename, bool pv_unique, char *pp_prefix, bool pv_flush, // flush ignored long long pv_max_size, bool pv_sig_hdlr) { char la_uniquename[PATH_MAX]; FILE *lp_file; if (ip_trace_file != NULL) { trace_flush(); if ((ip_trace_file != stdout) && (ip_trace_file != stderr)) { fclose(ip_trace_file); ip_trace_file = NULL; } } pv_flush = pv_flush; // no-warn iv_trace_max_size = pv_max_size; iv_trace_pid = getpid(); iv_trace_sig_hdlr = pv_sig_hdlr; if (ip_trace_file == NULL) ip_trace_file = stdout; if (pp_prefix != NULL) ip_trace_prefix = pp_prefix; if (pp_filename != NULL) { if (strcmp(pp_filename, "STDOUT") == 0) lp_file = stdout; else if (strcmp(pp_filename, "STDERR") == 0) lp_file = stderr; else if (pv_unique) { sprintf(la_uniquename, "%s%d", pp_filename, getpid()); if ((pv_max_size == 0) || (pv_max_size > INT_MAX)) lp_file = fopen64(la_uniquename, "a"); else lp_file = fopen(la_uniquename, "a"); } else { if ((pv_max_size == 0) || (pv_max_size > INT_MAX)) lp_file = fopen64(pp_filename, "a"); else lp_file = fopen(pp_filename, "a"); } if (lp_file != NULL) { ip_trace_file = lp_file; } } if (ip_trace_file != stderr) { if (iv_trace_set_mem_size > 0) { trace_set_mem(iv_trace_set_mem_size); iv_trace_set_mem_size = -1; } else { trace_flush(); setvbuf(ip_trace_file, NULL, _IOLBF, 0); } } }
void trace_prepre (const char *name, int id) { trace_header (id); trace_format ("%s ...", name); trace_flush (); }
void print_backtrace_and_die(int sig, siginfo_t *info, void *secret) { ucontext_t *uc = secret; unsigned long eip, ebp, addr; eip = uc->uc_mcontext.gregs[IP_REG]; ebp = uc->uc_mcontext.gregs[BP_REG]; addr = (unsigned long) info->si_addr; switch (sig) { case SIGSEGV: trace_printf("SIGSEGV at %s %08lx while accessing memory address %08lx.\n", IP_REG_NAME, eip, addr); break; case SIGILL: trace_printf("SIGILL at %s %08lx\n", sig, IP_REG_NAME, eip); break; default: trace_printf("Signal %d at %s %08lx\n", sig, IP_REG_NAME, eip); break; }; show_registers(uc->uc_mcontext.gregs); print_trace_from(eip, (void *) ebp); trace_flush(); abort(); }
static int wait_event_time(void *p) { MidiEvent *ev = (MidiEvent *)p; int rc, ch; for(;;){ if(ev->time - (current_tick()*play_mode->rate+30)/60 < 0) break; trace_loop(); YieldToAnyThread(); rc = check_apply_control(); if(RC_IS_SKIP_FILE(rc)){ prescan = 0; for(ch = 0; ch < MAX_CHANNELS; ch++){ if(note_channel[ch] != NULL){ NADisposeNoteChannel(gNoteAllocator, note_channel[ch]); note_channel[ch] = NULL; } channel[ch].bank_lsb = 0; channel[ch].bank_msb = 0; } trace_flush(); return rc; } } return RC_NONE; }
void __attribute__((noreturn)) supervisor_task(void) { struct trace_entry trace; uint32_t clk; INF("<%d> started...", thinkos_thread_self()); trace_tail(&trace); clk = thinkos_clock(); for (;;) { struct timeval tv; char s[80]; /* 8Hz periodic task */ clk += 125; thinkos_alarm(clk); while (trace_getnext(&trace, s, sizeof(s)) >= 0) { trace_ts2timeval(&tv, trace.dt); printf("%s %2d.%06d: %s\n", trace_lvl_tab[trace.ref->lvl], (int)tv.tv_sec, (int)tv.tv_usec, s); } trace_flush(&trace); } }
// // Purpose: close // void SB_Trace::trace_close() { if (ip_trace_file != NULL) { trace_flush(); if ((ip_trace_file != stdout) && (ip_trace_file != stderr)) fclose(ip_trace_file); ip_trace_file = NULL; } }
// // Purpose: set memory trace // void SB_Trace::trace_set_mem(int pv_size) { trace_flush(); if (ip_trace_file_buf != NULL) delete [] ip_trace_file_buf; ip_trace_file_buf = new char[pv_size]; if (ip_trace_file != NULL) setvbuf(ip_trace_file, ip_trace_file_buf, _IOFBF, pv_size); else iv_trace_set_mem_size = pv_size; }
// // Purpose: set in-memory trace // void SB_Trace::trace_set_inmem(int pv_size) { if (pv_size < TRACE_MIN_INMEM_SIZE) pv_size = TRACE_MIN_INMEM_SIZE; trace_flush(); if (ip_trace_mem_buf != NULL) delete [] ip_trace_mem_buf; iv_trace_mem_size = pv_size; ip_trace_mem_buf = new char[pv_size]; ip_trace_mem_buf[0] = '\0'; iv_trace_mem_inx = 0; }
static inline void trace_push(struct vm_object *loader, const char *class_name) { assert(trace_classloader_level >= 0); if (opt_trace_classloader) { trace_printf("classloader: %p %*s%s\n", loader, trace_classloader_level, "", class_name); trace_flush(); } ++trace_classloader_level; }
SB_Trace::~SB_Trace() { if (ip_trace_mem_buf != NULL) { fprintf(ip_trace_file, ip_trace_mem_buf); delete [] ip_trace_mem_buf; ip_trace_mem_buf = NULL; } if (ip_trace_file != NULL) { trace_flush(); fclose(ip_trace_file); ip_trace_file = NULL; } if (ip_trace_file_buf != NULL) delete [] ip_trace_file_buf; }
static int acntl(int request, void *arg) { int rc, ch; switch(request) { case PM_REQ_MIDI: if(!prescan) play_event_prescan(arg); rc = wait_event_time(arg); if(RC_IS_SKIP_FILE(rc)) return rc; qt_play_event(arg); return RC_NONE; case PM_REQ_INST_NAME: ch = (int)*(char **)arg; *(char **)arg = instrument_name[ch]; return 0; case PM_REQ_GETSAMPLES: *(int32 *)arg = current_samples(); return 0; case PM_REQ_PLAY_START: init_variable(); case PM_REQ_DISCARD: case PM_REQ_FLUSH: for(ch = 0; ch < MAX_CHANNELS; ch++){ if(note_channel[ch] != NULL){ NADisposeNoteChannel(gNoteAllocator, note_channel[ch]); note_channel[ch] = NULL; } channel[ch].bank_lsb = 0; channel[ch].bank_msb = 0; } trace_flush(); return 0; } return -1; }
static void qmgr_active_done_2_generic(QMGR_MESSAGE *message) { char *myname = "qmgr_active_done_2_generic"; const char *path; struct stat st; int status; /* * A delivery agent marks a queue file as corrupt by changing its * attributes, and by pretending that delivery was deferred. */ if (message->flags && mail_open_ok(MAIL_QUEUE_ACTIVE, message->queue_id, &st, &path) == MAIL_OPEN_NO) { qmgr_active_corrupt(message->queue_id); qmgr_message_free(message); return; } /* * If we did not read all recipients from this file, go read some more, * but remember whether some recipients have to be tried again. * * Throwing away queue files seems bad, especially when they made it this * far into the mail system. Therefore we save bad files to a separate * directory for further inspection by a human being. */ if (message->rcpt_offset > 0) { if (qmgr_message_realloc(message) == 0) { qmgr_active_corrupt(message->queue_id); qmgr_message_free(message); } else { if (message->refcount == 0) qmgr_active_done(message); /* recurse for consistency */ } return; } /* * As a temporary implementation, synchronously inform the sender of * trace information. This will block for 10 seconds when the qmgr FIFO * is full. */ if (message->tflags & (DEL_REQ_FLAG_EXPAND | DEL_REQ_FLAG_RECORD)) { status = trace_flush(message->tflags, message->queue_name, message->queue_id, message->encoding, message->sender); if (status == 0 && message->tflags_offset) qmgr_message_kill_record(message, message->tflags_offset); message->flags |= status; } /* * If we get to this point we have tried all recipients for this message. * If the message is too old, try to bounce it. * * Bounces are sent asynchronously to avoid stalling while the cleanup * daemon waits for the qmgr to accept the "new mail" trigger. */ if (message->flags) { if (event_time() >= message->arrival_time + (*message->sender ? var_max_queue_time : var_dsn_queue_time)) { msg_info("%s: from=<%s>, status=expired, returned to sender", message->queue_id, message->sender); if (message->verp_delims == 0 || var_verp_bounce_off) adefer_flush(BOUNCE_FLAG_KEEP, message->queue_name, message->queue_id, message->encoding, message->errors_to, qmgr_active_done_3_defer_flush, (char *) message); else adefer_flush_verp(BOUNCE_FLAG_KEEP, message->queue_name, message->queue_id, message->encoding, message->errors_to, message->verp_delims, qmgr_active_done_3_defer_flush, (char *) message); return; } else if (message->warn_time > 0 && event_time() > message->warn_time) { if (msg_verbose) msg_info("%s: sending defer warning for %s", myname, message->queue_id); adefer_warn(BOUNCE_FLAG_KEEP, message->queue_name, message->queue_id, message->encoding, message->errors_to, qmgr_active_done_3_defer_warn, (char *) message); return; } } /* * Asynchronous processing does not reach this point. */ qmgr_active_done_3_generic(message); }
static int do_compile(struct compilation_unit *cu) { bool ssa_enable; int err; if (opt_print_compilation) print_compilation(cu->method); if (opt_trace_compile) trace_method(cu); err = inline_subroutines(cu->method); if (err) goto out; if (opt_trace_bytecode) trace_bytecode(cu->method); err = analyze_control_flow(cu); if (err) goto out; err = convert_to_ir(cu); if (err) goto out; ssa_enable = opt_ssa_enable && uses_array_ops(cu); if (ssa_enable) { err = compute_dfns(cu); if (err) goto out; } if (opt_trace_cfg) trace_cfg(cu); if (opt_trace_tree_ir) trace_tree_ir(cu); err = select_instructions(cu); if (err) goto out; compute_insn_positions(cu); if (opt_trace_lir) trace_lir(cu); if (ssa_enable) { err = compute_dom(cu); if (err) goto out; err = compute_dom_frontier(cu); if (err) goto out; err = lir_to_ssa(cu); if (err) goto out; if(opt_trace_ssa) trace_ssa(cu); imm_copy_propagation(cu); abc_removal(cu); err = dce(cu); if (err) goto out; err = ssa_to_lir(cu); if (err) goto out; } err = analyze_liveness(cu); if (err) goto out; if (opt_trace_liveness) trace_liveness(cu); err = allocate_registers(cu); if (err) goto out; err = mark_clobbers(cu); if (err) goto out; err = insert_spill_reload_insns(cu); if (err) goto out; if (opt_trace_regalloc) trace_regalloc(cu); err = convert_ic_calls(cu); if (err) goto out; assert(all_insn_have_bytecode_offset(cu)); err = peephole_optimize(cu); if (err) goto out; err = emit_machine_code(cu); if (err) goto out; err = build_bc_offset_map(cu); if (err) goto out; if (opt_trace_machine_code) trace_machine_code(cu); resolve_fixup_offsets(cu); perf_append_cu(cu); out: if (opt_trace_compile) trace_flush(); if (err && !exception_occurred()) compile_error(cu, err); return err; }
void trace(char c) { if (trace_cnt < TRACE) trace_buf[1 + trace_cnt++] = c; if (trace_cnt >= 3*TRACE/4) trace_flush(); }
DEFINEFN void psyco_dump_code_buffers(void) { static int is_dumping = 0; FILE* f; #if CODE_DUMP >= 3 static int alt = 1; char filename[200]; sprintf(filename, "%s-%d", CODE_DUMP_FILE, alt); alt = 3-alt; #else char* filename = CODE_DUMP_FILE; #endif #if defined(PSYCO_TRACE) trace_flush(); #endif if (is_dumping) return; is_dumping = 1; f = fopen(filename, "wb"); if (f != NULL) { CodeBufferObject* obj; PyObject *exc, *val, *tb; long buftablepos; void** chain; int bufcount = 0; long* buftable; PyErr_Fetch(&exc, &val, &tb); debug_printf(1, ("writing %s\n", filename)); for (obj=psyco_codebuf_chained_list; obj != NULL; obj=obj->chained_list) bufcount++; buftable = PyMem_NEW(long, bufcount); fprintf(f, "Psyco dump [%s]\n", MACHINE_CODE_FORMAT); fwrite(&bufcount, sizeof(bufcount), 1, f); buftablepos = ftell(f); fwrite(buftable, sizeof(long), bufcount, f); /* give the address of an arbitrary symbol from the Python interpreter and from the Psyco module */ fprintf(f, "PyInt_FromLong: 0x%lx\n", (long) &PyInt_FromLong); fprintf(f, "psyco_dump_code_buffers: 0x%lx\n", (long) &psyco_dump_code_buffers); for (obj=psyco_codebuf_chained_list; obj != NULL; obj=obj->chained_list) { PyCodeObject* co = obj->snapshot.fz_pyc_data ? obj->snapshot.fz_pyc_data->co : NULL; fprintf(f, "CodeBufferObject 0x%lx %d '%s' '%s' %d '%s'\n", (long) obj->codestart, get_stack_depth(&obj->snapshot), co?PyString_AsString(co->co_filename):"", co?PyCodeObject_NAME(co):"", co?obj->snapshot.fz_pyc_data->next_instr:-1, obj->codemode); } psyco_dump_bigbuffers(f); for (chain = psyco_codebuf_spec_dict_list; chain; chain=(void**)*chain) { PyObject* spec_dict = (PyObject*)(chain[-1]); int i = 0; PyObject *key, *value; fprintf(f, "spec_dict 0x%lx\n", (long) chain); while (PyDict_Next(spec_dict, &i, &key, &value)) { PyObject* repr; if (PyInt_Check(key)) { repr = (key->ob_type->tp_as_number->nb_hex)(key); } else { repr = PyObject_Repr(key); } psyco_assert(!PyErr_Occurred()); psyco_assert(PyString_Check(repr)); psyco_assert(CodeBuffer_Check(value)); fprintf(f, "0x%lx %s\n", (long)((CodeBufferObject*)value)->codestart, PyString_AsString(repr)); Py_DECREF(repr); } fprintf(f, "\n"); } { int i = 0; fprintf(f, "vinfo_array\n"); for (obj=psyco_codebuf_chained_list; obj != NULL; obj=obj->chained_list) { PsycoObject* live_po; PyObject* d; if (psyco_top_array_count(&obj->snapshot) > 0) live_po = fpo_unfreeze(&obj->snapshot); else live_po = NULL; d = PyDict_New(); psyco_assert(d); buftable[i++] = ftell(f); vinfo_array_dump(live_po ? &live_po->vlocals : NullArray, f, d); Py_DECREF(d); if (live_po) PsycoObject_Delete(live_po); } psyco_assert(i==bufcount); fseek(f, buftablepos, 0); fwrite(buftable, sizeof(long), bufcount, f); } PyMem_FREE(buftable); psyco_assert(!PyErr_Occurred()); fclose(f); PyErr_Restore(exc, val, tb); }
int aq_flush(int discard) { int rc; int more_trace; /* to avoid infinite loop */ double t, timeout_expect; aq_add_count = 0; init_effect(); if(discard) { trace_flush(); if(play_mode->acntl(PM_REQ_DISCARD, NULL) != -1) { flush_buckets(); return RC_NONE; } ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "ERROR: Can't discard audio buffer"); } if(!IS_STREAM_TRACE) { play_mode->acntl(PM_REQ_FLUSH, NULL); play_counter = play_offset_counter = 0; return RC_NONE; } rc = aq_soft_flush(); if(RC_IS_SKIP_FILE(rc)) return rc; more_trace = 1; t = get_current_calender_time(); timeout_expect = t + (double)aq_filled() / play_mode->rate; while(more_trace || aq_filled() > 0) { rc = check_apply_control(); if(RC_IS_SKIP_FILE(rc)) { play_mode->acntl(PM_REQ_DISCARD, NULL); flush_buckets(); return rc; } more_trace = trace_loop(); t = get_current_calender_time(); if(t >= timeout_expect - 0.1) break; if(!more_trace) usleep((unsigned long)((timeout_expect - t) * 1000000)); else aq_wait_ticks(); } trace_flush(); play_mode->acntl(PM_REQ_FLUSH, NULL); flush_buckets(); return RC_NONE; }
void __attribute__((noreturn)) supervisor_task(void) { struct trace_entry trace; uint32_t clk; uint32_t dump_tmo; int n; INF("<%d> started...", thinkos_thread_self()); /* set the supervisor stream to stdout */ trace_file = stdout; /* enable auto flush */ trace_auto_flush = true; trace_tail(&trace); #if 0 struct sockaddr_in sin; struct udp_pcb * udp; bool udp_enabled; if ((udp = udp_alloc()) == NULL) { abort(); } if (!inet_aton(trace_host, &sin.sin_addr)) { abort(); } sin.sin_port = htons(trace_port); if (udp_bind(udp, INADDR_ANY, htons(10)) < 0) { abort(); } // if (udp_connect(udp, sin.sin_addr.s_addr, htons(sin.sin_port)) < 0) { // abort(); // } #endif clk = thinkos_clock(); dump_tmo = clk + 15000; for (;;) { char msg[80]; /* 8Hz periodic task */ clk += 125; thinkos_alarm(clk); // udp_enabled = trace_udp_enabled; while (trace_getnext(&trace, msg, sizeof(msg)) >= 0) { struct timeval tv; char s[128]; trace_ts2timeval(&tv, trace.dt); if (trace.ref->lvl <= TRACE_LVL_WARN) n = sprintf(s, "%s %2d.%06d: %s,%d: %s\n", trace_lvl_nm[trace.ref->lvl], (int)tv.tv_sec, (int)tv.tv_usec, trace.ref->func, trace.ref->line, msg); else n = sprintf(s, "%s %2d.%06d: %s\n", trace_lvl_nm[trace.ref->lvl], (int)tv.tv_sec, (int)tv.tv_usec, msg); /* write log to local console */ fwrite(s, n, 1, trace_file); #if 0 if (udp_enabled) { /* sent log to remote station */ if (udp_sendto(udp, s, n, &sin) < 0) { udp_enabled = false; } } #endif } if (trace_auto_flush) trace_flush(&trace); if ((int32_t)(clk - dump_tmo) >= 0) { const struct thinkos_thread_inf * infbuf[33]; uint32_t cycbuf[33]; uint32_t cycsum = 0; uint32_t cycbusy; uint32_t cycidle; uint32_t cycdiv; uint32_t idle; uint32_t busy; int n; int i; thinkos_critical_enter(); thinkos_thread_inf(infbuf); n = thinkos_cyccnt(cycbuf); thinkos_critical_exit(); cycsum = 0; for (i = 0; i < n; ++i) cycsum += cycbuf[i]; cycidle = cycbuf[n - 1]; /* The last item is IDLE */ cycbusy = cycsum - cycidle; cycdiv = (cycsum + 5000) / 10000; busy = (cycbusy + (cycdiv / 2)) / cycdiv; idle = 1000 - busy; printf("CPU usage: %d.%02d%% busy, %d.%02d%% idle\n", busy / 100, busy % 100, idle / 100, idle % 100); for (i = 0; i < n; ++i) { const struct thinkos_thread_inf * inf; if (((inf = infbuf[i]) != NULL) && (cycbuf[i] != 0)) { uint32_t usage; usage = (cycbuf[i] + cycdiv / 2) / cycdiv; printf("%2d %7s %3d.%02d%%\n", i, inf->tag, usage / 100, usage % 100); } } dump_tmo = clk + 15000; } } }