void nested() { /* local variable definition */ sysClkRateSet(1000); sysTimestampEnable(); jiffies_per_tick = sysTimestampPeriod(); clock_frequency = sysTimestampFreq(); microseconds_per_tick = (jiffies_per_tick / clock_frequency)*1000000.0; microseconds_per_jiffy = microseconds_per_tick / jiffies_per_tick; int i, j, p; start_profiling(); for(i=2; i<100; i++) { start_profiling_in(); for(j=2; j <= (i/j); j++) if(!(i%j)) break; /* if factor found, not prime*/ stop_profiling_in(); if(j > (i/j)) p = i; } stop_profiling(); output_profiling("nested for outer loop including inner loop profiling"); start_profiling(); for(i=2; i<100; i++) { for(j=2; j <= (i/j); j++) if(!(i%j)) break; /* if factor found, not prime*/ if(j > (i/j)) p = i; } stop_profiling(); output_profiling("nested for outer loop without inner loop profiling"); }
int main (int argc, char *argv[]) { char *fn; int f_ret, u_ret; prog_name = argv[0]; tvm_argc = argc; tvm_argv = argv; if (argc < 2) { usage (stderr); return 1; } else { fn = argv[1]; } init_vm (); if (install_user_ctx (fn) < 0) { error_out_no_errno ("failed to load user bytecode"); return 1; } if (install_firmware_ctx () < 0) { error_out_no_errno ("failed to install firmware"); return 1; } kyb_channel = NOT_PROCESS_P; scr_channel = NOT_PROCESS_P; err_channel = NOT_PROCESS_P; for (;;) { f_ret = run_firmware (); u_ret = run_user (); if ((f_ret == ECTX_EMPTY || f_ret == ECTX_SLEEP) && (u_ret == ECTX_EMPTY || u_ret == ECTX_SLEEP)) { if (firmware->fptr == NOT_PROCESS_P && user->fptr == NOT_PROCESS_P) { tvm_sleep (); } } else if (f_ret == ECTX_ERROR || u_ret == ECTX_ERROR) { break; } else if (u_ret == ECTX_SHUTDOWN) { /* Run firmware to clear buffers */ run_firmware (); break; } } if (u_ret == ECTX_ERROR) { tbc_t *tbc = user->priv.bytecode->tbc; if (tbc->debug) { tbc_dbg_t *dbg = tbc->debug; tbc_lnd_t *ln; tenc_str_t *file; int offset = user->iptr - tbc->bytecode; int i = 0; while (i < dbg->n_lnd) { if (dbg->lnd[i].offset > offset) { break; } i++; } ln = &(dbg->lnd[i - 1]); file = dbg->files; for (i = 0; i < ln->file; ++i) { file = file->next; } fprintf (stderr, "Error at %s:%d\n", file->str, ln->line ); } /* FIXME: more debugging */ fprintf (stderr, "Program failed, state = %c, eflags = %08x\n", user->state, user->eflags ); return 1; } free_ectx (firmware); free_ectx (user); free_bytecode (fw_bc); free_bytecode (us_bc); #ifdef TVM_PROFILING output_profiling (); #endif return 0; }