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   }
SetFreedRevoke(uint64_t freed)63   void SetFreedRevoke(uint64_t freed) {
64     freed_bytes_revoke_ = freed;
65   }
66   void Reset(GcCause gc_cause, bool clear_soft_references);
67   // Returns the estimated throughput of the iteration.
68   uint64_t GetEstimatedThroughput() const;
GetClearSoftReferences()69   bool GetClearSoftReferences() const {
70     return clear_soft_references_;
71   }
SetClearSoftReferences(bool clear_soft_references)72   void SetClearSoftReferences(bool clear_soft_references) {
73     clear_soft_references_ = clear_soft_references;
74   }
GetGcCause()75   GcCause GetGcCause() const {
76     return gc_cause_;
77   }
78 
79  private:
SetDurationNs(uint64_t duration)80   void SetDurationNs(uint64_t duration) {
81     duration_ns_ = duration;
82   }
83 
84   GcCause gc_cause_;
85   bool clear_soft_references_;
86   uint64_t duration_ns_;
87   TimingLogger timings_;
88   ObjectBytePair freed_;
89   ObjectBytePair freed_los_;
90   uint64_t freed_bytes_revoke_;  // see Heap::num_bytes_freed_revoke_.
91   std::vector<uint64_t> pause_times_;
92 
93   friend class GarbageCollector;
94   DISALLOW_COPY_AND_ASSIGN(Iteration);
95 };
96 
97 }  // namespace collector
98 }  // namespace gc
99 }  // namespace art
100 
101 #endif  // ART_RUNTIME_GC_COLLECTOR_ITERATION_H_
102