GCC Middle and Back End API Reference
gcov-io.c File Reference

Functions

static void gcov_write_block (unsigned)
static gcov_unsigned_tgcov_write_words (unsigned)
static const gcov_unsigned_tgcov_read_words (unsigned)
static void gcov_allocate (unsigned)
static gcov_unsigned_t from_file (gcov_unsigned_t value)
GCOV_LINKAGE int gcov_open (#else gcov_open(const char *name, int mode)#endif)
GCOV_LINKAGE int gcov_close ()
GCOV_LINKAGE int gcov_magic ()
static void gcov_allocate ()
static void gcov_write_block ()
static gcov_unsigned_tgcov_write_words ()
GCOV_LINKAGE void gcov_write_unsigned ()
GCOV_LINKAGE void gcov_write_counter ()
GCOV_LINKAGE void gcov_write_string ()
GCOV_LINKAGE gcov_position_t gcov_write_tag ()
GCOV_LINKAGE void gcov_write_length ()
GCOV_LINKAGE void gcov_write_tag_length ()
GCOV_LINKAGE void gcov_write_summary ()
static const gcov_unsigned_tgcov_read_words ()
GCOV_LINKAGE gcov_unsigned_t gcov_read_unsigned ()
GCOV_LINKAGE gcov_type gcov_read_counter ()
GCOV_LINKAGE const char * gcov_read_string ()
GCOV_LINKAGE void gcov_read_summary ()
GCOV_LINKAGE void gcov_sync ()
GCOV_LINKAGE void gcov_seek ()
GCOV_LINKAGE time_t gcov_time ()
static unsigned GCOV_LINKAGE
unsigned 
gcov_histo_index ()
static void gcov_histogram_merge (gcov_bucket_type *tgt_histo, gcov_bucket_type *src_histo)
GCOV_LINKAGE void compute_working_sets (const struct gcov_ctr_summary *summary, gcov_working_set_t *gcov_working_sets)

Function Documentation

GCOV_LINKAGE void compute_working_sets ( const struct gcov_ctr_summary summary,
gcov_working_set_t gcov_working_sets 
)
   This is used by gcov-dump (IN_GCOV == -1) and in the compiler
   (!IN_GCOV && !IN_LIBGCOV).  
   Compute the working set information from the counter histogram in
   the profile summary. This is an array of information corresponding to a
   range of percentages of the total execution count (sum_all), and includes
   the number of counters required to cover that working set percentage and
   the minimum counter value in that working set.  
     Compute the amount of sum_all that the cumulative hotness grows
     by in each successive working set entry, which depends on the
     number of working set entries.  
     Next fill in an array of the cumulative hotness values corresponding
     to each working set summary entry we are going to compute below.
     Skip 0% statistics, which can be extrapolated from the
     rest of the summary data.  
     The last summary entry is reserved for (roughly) 99.9% of the
     working set. Divide by 1024 so it becomes a shift, which gives
     almost exactly 99.9%.  
     Next, walk through the histogram in decending order of hotness
     and compute the statistics for the working set summary array.
     As histogram entries are accumulated, we check to see which
     working set entries have had their expected cum_value reached
     and fill them in, walking the working set entries in increasing
     size of cum_value.  
         If we haven't reached the required cumulative counter value for
         the current working set percentage, simply accumulate this histogram
         entry into the running sums and continue to the next histogram
         entry.  
         If adding the current histogram entry's cumulative counter value
         causes us to exceed the current working set size, then estimate
         how many of this histogram entry's counter values are required to
         reach the working set size, and fill in working set entries
         as we reach their expected cumulative value.  
             If we haven't reached the last histogram entry counter, add
             in the minimum value again. This will underestimate the
             cumulative sum so far, because many of the counter values in this
             entry may have been larger than the minimum. We could add in the
             average value every time, but that would require an expensive
             divide operation.  
             If we have reached the last histogram entry counter, then add
             in the entire cumulative value.  
             Next walk through successive working set entries and fill in
             the statistics for any whose size we have reached by accumulating
             this histogram counter.  
         Finally, update the running cumulative value since we were
         using a temporary above.  

References count, gcov_bucket_type::cum_value, gcov_working_set_info::min_counter, gcov_bucket_type::min_value, gcov_bucket_type::num_counters, and gcov_working_set_info::num_counters.

static gcov_unsigned_t from_file ( gcov_unsigned_t  value)
inlinestatic
static void gcov_allocate ( unsigned  )
static
static void gcov_allocate ( )
static
GCOV_LINKAGE int gcov_close ( void  )
   Close the current gcov file. Flushes data to disk. Returns nonzero
   on failure or error flag set.  
static unsigned GCOV_LINKAGE unsigned gcov_histo_index ( )
static
   Determine the index into histogram for VALUE. 
     Find index into log2 scale histogram, where each of the log2
     sized buckets is divided into 4 linear sub-buckets for better
     focus in the higher buckets.  
     Find the place of the most-significant bit set.  
         When building libgcov we don't include system.h, which includes
         hwint.h (where floor_log2 is declared). However, libgcov.a
         is built by the bootstrapped compiler and therefore the builtins
         are always available.  
         We use floor_log2 from hwint.c, which takes a HOST_WIDE_INT
         that is either 32 or 64 bits, and gcov_type_unsigned may be 64 bits.
         Need to check for the case where gcov_type_unsigned is 64 bits
         and HOST_WIDE_INT is 32 bits and handle it specially.  
     If at most the 2 least significant bits are set (value is
     0 - 3) then that value is our index into the lowest set of
     four buckets.  
     Find the two next most significant bits to determine which
     of the four linear sub-buckets to select.  
     Finally, compose the final bucket index from the log2 index and
     the next 2 bits. The minimum r value at this point is 2 since we
     returned above if r was 2 or more, so the minimum bucket at this
     point is 4.  
static void gcov_histogram_merge ( gcov_bucket_type tgt_histo,
gcov_bucket_type src_histo 
)
static
   Merge SRC_HISTO into TGT_HISTO. The counters are assumed to be in
   the same relative order in both histograms, and are matched up
   and merged in reverse order. Each counter is assigned an equal portion of
   its entry's original cumulative counter value when computing the
   new merged cum_value.  
     Assume that the counters are in the same relative order in both
     histograms. Walk the histograms from largest to smallest entry,
     matching up and combining counters in order.  
         Keep going until all of the target histogram's counters at this
         position have been matched and merged with counters from the
         source histogram.  
             If this is either the first time through this loop or we just
             exhausted the previous non-zero source histogram entry, look
             for the next non-zero source histogram entry.  
                 Locate the next non-zero entry.  
                 If source histogram has fewer counters, then just copy over the
                 remaining target counters and quit.  
             The number of counters to merge on this pass is the minimum
             of the remaining counters from the current target and source
             histogram entries.  
             The merged min_value is the sum of the min_values from target
             and source.  
             Compute the portion of source and target entries' cum_value
             that will be apportioned to the counters being merged.
             The total remaining cum_value from each entry is divided
             equally among the counters from that histogram entry if we
             are not merging all of them.  
             The merged cum_value is the sum of the source and target
             components.  
             Update the remaining number of counters and cum_value left
             to be merged from this source and target entry.  
             The merged counters get placed in the new merged histogram
             at the entry for the merged min_value.  
             Ensure the search for the next non-zero src_histo entry starts
             at the next smallest histogram bucket.  
     In the case where there were more counters in the source histogram,
     accumulate the remaining unmerged cumulative counter values. Add
     those to the smallest non-zero target histogram entry. Otherwise,
     the total cumulative counter values in the histogram will be smaller
     than the sum_all stored in the summary, which will complicate
     computing the working set information from the histogram later on.  
     At this point, tmp_i should be the smallest non-zero entry in the
     tmp_histo.  
     Finally, copy the merged histogram into tgt_histo.  

References gcov_bucket_type::cum_value, gcov_bucket_type::min_value, and gcov_bucket_type::num_counters.

GCOV_LINKAGE int gcov_magic ( )
   Check if MAGIC is EXPECTED. Use it to determine endianness of the
   file. Returns +1 for same endian, -1 for other endian and zero for
   not EXPECTED.  
GCOV_LINKAGE int gcov_open ( #else gcov_open(const char *name, int mode)#  endif)
   Open a gcov file. NAME is the name of the file to open and MODE
   indicates whether a new file should be created, or an existing file
   opened. If MODE is >= 0 an existing file will be opened, if
   possible, and if MODE is <= 0, a new file will be created. Use
   MODE=0 to attempt to reopen an existing file and then fall back on
   creating a new one.  If MODE < 0, the file will be opened in
   read-only mode.  Otherwise it will be opened for modification.
   Return zero on failure, >0 on opening an existing file and <0 on
   creating a new one.  
         Read-only mode - acquire a read-lock.  
         pass mode (ignored) for compatibility 
         Write mode - acquire a write-lock.  

References gcov_var::endian, errno, gcov_var::error, gcov_var::file, gcov_var::length, gcov_var::mode, gcov_var::offset, gcov_var::overread, and gcov_var::start.

Referenced by coverage_obj_fn().

GCOV_LINKAGE gcov_type gcov_read_counter ( void  )
   Read counter value from a coverage file. Sets error flag on file
   error, overflow flag on overflow 

References gcov_read_unsigned(), and gcov_read_words().

GCOV_LINKAGE const char* gcov_read_string ( void  )
   Read string from coverage file. Returns a pointer to a static
   buffer, or NULL on empty string. You must copy the string before
   calling another gcov function.  

Referenced by tag_lines().

GCOV_LINKAGE void gcov_read_summary ( )
             When building libgcov we don't include system.h, which includes
             hwint.h (where popcount_hwi is declared). However, libgcov.a
             is built by the bootstrapped compiler and therefore the builtins
             are always available.  
             Find the index corresponding to the next entry we will read in.
             First find the next non-zero bitvector and re-initialize
             the histogram index accordingly, then right shift and increment
             the index until we find a set bit.  
             Shift off the index we are done with and increment to the
             corresponding next histogram entry.  
GCOV_LINKAGE gcov_unsigned_t gcov_read_unsigned ( void  )
   Read unsigned value from a coverage file. Sets error flag on file
   error, overflow flag on overflow 

Referenced by gcov_read_counter(), read_graph_file(), and tag_lines().

static const gcov_unsigned_t* gcov_read_words ( unsigned  )
static

Referenced by gcov_read_counter().

static const gcov_unsigned_t* gcov_read_words ( )
static
   Return a pointer to read BYTES bytes from the gcov file. Returns
   NULL on failure (read past EOF).  
GCOV_LINKAGE void gcov_seek ( )
   Move to a given position in a gcov file.  
GCOV_LINKAGE void gcov_sync ( )
   Reset to a known position.  BASE should have been obtained from
   gcov_position, LENGTH should be a record length.  
GCOV_LINKAGE time_t gcov_time ( void  )
   Return the modification time of the current gcov file.  

References floor_log2(), HOST_BITS_PER_WIDE_INT, and HOST_WIDE_INT.

static void gcov_write_block ( unsigned  )
static
@verbatim 

File format for coverage information Copyright (C) 1996-2013 Free Software Foundation, Inc. Contributed by Bob Manson manso.nosp@m.n@cy.nosp@m.gnus..nosp@m.com. Completely remangled by Nathan Sidwell natha.nosp@m.n@co.nosp@m.desou.nosp@m.rcer.nosp@m.y.com.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Under Section 7 of GPL version 3, you are granted additional permissions described in the GCC Runtime Library Exception, version 3.1, as published by the Free Software Foundation.

You should have received a copy of the GNU General Public License and a copy of the GCC Runtime Library Exception along with this program; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see http://www.gnu.org/licenses/.

   Routines declared in gcov-io.h.  This file should be #included by
   another source file, after having #included gcov-io.h.  

Referenced by gcov_write_block(), and gcov_write_tag().

static void gcov_write_block ( )
static
   Write out the current block, if needs be.  

References gcov_write_block(), gcov_var::mode, and gcov_var::offset.

GCOV_LINKAGE void gcov_write_counter ( )
   Write counter VALUE to coverage file.  Sets error flag
   appropriately.  

References buffer, gcov_write_words(), and strlen().

GCOV_LINKAGE void gcov_write_length ( )
   Write a record length using POSITION, which was returned by
   gcov_write_tag.  The current file position is the end of the
   record, and is restored before returning.  Returns nonzero on
   overflow.  
GCOV_LINKAGE void gcov_write_string ( )
   Write STRING to coverage file.  Sets error flag on file
   error, overflow flag on overflow 
GCOV_LINKAGE void gcov_write_summary ( )
   Write a summary structure to the gcov file.  Return nonzero on
   overflow.  
     Count number of non-zero histogram entries, and fill in a bit vector
     of non-zero indices. The histogram is only currently computed for arc
     counters.  
GCOV_LINKAGE gcov_position_t gcov_write_tag ( )
   Write a tag TAG and reserve space for the record length. Return a
   value to be used for gcov_write_length.  

References buffer, gcov_var::buffer, gcov_write_block(), gcov_var::mode, gcov_var::offset, offset, and gcov_var::start.

GCOV_LINKAGE void gcov_write_tag_length ( )
   Write a tag TAG and length LENGTH.  

References gcov_ctr_summary::histogram, and gcov_bucket_type::num_counters.

GCOV_LINKAGE void gcov_write_unsigned ( )
   Write unsigned VALUE to coverage file.  Sets error flag
   appropriately.  

References buffer, and gcov_write_words().

Referenced by coverage_obj_fn().

static gcov_unsigned_t* gcov_write_words ( unsigned  )
static
static gcov_unsigned_t* gcov_write_words ( )
static
   Allocate space to write BYTES bytes to the gcov file. Return a
   pointer to those bytes, or NULL on failure.  

References gcov_var::buffer, memcpy(), and gcov_var::offset.