Esempio n. 1
0
/*
 * Used to find, extract and dump state from
 * a running bootchartd process.
 */
int
buffers_extract_and_dump (const char *output_path, Arguments *remote_args)
{
	int i, pid, ret = 0;
	DumpState *state;

	assert (!chdir (output_path));

	pid = bootchart_find_running_pid (remote_args);
	if (pid < 0) {
		log ("Failed to find the collector's pid\n");
		return 1;
	}
	log ("Extracting profile data from pid %d\n", pid);

	/* the kernel for reasons of it's own really likes to return
	   ESRCH - No such process from pread randomly, so retry a bit */
	for (i = 0; i < 8; i++) {
		if (!(state = open_pid (pid)))
			return 1;

		if (find_chunks (state)) {
			ret = 1;
			log ("Couldn't find state structures on pid %d's stack%s\n",
				 pid, i < 7 ? ", retrying" : " aborting");
			close_pid (state, 1);
		} else {
			ret = 0;
			dump_buffers (state);
			close_wait_pid (state, 0);
			break;
		}
	}

	return ret;
}
Esempio n. 2
0
/**
 * Main
 */
int main(int argc, char* argv[], char* envp[]) {
  LOG_ENTRY;
  parse_args(argc, argv);
  input_buffer = calloc(INPUT_BUFFER_SIZE, sizeof(char));
  prompt_buffer = calloc(PROMPT_BUFFER_SIZE, sizeof(char));
  while(1) {
    display_prompt();
    if(read_input() != NULL) {
      bool valid = handle_input();
      if (valid) {
	pid_t child_pid = fork();
	int status;
	if(child_pid) { //parent-execution
	  struct rusage child_info;
	  wait4(child_pid, &status, 0, &child_info);
	  if (display_child_time) {
	    printf(CHILD_EXECUTION_TIME_FMT,
		   (float) (child_info.ru_stime.tv_sec + child_info.ru_utime.tv_sec) +
		   (float) (child_info.ru_stime.tv_usec + child_info.ru_utime.tv_usec) / 1000000);
	  }
	  CHILD_OUT_END;
	  handle_exit_status(status);
	} else { //child execution
	  child_execute_input(envp);
	}
      }
    } else {
      printf(EOF_ERROR_MSG);
      exit_shell();
    }
#if DEBUG
    dump_buffers();
    #endif
  }
  LOG_RETURN(0);
}
Esempio n. 3
0
bool FrBWTIndex::compress(const char *infile, const char *outfile) const
{
   if (infile && *infile && outfile && *outfile &&
       strcmp(infile,outfile) != 0)
      {
      FILE *infp = fopen(infile,FrFOPEN_READ_MODE) ;
      if (!infp)
	 return false ;

      // step 1: copy the header to the output file, updating
      //   compression-parameter fields
      BWTHeader header ;
      Fr_read_BWT_header(infp,&header,signatureString()) ;
      if (header.m_compression != BWT_UNCOMP)
	 {
	 fclose(infp) ;
	 errno = EINVAL ;
	 return false ;			// already compressed
	 }
      FILE *outfp = fopen(outfile,FrFOPEN_WRITE_MODE) ;
      if (!outfp)
	 {
	 int e = errno ;
	 fclose(infp) ;
	 errno = e ;
	 return false ;
	 }

      // (for now, we'll just hard-code some reasonable values for the params)
      header.m_bucketsize = DEFAULT_BUCKET_SIZE ;
      header.m_maxdelta = 255 - header.m_bucketsize ;

      // while we're at it, put in the pre-determined locations of the
      //   bucket pointers and bucket pool
      size_t numbuckets = ((header.m_FL_length + header.m_bucketsize - 1) /
			   header.m_bucketsize) ;
      header.m_buckets_offset = (header.m_FL_offset + header.m_FL_length) ;
      header.m_bucketpool_offset = (header.m_buckets_offset +
				    numbuckets * bytesPerPointer()) ;
      Fr_write_BWT_header(outfp,&header,signatureString()) ;

      // copy m_C to the output file
      copy_bytes(infp,outfp,
		 (header.m_C_length + 1) * FrBWTIndex::bytesPerPointer()) ;

      // step 2: convert m_items values to differences and encode in bytes,
      //   writing the results to the output file
      CompressionBuffers compbuffers(header.m_bucketsize) ;
      compbuffers.setupEOR(header.m_eor_handling != 0,header.m_EOR) ;
      size_t prev = 0 ;
      bool success = true ;
      for (size_t i = 0 ; i < header.m_FL_length ; i++)
	 {
	 size_t succ ;
	 if (!Fr_read_long(infp,succ))
	    {
	    success = false ;
	    break ;
	    }
	 (void)compbuffers.encode(i,prev,succ) ;
	 if (!dump_buffers(outfp, compbuffers, header.m_FL_offset,
			   header.m_buckets_offset, header.m_bucketpool_offset))
	    {
	    success = false ;
	    break ;
	    }
	 if (((i+1) % header.m_bucketsize) == 0)
	    compbuffers.nextBucket() ;
	 prev = succ ;
	 }
      success = dump_buffers(outfp,compbuffers,header.m_buckets_offset,
			     header.m_bucketpool_offset,true) ;
      header.m_bucketpool_length = compbuffers.poolSize() / bytesPerPointer() ;

      // step 3: update header pointers
      fseek(infp,0L,SEEK_END) ;
      size_t udata_size = ftell(infp) - header.m_userdata ;
      fseek(infp,header.m_userdata,SEEK_SET) ;
      header.m_userdata = (size_t)ftell(outfp) ;
      Fr_write_BWT_header(outfp,&header,signatureString()) ;

      // step 4: copy any user data from the uncompressed file into new file
      copy_bytes(infp,outfp,udata_size) ;
      fclose(infp) ;
      fclose(outfp) ;
      return success ;
      }
   return false ;
}