Googler | 813d3bd | 2024-01-24 08:16:08 -0800 | [diff] [blame] | 1 | // Copyright 2024 The Bazel Authors. 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 | package com.google.devtools.build.lib.metrics; |
| 16 | |
| 17 | import com.google.auto.value.AutoValue; |
| 18 | import com.google.common.collect.ImmutableMap; |
| 19 | import java.time.Instant; |
| 20 | |
| 21 | /** Contains a snapshot of the resource usage of multiple processes. */ |
| 22 | @AutoValue |
| 23 | public abstract class ResourceSnapshot { |
| 24 | /** Overall memory consumption by all descendant processes including initial process. */ |
| 25 | public abstract ImmutableMap<Long, Integer> getPidToMemoryInKb(); |
| 26 | |
| 27 | /** Time when this snapshot was collected. */ |
| 28 | public abstract Instant getCollectionTime(); |
| 29 | |
| 30 | public static ResourceSnapshot create( |
| 31 | ImmutableMap<Long, Integer> pidToMemoryInKb, Instant collectionTime) { |
| 32 | return new AutoValue_ResourceSnapshot(pidToMemoryInKb, collectionTime); |
| 33 | } |
| 34 | |
Googler | c3c8f15 | 2024-02-08 04:03:05 -0800 | [diff] [blame] | 35 | public static ResourceSnapshot createEmpty(Instant collectionTime) { |
| 36 | return new AutoValue_ResourceSnapshot(ImmutableMap.of(), collectionTime); |
Googler | 813d3bd | 2024-01-24 08:16:08 -0800 | [diff] [blame] | 37 | } |
| 38 | } |