1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_RUNTIME_GC_COLLECTOR_ITERATION_H_
18 #define ART_RUNTIME_GC_COLLECTOR_ITERATION_H_
19 
20 #include <inttypes.h>
21 #include <vector>
22 
23 #include "android-base/macros.h"
24 #include "base/timing_logger.h"
25 #include "gc/gc_cause.h"
26 #include "object_byte_pair.h"
27 
28 namespace art {
29 namespace gc {
30 namespace collector {
31 
32 // A information related single garbage collector iteration. Since we only ever have one GC running
33 // at any given time, we can have a single iteration info.
34 class Iteration {
35  public:
36   Iteration();
37   // Returns how long the mutators were paused in nanoseconds.
GetPauseTimes()38   const std::vector<uint64_t>& GetPauseTimes() const {
39     return pause_times_;
40   }
GetTimings()41   TimingLogger* GetTimings() {
42     return &timings_;
43   }
44   // Returns how long the GC took to complete in nanoseconds.
GetDurationNs()45   uint64_t GetDurationNs() const {
46     return duration_ns_;
47   }
GetFreedBytes()48   int64_t GetFreedBytes() const {
49     return freed_.bytes;
50   }
GetFreedLargeObjectBytes()51   int64_t GetFreedLargeObjectBytes() const {
52     return freed_los_.bytes;
53   }
GetFreedObjects()54   uint64_t GetFreedObjects() const {
55     return freed_.objects;
56   }
GetFreedLargeObjects()57   uint64_t GetFreedLargeObjects() const {
58     return freed_los_.objects;
59   }
GetFreedRevokeBytes()60   uint64_t GetFreedRevokeBytes() const {
61     return freed_bytes_revoke_;
62   }
GetScannedBytes()63   uint64_t GetScannedBytes() const {
64     return bytes_scanned_;
65   }
SetScannedBytes(uint64_t bytes)66   void SetScannedBytes(uint64_t bytes) {
67       bytes_scanned_ = bytes;
68   }
SetFreedRevoke(uint64_t freed)69   void SetFreedRevoke(uint64_t freed) {
70     freed_bytes_revoke_ = freed;
71   }
72   void Reset(GcCause gc_cause, bool clear_soft_references);
73   // Returns the estimated throughput of the iteration.
74   uint64_t GetEstimatedThroughput() const;
GetClearSoftReferences()75   bool GetClearSoftReferences() const {
76     return clear_soft_references_;
77   }
SetClearSoftReferences(bool clear_soft_references)78   void SetClearSoftReferences(bool clear_soft_references) {
79     clear_soft_references_ = clear_soft_references;
80   }
GetGcCause()81   GcCause GetGcCause() const {
82     return gc_cause_;
83   }
84 
85  private:
SetDurationNs(uint64_t duration)86   void SetDurationNs(uint64_t duration) {
87     duration_ns_ = duration;
88   }
89 
90   GcCause gc_cause_;
91   bool clear_soft_references_;
92   uint64_t duration_ns_;
93   uint64_t bytes_scanned_;
94   TimingLogger timings_;
95   ObjectBytePair freed_;
96   ObjectBytePair freed_los_;
97   uint64_t freed_bytes_revoke_;  // see Heap::num_bytes_freed_revoke_.
98   std::vector<uint64_t> pause_times_;
99 
100   friend class GarbageCollector;
101   DISALLOW_COPY_AND_ASSIGN(Iteration);
102 };
103 
104 }  // namespace collector
105 }  // namespace gc
106 }  // namespace art
107 
108 #endif  // ART_RUNTIME_GC_COLLECTOR_ITERATION_H_
109