[cfe-commits] r64345 - in /cfe/trunk: include/clang/Basic/FileManager.h lib/Basic/FileManager.cpp
Ted Kremenek
kremenek at apple.com
Wed Feb 11 16:39:05 PST 2009
Author: kremenek
Date: Wed Feb 11 18:39:05 2009
New Revision: 64345
URL: http://llvm.org/viewvc/llvm-project?rev=64345&view=rev
Log:
Add lightweight shim "clang::StatSysCallCache" that caches 'stat' system calls
for use by FileManager. FileManager now takes a StatSysCallCache* in its
constructor (which defaults to NULL). This will be used for evaluating whether
or not caching 'stat' system calls in PTH is a performance win. This shim adds
no observable performance impact in the case where the 'StatSysCallCache*' is
null.
Modified:
cfe/trunk/include/clang/Basic/FileManager.h
cfe/trunk/lib/Basic/FileManager.cpp
Modified: cfe/trunk/include/clang/Basic/FileManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=64345&r1=64344&r2=64345&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Wed Feb 11 18:39:05 2009
@@ -22,6 +22,7 @@
#include <string>
// FIXME: Enhance libsystem to support inode and other fields in stat.
#include <sys/types.h>
+#include <sys/stat.h>
namespace clang {
class FileManager;
@@ -68,6 +69,14 @@
}
};
+// FIXME: This is a lightweight shim that is used by FileManager to cache
+// 'stat' system calls. We will use it with PTH to identify if caching
+// stat calls in PTH files is a performance win.
+class StatSysCallCache {
+public:
+ virtual ~StatSysCallCache() {}
+ virtual int stat(const char *path, struct stat *buf) = 0;
+};
/// FileManager - Implements support for file system lookup, file system
/// caching, and directory search management. This also handles more advanced
@@ -97,8 +106,15 @@
// Statistics.
unsigned NumDirLookups, NumFileLookups;
unsigned NumDirCacheMisses, NumFileCacheMisses;
+
+ // Caching.
+ StatSysCallCache *StatCache;
+ int stat_cached(const char* path, struct stat* buf) {
+ return StatCache ? StatCache->stat(path, buf) : stat(path, buf);
+ }
+
public:
- FileManager();
+ FileManager(StatSysCallCache *statCache = 0);
~FileManager();
/// getDirectory - Lookup, cache, and verify the specified directory. This
Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=64345&r1=64344&r2=64345&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Wed Feb 11 18:39:05 2009
@@ -29,7 +29,7 @@
#include <sys/stat.h>
#if defined(_MSC_VER)
-#define S_ISDIR(s) (_S_IFDIR & s)
+#defisstne S_ISDIR(s) (_S_IFDIR & s)
#endif
/// NON_EXISTENT_DIR - A special value distinct from null that is used to
@@ -134,10 +134,11 @@
// Common logic.
//===----------------------------------------------------------------------===//
-FileManager::FileManager() : UniqueDirs(*new UniqueDirContainer),
- UniqueFiles(*new UniqueFileContainer),
- DirEntries(64), FileEntries(64), NextFileUID(0)
-{
+FileManager::FileManager(StatSysCallCache* statCache)
+ : UniqueDirs(*new UniqueDirContainer),
+ UniqueFiles(*new UniqueFileContainer),
+ DirEntries(64), FileEntries(64), NextFileUID(0),
+ StatCache(statCache) {
NumDirLookups = NumFileLookups = 0;
NumDirCacheMisses = NumFileCacheMisses = 0;
}
@@ -145,6 +146,7 @@
FileManager::~FileManager() {
delete &UniqueDirs;
delete &UniqueFiles;
+ delete StatCache;
}
@@ -173,7 +175,7 @@
// Check to see if the directory exists.
struct stat StatBuf;
- if (stat(InterndDirName, &StatBuf) || // Error stat'ing.
+ if (stat_cached(InterndDirName, &StatBuf) || // Error stat'ing.
!S_ISDIR(StatBuf.st_mode)) // Not a directory?
return 0;
@@ -246,8 +248,8 @@
// Nope, there isn't. Check to see if the file exists.
struct stat StatBuf;
//llvm::cerr << "STATING: " << Filename;
- if (stat(InterndFileName, &StatBuf) || // Error stat'ing.
- S_ISDIR(StatBuf.st_mode)) { // A directory?
+ if (stat_cached(InterndFileName, &StatBuf) || // Error stat'ing.
+ S_ISDIR(StatBuf.st_mode)) { // A directory?
// If this file doesn't exist, we leave a null in FileEntries for this path.
//llvm::cerr << ": Not existing\n";
return 0;
More information about the cfe-commits
mailing list