示例#1
0
/* Build a sub-hist, based on the main hist.
 */
static void *
build_subhist( IMAGE *out, void *a, void *b )
{
        Histogram *mhist = (Histogram *) a;

	return( (void *) 
		build_hist( mhist->in, mhist->out, mhist->bins ) );
}
示例#2
0
int 
im_histnD( IMAGE *in, IMAGE *out, int bins )
{
	int max_val;
	Histogram *mhist;
	int x, y, z, i;
	unsigned int *obuffer;

	/* Check images. PIO from in, WIO to out.
	 */
	if( im_pincheck( in ) || im_outcheck( out ) )
		return( -1 );
	if( in->Coding != IM_CODING_NONE ) {
		im_error( "im_histnD", _( " uncoded images only" ) );
		return( -1 );
	}
	if( in->BandFmt != IM_BANDFMT_UCHAR && 
		in->BandFmt != IM_BANDFMT_USHORT ) {
		im_error( "im_histnD", 
			_( " unsigned 8 or 16 bit images only" ) );
		return( -1 );
	}

	max_val = in->BandFmt == IM_BANDFMT_UCHAR ? 256 : 65536;
	if( bins < 1 || bins > max_val ) {
		im_error( "im_histnD", 
			_( " bins out of range [1,%d]" ), max_val );
		return( -1 );
	}

	/* Build main hist we accumulate to.
	 */
	if( !(mhist = build_hist( in, out, bins )) )
		return( -1 );

	/* Accumulate data.
	 */
	if( im_iterate( in, 
		build_subhist, find_hist, merge_subhist, mhist, NULL ) )
		return( -1 );

	/* Make the output image.
	 */
	if( im_cp_desc( out, in ) ) 
		return( -1 );
	im_initdesc( out,
		bins, in->Bands > 1 ? bins : 1, in->Bands > 2 ? bins : 1,
		IM_BBITS_INT, IM_BANDFMT_UINT, 
		IM_CODING_NONE, IM_TYPE_HISTOGRAM, 1.0, 1.0, 0, 0 );
	if( im_setupout( out ) )
		return( -1 );

	/* Interleave to output buffer.
	 */
	if( !(obuffer = IM_ARRAY( out, 
		IM_IMAGE_N_ELEMENTS( out ), unsigned int )) )
		return( -1 );

	for( y = 0; y < out->Ysize; y++ ) {
		for( i = 0, x = 0; x < out->Xsize; x++ ) 
			for( z = 0; z < out->Bands; z++, i++ )
				obuffer[i] = mhist->data[z][y][x];

		if( im_writeline( y, out, (PEL *) obuffer ) )
			return( -1 );
	}

	return( 0 );
}
示例#3
0
static void
hrprof_finish (void)
{
   struct gmon_hdr ghdr;
   struct gmon_hist_hdr thdr;
   struct gmon_cg_arc_record raw_arc;
   int h;
   struct arc *cp;
   double tsc_secs;
   double tod_secs;
   double charged_secs;
   double end_time;
   unsigned long long charged_ticks;
   unsigned long long used_ticks;
   char from_name[1000], to_name[1000];
   int idx;

   FILE *f;

   if (hrprof_state != 1)
      return;
   hrprof_state = 2;

   end_time = get_time ();
   tod_secs = end_time - start_time;

   if (hrprof_scale_ready == 0) {
      if (tod_secs < 10)
         hrprof_set_scale (1000);
      else
         hrprof_set_scale (1);
   }

   charged_ticks = build_hist ();

   used_ticks = last_tsc - start_tsc;

   charged_secs = charged_ticks / processor_clock;

   tsc_secs = used_ticks / processor_clock;

   remove ("hrprof.out");
   if ((f = fopen ("hrprof.out", "w")) != NULL) {
      fprintf (f, "processor clock %g MHz\n",
          processor_clock / 1000000.0);
      fprintf (f, "secs according to tsc: %g\n", tsc_secs);
      fprintf (f, "secs according to tod: %g\n", tod_secs);
      fprintf (f, "charged secs %g\n", charged_secs);
      fprintf (f, "given out %g\n",
          ticks_given_out / processor_clock);

      fprintf (f, "hist:\n");
      for (idx = 0; idx < kmax_idx; idx++) {
         if (kcount[idx]) {
            void *pc;
            pc = (void *)(idx * HISTFRACTION
                     * sizeof (HISTCOUNTER)
                     + lowpc);
            fprintf (f, "%s %d\n",
                hrprof_sym (from_name, pc),
                kcount[idx]);
         }
      }

      fclose (f);
   }

   remove ("gmon.out");
   if ((f = fopen ("gmon.out", "w")) == NULL)
      return;

   memset (&ghdr, 0, sizeof ghdr);
   memcpy (ghdr.cookie, GMON_MAGIC, sizeof ghdr.cookie);
   put4 (ghdr.version, GMON_VERSION);
   fwrite (&ghdr, 1, sizeof ghdr, f);

   memset (&thdr, 0, sizeof thdr);
   put4 (thdr.low_pc, lowpc);
   put4 (thdr.high_pc, highpc);
   put4 (thdr.hist_size, kcountsize / sizeof (HISTCOUNTER));
   put4 (thdr.prof_rate, profile_rate);
   if (hrprof_scale == 1) {
      strcpy (thdr.dimen, "secs");
      thdr.dimen_abbrev = 's';
   } else {
      strcpy (thdr.dimen, "msecs");
      thdr.dimen_abbrev = 'u';
   }

   putc (GMON_TAG_TIME_HIST, f);
   fwrite (&thdr, 1, sizeof thdr, f);
   fwrite (kcount, 1, kcountsize, f);

   for (h = 0; h < NHASH; h++) {
      for (cp = arc_hash[h]; cp; cp = cp->hash_next) {
         if (hrprof_trace)
            printf ("arc: %s %s %d\n",
               hrprof_sym (from_name, cp->call_site),
               hrprof_sym (to_name, cp->fn_addr),
               cp->count);
         put4 (raw_arc.from_pc,
               (unsigned int)cp->call_site);
         put4 (raw_arc.self_pc,
               (unsigned int)cp->fn_addr);
         put4 (raw_arc.count, cp->count);

         putc (GMON_TAG_CG_ARC, f);
         fwrite (&raw_arc, 1, sizeof raw_arc, f);
      }
   }

   fclose (f);

   free (kcount);
}