LLVM  4.0.0
CachePruning.h
Go to the documentation of this file.
1 //=- CachePruning.h - Helper to manage the pruning of a cache dir -*- 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 implements pruning of a directory intended for cache storage, using
11 // various policies.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_SUPPORT_CACHE_PRUNING_H
16 #define LLVM_SUPPORT_CACHE_PRUNING_H
17 
18 #include "llvm/ADT/StringRef.h"
19 #include <chrono>
20 
21 namespace llvm {
22 
23 /// Handle pruning a directory provided a path and some options to control what
24 /// to prune.
25 class CachePruning {
26 public:
27  /// Prepare to prune \p Path.
28  CachePruning(StringRef Path) : Path(Path) {}
29 
30  /// Define the pruning interval. This is intended to be used to avoid scanning
31  /// the directory too often. It does not impact the decision of which file to
32  /// prune. A value of 0 forces the scan to occurs.
33  CachePruning &setPruningInterval(std::chrono::seconds PruningInterval) {
34  Interval = PruningInterval;
35  return *this;
36  }
37 
38  /// Define the expiration for a file. When a file hasn't been accessed for
39  /// \p ExpireAfter seconds, it is removed from the cache. A value of 0 disable
40  /// the expiration-based pruning.
41  CachePruning &setEntryExpiration(std::chrono::seconds ExpireAfter) {
42  Expiration = ExpireAfter;
43  return *this;
44  }
45 
46  /// Define the maximum size for the cache directory, in terms of percentage of
47  /// the available space on the the disk. Set to 100 to indicate no limit, 50
48  /// to indicate that the cache size will not be left over half the
49  /// available disk space. A value over 100 will be reduced to 100. A value of
50  /// 0 disable the size-based pruning.
51  CachePruning &setMaxSize(unsigned Percentage) {
52  PercentageOfAvailableSpace = std::min(100u, Percentage);
53  return *this;
54  }
55 
56  /// Peform pruning using the supplied options, returns true if pruning
57  /// occured, i.e. if PruningInterval was expired.
58  bool prune();
59 
60 private:
61  // Options that matches the setters above.
62  std::string Path;
63  std::chrono::seconds Expiration = std::chrono::seconds::zero();
64  std::chrono::seconds Interval = std::chrono::seconds::zero();
65  unsigned PercentageOfAvailableSpace = 0;
66 };
67 
68 } // namespace llvm
69 
70 #endif
CachePruning(StringRef Path)
Prepare to prune Path.
Definition: CachePruning.h:28
Interval Class - An Interval is a set of nodes defined such that every node in the interval has all o...
Definition: Interval.h:37
CachePruning & setEntryExpiration(std::chrono::seconds ExpireAfter)
Define the expiration for a file.
Definition: CachePruning.h:41
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with etc Experimental Use value profile to guide fuzzing Number of simultaneous worker processes to run the jobs If zero
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with etc Experimental Use value profile to guide fuzzing Number of simultaneous worker processes to run the jobs If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
CachePruning & setMaxSize(unsigned Percentage)
Define the maximum size for the cache directory, in terms of percentage of the available space on the...
Definition: CachePruning.h:51
bool prune()
Peform pruning using the supplied options, returns true if pruning occured, i.e.
CachePruning & setPruningInterval(std::chrono::seconds PruningInterval)
Define the pruning interval.
Definition: CachePruning.h:33
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
Handle pruning a directory provided a path and some options to control what to prune.
Definition: CachePruning.h:25