Coverage for /Syzygy/bard/events/heap_alloc_event.cc

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
90.2%46510.C++source

Line-by-line coverage:

   1    :  // Copyright 2015 Google Inc. All Rights Reserved.
   2    :  //
   3    :  // Licensed under the Apache License, Version 2.0 (the "License");
   4    :  // you may not use this file except in compliance with the License.
   5    :  // You may obtain a copy of the License at
   6    :  //
   7    :  //     http://www.apache.org/licenses/LICENSE-2.0
   8    :  //
   9    :  // Unless required by applicable law or agreed to in writing, software
  10    :  // distributed under the License is distributed on an "AS IS" BASIS,
  11    :  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12    :  // See the License for the specific language governing permissions and
  13    :  // limitations under the License.
  14    :  
  15    :  #include "syzygy/bard/events/heap_alloc_event.h"
  16    :  
  17    :  #include "syzygy/bard/backdrops/heap_backdrop.h"
  18    :  #include "syzygy/bard/events/play_util.h"
  19    :  
  20    :  namespace bard {
  21    :  namespace events {
  22    :  
  23    :  HeapAllocEvent::HeapAllocEvent(uint32_t stack_trace_id,
  24    :                                 HANDLE trace_heap,
  25    :                                 DWORD flags,
  26    :                                 SIZE_T bytes,
  27    :                                 LPVOID trace_alloc)
  28  E :      : stack_trace_id_(stack_trace_id),
  29  E :        trace_heap_(trace_heap),
  30  E :        flags_(flags),
  31  E :        bytes_(bytes),
  32  E :        trace_alloc_(trace_alloc) {
  33  E :  }
  34    :  
  35    :  bool HeapAllocEvent::Save(const EventInterface* const event,
  36  E :                            core::OutArchive* out_archive) {
  37  E :    DCHECK_NE(static_cast<EventInterface*>(nullptr), event);
  38  E :    DCHECK_NE(static_cast<core::OutArchive*>(nullptr), out_archive);
  39    :  
  40    :    const HeapAllocEvent* derived_event =
  41  E :        reinterpret_cast<const HeapAllocEvent*>(event);
  42    :  
  43  E :    return out_archive->Save(derived_event->stack_trace_id_) &&
  44    :           out_archive->Save(
  45    :               reinterpret_cast<uintptr_t>(derived_event->trace_heap_)) &&
  46    :           out_archive->Save(derived_event->flags_) &&
  47    :           out_archive->Save(derived_event->bytes_) &&
  48    :           out_archive->Save(
  49    :               reinterpret_cast<uintptr_t>(derived_event->trace_alloc_));
  50  E :  }
  51    :  
  52    :  std::unique_ptr<HeapAllocEvent> HeapAllocEvent::Load(
  53  E :      core::InArchive* in_archive) {
  54  E :    DCHECK_NE(static_cast<core::InArchive*>(nullptr), in_archive);
  55    :  
  56  E :    uint32_t stack_trace_id = 0;
  57  E :    uintptr_t trace_heap = 0;
  58  E :    DWORD flags = 0;
  59  E :    SIZE_T bytes = 0;
  60  E :    uintptr_t trace_alloc = 0;
  61    :    if (in_archive->Load(&stack_trace_id) && in_archive->Load(&trace_heap) &&
  62  E :        in_archive->Load(&flags) && in_archive->Load(&bytes) &&
  63    :        in_archive->Load(&trace_alloc)) {
  64  E :      return std::unique_ptr<HeapAllocEvent>(new HeapAllocEvent(
  65    :          stack_trace_id, reinterpret_cast<HANDLE>(trace_heap), flags, bytes,
  66    :          reinterpret_cast<LPVOID>(trace_alloc)));
  67    :    }
  68  i :    return nullptr;
  69  E :  }
  70    :  
  71  E :  bool HeapAllocEvent::Play(void* backdrop) {
  72  E :    DCHECK_NE(static_cast<void*>(nullptr), backdrop);
  73    :  
  74    :    using bard::backdrops::HeapBackdrop;
  75  E :    HeapBackdrop* heap_backdrop = reinterpret_cast<HeapBackdrop*>(backdrop);
  76    :  
  77  E :    HANDLE live_heap = INVALID_HANDLE_VALUE;
  78    :  
  79  E :    if (!heap_backdrop->heap_map().GetLiveFromTrace(trace_heap_, &live_heap))
  80  i :      return false;
  81    :  
  82  E :    uint64_t timing = 0;
  83    :    LPVOID live_alloc =
  84  E :        InvokeOnBackdrop(stack_trace_id_, &timing, heap_backdrop,
  85    :                         &HeapBackdrop::HeapAlloc, live_heap, flags_, bytes_);
  86    :  
  87  E :    if (!live_alloc && trace_alloc_) {
  88  E :      LOG(ERROR) << "HeapAlloc failed to allocate memory.";
  89  E :      return false;
  90    :    }
  91    :  
  92  E :    if (live_alloc) {
  93  E :      if (!trace_alloc_) {
  94    :        // No need to keep this allocation if it failed in the trace file.
  95  i :        heap_backdrop->HeapFree(live_heap, flags_, live_alloc);
  96  E :      } else if (!heap_backdrop->alloc_map().AddMapping(trace_alloc_,
  97    :                                                        live_alloc)) {
  98  i :        return false;
  99    :      }
 100    :    }
 101    :  
 102  E :    heap_backdrop->UpdateStats(type(), timing);
 103    :  
 104  E :    return true;
 105  E :  }
 106    :  
 107  E :  bool HeapAllocEvent::Equals(const EventInterface* rhs) const {
 108  E :    DCHECK_NE(static_cast<EventInterface*>(nullptr), rhs);
 109    :  
 110  E :    if (rhs->type() != kHeapAllocEvent)
 111  i :      return false;
 112    :  
 113  E :    const auto e = reinterpret_cast<const HeapAllocEvent*>(rhs);
 114    :    if (stack_trace_id_ != e->stack_trace_id_ || trace_heap_ != e->trace_heap_ ||
 115  E :        flags_ != e->flags_ || bytes_ != e->bytes_ ||
 116    :        trace_alloc_ != e->trace_alloc_) {
 117  E :      return false;
 118    :    }
 119    :  
 120  E :    return true;
 121  E :  }
 122    :  
 123    :  }  // namespace events
 124    :  }  // namespace bard

Coverage information generated Fri Jul 29 11:00:21 2016.