LCOV - code coverage report
Current view: top level - include/llvm/ProfileData - ProfileCommon.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 13 13 100.0 %
Date: 2017-09-14 15:23:50 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- ProfileCommon.h - Common profiling APIs. -----------------*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file contains data structures and functions common to both instrumented
      11             : // and sample profiling.
      12             : //
      13             : //===----------------------------------------------------------------------===//
      14             : 
      15             : #ifndef LLVM_PROFILEDATA_PROFILECOMMON_H
      16             : #define LLVM_PROFILEDATA_PROFILECOMMON_H
      17             : 
      18             : #include "llvm/ADT/ArrayRef.h"
      19             : #include "llvm/IR/ProfileSummary.h"
      20             : #include "llvm/ProfileData/InstrProf.h"
      21             : #include "llvm/Support/Error.h"
      22             : #include <algorithm>
      23             : #include <cstdint>
      24             : #include <functional>
      25             : #include <map>
      26             : #include <memory>
      27             : #include <vector>
      28             : 
      29             : namespace llvm {
      30             : 
      31             : namespace sampleprof {
      32             : 
      33             : class FunctionSamples;
      34             : 
      35             : } // end namespace sampleprof
      36             : 
      37             : inline const char *getHotSectionPrefix() { return ".hot"; }
      38             : inline const char *getUnlikelySectionPrefix() { return ".unlikely"; }
      39             : 
      40             : class ProfileSummaryBuilder {
      41             : private:
      42             :   /// We keep track of the number of times a count (block count or samples)
      43             :   /// appears in the profile. The map is kept sorted in the descending order of
      44             :   /// counts.
      45             :   std::map<uint64_t, uint32_t, std::greater<uint64_t>> CountFrequencies;
      46             :   std::vector<uint32_t> DetailedSummaryCutoffs;
      47             : 
      48             : protected:
      49             :   SummaryEntryVector DetailedSummary;
      50             :   uint64_t TotalCount = 0;
      51             :   uint64_t MaxCount = 0;
      52             :   uint64_t MaxFunctionCount = 0;
      53             :   uint32_t NumCounts = 0;
      54             :   uint32_t NumFunctions = 0;
      55             : 
      56             :   ProfileSummaryBuilder(std::vector<uint32_t> Cutoffs)
      57        1592 :       : DetailedSummaryCutoffs(std::move(Cutoffs)) {}
      58        1556 :   ~ProfileSummaryBuilder() = default;
      59             : 
      60             :   inline void addCount(uint64_t Count);
      61             :   void computeDetailedSummary();
      62             : 
      63             : public:
      64             :   /// \brief A vector of useful cutoff values for detailed summary.
      65             :   static const ArrayRef<uint32_t> DefaultCutoffs;
      66             : };
      67             : 
      68         295 : class InstrProfSummaryBuilder final : public ProfileSummaryBuilder {
      69             :   uint64_t MaxInternalBlockCount = 0;
      70             : 
      71             :   inline void addEntryCount(uint64_t Count);
      72             :   inline void addInternalCount(uint64_t Count);
      73             : 
      74             : public:
      75             :   InstrProfSummaryBuilder(std::vector<uint32_t> Cutoffs)
      76        1216 :       : ProfileSummaryBuilder(std::move(Cutoffs)) {}
      77             : 
      78             :   void addRecord(const InstrProfRecord &);
      79             :   std::unique_ptr<ProfileSummary> getSummary();
      80             : };
      81             : 
      82          94 : class SampleProfileSummaryBuilder final : public ProfileSummaryBuilder {
      83             : public:
      84             :   SampleProfileSummaryBuilder(std::vector<uint32_t> Cutoffs)
      85         376 :       : ProfileSummaryBuilder(std::move(Cutoffs)) {}
      86             : 
      87             :   void addRecord(const sampleprof::FunctionSamples &FS);
      88             :   std::unique_ptr<ProfileSummary> getSummary();
      89             : };
      90             : 
      91             : /// This is called when a count is seen in the profile.
      92        2237 : void ProfileSummaryBuilder::addCount(uint64_t Count) {
      93        2237 :   TotalCount += Count;
      94        2237 :   if (Count > MaxCount)
      95         598 :     MaxCount = Count;
      96        2237 :   NumCounts++;
      97        2237 :   CountFrequencies[Count]++;
      98        2237 : }
      99             : 
     100             : } // end namespace llvm
     101             : 
     102             : #endif // LLVM_PROFILEDATA_PROFILECOMMON_H

Generated by: LCOV version 1.13