long clock() { struct tms buffer; if (times(&buffer) != -1L && first == 0L) first = TIMES(buffer); return ((TIMES(buffer) - first) * (1000000L/HZ)); }
/* Called on each linestart and linefetch */ void pcurrpos(void) { trace_entry tmp_trc_tbl_entry; DCL_THREADGBL_ACCESS; SETUP_THREADGBL_ACCESS; assert(TREF(mprof_ptr)); assert(TREF(prof_fp)); TIMES(&(TREF(mprof_ptr))->tcurr); /* remember the new time */ /* update the time of previous M line */ if (NULL != (TREF(mprof_ptr))->curr_tblnd) { UPDATE_TIME((TREF(mprof_ptr))->curr_tblnd); } get_entryref_information(TRUE, &tmp_trc_tbl_entry); if (FALSE == (TREF(mprof_ptr))->is_tracing_ini) { (TREF(mprof_ptr))->is_tracing_ini = TRUE; (TREF(mprof_ptr))->curr_tblnd = (TREF(mprof_ptr))->head_tblnd = (mprof_tree *)new_node(&tmp_trc_tbl_entry); (TREF(mprof_ptr))->curr_tblnd->e.count = 1; } else { (TREF(mprof_ptr))->curr_tblnd = (mprof_tree *)mprof_tree_insert(&((TREF(mprof_ptr))->head_tblnd), &tmp_trc_tbl_entry); if (0 == (TREF(mprof_ptr))->curr_tblnd->e.count) (TREF(mprof_ptr))->curr_tblnd->e.count = 1; else (TREF(mprof_ptr))->curr_tblnd->e.count++; } (TREF(mprof_ptr))->tprev = (TREF(mprof_ptr))->tcurr; return; }
void turn_tracing_off (mval *gvn) { DCL_THREADGBL_ACCESS; SETUP_THREADGBL_ACCESS; if (FALSE == is_tracing_on) return; assert(TREF(mprof_ptr)); TIMES(&(TREF(mprof_ptr))->tcurr); /* update the time of previous M line, if there was one */ if (NULL != (TREF(mprof_ptr))->curr_tblnd) { UPDATE_TIME((TREF(mprof_ptr))->curr_tblnd); } if (NULL != gvn) parse_gvn(gvn); is_tracing_on = (TREF(mprof_ptr))->is_tracing_ini = FALSE; assert(0 != (TREF(mprof_ptr))->gbl_to_fill.str.addr); free((TREF(mprof_ptr))->gbl_to_fill.str.addr); (TREF(mprof_ptr))->gbl_to_fill.str.addr = NULL; mprof_tree_walk((TREF(mprof_ptr))->head_tblnd); mprof_stack_free(); (TREF(mprof_ptr))->pcavailptr = (TREF(mprof_ptr))->pcavailbase; (TREF(mprof_ptr))->pcavail = PROFCALLOC_DSBLKSIZE - SIZEOF(char *); CLEAR_PROFILING_TABLE(); return; }
void turn_tracing_on(mval *gvn) { struct tms *curr; trace_entry tmp_trc_tbl_entry; DCL_THREADGBL_ACCESS; SETUP_THREADGBL_ACCESS; if (is_tracing_on) { gtm_putmsg(VARLSTCNT(1) ERR_TRACINGON); return; } if (0 == gvn->str.len || '^' != gvn->str.addr[0]) rts_error(VARLSTCNT(4) ERR_NOTGBL, 2, gvn->str.len, gvn->str.addr); if (!TREF(mprof_ptr)) { TREF(mprof_ptr) = (mprof_wrapper *)malloc(SIZEOF(mprof_wrapper)); memset(TREF(mprof_ptr), 0, SIZEOF(mprof_wrapper)); } parse_gvn(gvn); (TREF(mprof_ptr))->gbl_to_fill = *gvn; (TREF(mprof_ptr))->gbl_to_fill.str.addr = (char *)malloc(gvn->str.len); /* len was already set up */ memcpy((TREF(mprof_ptr))->gbl_to_fill.str.addr, gvn->str.addr, gvn->str.len); if (!(TREF(mprof_ptr))->pcavailbase) { (TREF(mprof_ptr))->pcavailbase = (char **)malloc(PROFCALLOC_DSBLKSIZE); *(TREF(mprof_ptr))->pcavailbase = 0; } (TREF(mprof_ptr))->pcavailptr = (TREF(mprof_ptr))->pcavailbase; (TREF(mprof_ptr))->pcavail = PROFCALLOC_DSBLKSIZE - SIZEOF(char *); memset((TREF(mprof_ptr))->pcavailptr + 1, 0, (TREF(mprof_ptr))->pcavail); curr = &((TREF(mprof_ptr))->tprev); TIMES(curr); mprof_stack_init(); TREF(prof_fp) = mprof_stack_push(); get_entryref_information(FALSE, NULL); tmp_trc_tbl_entry.rout_name = NULL; tmp_trc_tbl_entry.label_name = NULL; (TREF(mprof_ptr))->curr_tblnd = (TREF(mprof_ptr))->head_tblnd = NULL; (TREF(prof_fp))->start.tms_stime = (*curr).tms_stime; (TREF(prof_fp))->start.tms_utime = (*curr).tms_utime; (TREF(prof_fp))->carryover.tms_stime = 0; (TREF(prof_fp))->carryover.tms_utime = 0; (TREF(prof_fp))->dummy_stack_count = 0; (TREF(prof_fp))->rout_name = (TREF(prof_fp))->label_name = NULL; POPULATE_PROFILING_TABLE(); is_tracing_on = TRUE; return; }
/* Enables tracing and ensures that all critical structures are initialized */ void turn_tracing_on(mval *gvn, boolean_t from_env, boolean_t save_gbl) { ext_tms curr; trace_entry tmp_trc_tbl_entry; DCL_THREADGBL_ACCESS; SETUP_THREADGBL_ACCESS; mdb_ch_set = !from_env; /* if tracing is on explicitly, or if it is implicit with saving */ if (save_gbl || !from_env) { if (is_tracing_on) { gtm_putmsg(VARLSTCNT(1) ERR_TRACINGON); return; } if ((0 == gvn->str.len) || ('^' != gvn->str.addr[0])) MPROF_RTS_ERROR((VARLSTCNT(4) ERR_NOTGBL, 2, gvn->str.len, gvn->str.addr)); } /* the following should only be a one-time operation */ if (!TREF(mprof_ptr)) { TREF(mprof_ptr) = (mprof_wrapper *)malloc(SIZEOF(mprof_wrapper)); memset(TREF(mprof_ptr), 0, SIZEOF(mprof_wrapper)); } /* only need to have the gvn if we are going to save the data */ if (save_gbl && (0 < gvn->str.len)) { parse_gvn(gvn); (TREF(mprof_ptr))->gbl_to_fill = *gvn; (TREF(mprof_ptr))->gbl_to_fill.str.addr = (char *)malloc(gvn->str.len); /* len was already set up */ memcpy((TREF(mprof_ptr))->gbl_to_fill.str.addr, gvn->str.addr, gvn->str.len); } /* preallocate some space */ if (!(TREF(mprof_ptr))->pcavailbase) { (TREF(mprof_ptr))->pcavailbase = (char **)malloc(PROFCALLOC_DSBLKSIZE); *(TREF(mprof_ptr))->pcavailbase = 0; } (TREF(mprof_ptr))->pcavailptr = (TREF(mprof_ptr))->pcavailbase; (TREF(mprof_ptr))->pcavail = PROFCALLOC_DSBLKSIZE - OFFSET_LEN; memset((TREF(mprof_ptr))->pcavailptr + 1, 0, (TREF(mprof_ptr))->pcavail); curr = (TREF(mprof_ptr))->tprev; TIMES(&curr); UNIX_ONLY(child_times_usec();)
// I denote by "**n" the counterpart of "TIMES(n)." // I <- ('a' 'b')**3 bool is_I(_iterator &it){ PEG( TIMES(3) && _is('a') && _is('b') && END_TIMES ); return true; }