Ejemplo n.º 1
0
/* and the local and total time markers are started */
void lprofM_enter_function(lprofP_STATE* S, char *file_defined, char *fcn_name, long linedefined, long currentline) {
  char* prev_name;
  char* cur_name;
  /* the flow has changed to another function: */
  /* pause the parent's function timer timer   */
  if (S->stack_top) {
    lprofM_pause_local_time(S);
    prev_name = S->stack_top->function_name;
  } else prev_name = "top level";
  /* measure new function */
  lprofC_start_timer(&(newf.time_marker_function_local_time));
  lprofC_start_timer(&(newf.time_marker_function_total_time));
  newf.file_defined = file_defined;
  if(fcn_name != NULL) {
    newf.function_name = fcn_name;
  } else if(strcmp(file_defined, "=[C]") == 0) {
    cur_name = (char*)malloc(sizeof(char)*(strlen("called from ")+strlen(prev_name)+1));
    sprintf(cur_name, "called from %s", prev_name);
    newf.function_name = cur_name;
  } else {
    cur_name = (char*)malloc(sizeof(char)*(strlen(file_defined)+12));
    sprintf(cur_name, "%s:%li", file_defined, linedefined);
    newf.function_name = cur_name;
  }	   
  newf.line_defined = linedefined;
  newf.current_line = currentline;
  newf.local_time = 0.0;
  newf.total_time = 0.0;
  lprofS_push(&(S->stack_top), newf);
}
Ejemplo n.º 2
0
/* returns if there is another function in the stack */
int lprofP_callhookOUT(lprofP_STATE* S, lprofP_STATE* R) {

  if (S->stack_level == 0) {
    return 0;
  }

  S->stack_level--;

  /* 0: do not resume the parent function's timer yet... */
  info = lprofM_leave_function(S, 0);

  //info->local_time += function_call_time;
  //info->total_time += function_call_time;

  // for call stack level
  //if (info->local_time > 0.0000001 || info->total_time > 0.0000001)
  //{
	  R->stack_level++;
	  //info->stack_level = S->stack_level;
	  lprofS_push(&(R->stack_top), *info);
	  R->stack_top->stack_level = S->stack_level;
  //}

  if (S->stack_level != 0) {
	  lprofM_resume_local_time(S);
  }
/*
  // writing a log may take too long to be computed with the function's time ...
  lprofM_pause_total_time(S);

  info->local_time += function_call_time;
  info->total_time += function_call_time;
  
  if (info->local_time > 0.0000001 || info->total_time > 0.0000001)
  {
	  char* source = info->file_defined;
	  //if (source[0] != '@') {
		 // source = "(string)";
	  //}
	  //else {
		 // formats(source);
	  //}
	  char* name = info->function_name;

	  if (strlen(name) > MAX_FUNCTION_NAME_LENGTH) {
		  name = (char*)malloc(MAX_FUNCTION_NAME_LENGTH + 10);
		  name[0] = '\"';
		  strncpy(name + 1, info->function_name, MAX_FUNCTION_NAME_LENGTH);
		  name[MAX_FUNCTION_NAME_LENGTH] = '"';
		  name[MAX_FUNCTION_NAME_LENGTH + 1] = '\0';
	  }
	  formats(name);
	  output("%d\t%s\t%s\t%d\t%d\t%f\t%f\n", S->stack_level, source, name,
		  info->line_defined, info->current_line,
		  info->local_time, info->total_time);
  }

  // ... now it's ok to resume the timer
  if (S->stack_level != 0) {
    lprofM_resume_function(S);
  }
*/
  return 1;

}