Clang: Watch directories instead of files

Because there a limited resources to watch files we watch now directories.
So we need much less resources.

Change-Id: Iac558832e9521a7a1a67c5ea99b42ad1b0b5129c
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2019-06-06 10:57:55 +02:00
parent 9d290fc682
commit bbd58ca30b
38 changed files with 1485 additions and 541 deletions

View File

@@ -17,8 +17,6 @@ HEADERS += \
$$PWD/symbolsvisitorbase.h \
$$PWD/usedmacro.h \
$$PWD/sourcedependency.h \
$$PWD/filestatus.h \
$$PWD/filestatuscache.h \
$$PWD/indexdataconsumer.h \
$$PWD/sourcesmanager.h \
$$PWD/symbolindexertaskqueue.h \
@@ -67,5 +65,4 @@ HEADERS += \
SOURCES += \
$$PWD/filestatuspreprocessorcallbacks.cpp \
$$PWD/sourcerangefilter.cpp \
$$PWD/symbolindexer.cpp \
$$PWD/filestatuscache.cpp
$$PWD/symbolindexer.cpp

View File

@@ -1,63 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <filepathid.h>
#include <ctime>
#include <sys/types.h>
#include <vector>
namespace ClangBackEnd {
class FileStatus
{
public:
FileStatus(FilePathId filePathId, off_t size, std::time_t lastModified)
: filePathId(filePathId), size(size), lastModified(lastModified) {}
friend
bool operator==(const FileStatus &first, const FileStatus &second)
{
return first.filePathId == second.filePathId
&& first.size == second.size
&& first.lastModified == second.lastModified;
}
friend
bool operator<(const FileStatus &first, const FileStatus &second)
{
return first.filePathId < second.filePathId;
}
public:
FilePathId filePathId;
off_t size;
std::time_t lastModified;
};
using FileStatuses = std::vector<FileStatus>;
}

View File

@@ -1,93 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "filestatuscache.h"
#include <QDateTime>
#include <QFileInfo>
namespace ClangBackEnd {
FileStatusCache::FileStatusCache(FilePathCachingInterface &filePathCache)
: m_filePathCache(filePathCache)
{
}
long long FileStatusCache::lastModifiedTime(FilePathId filePathId) const
{
return findEntry(filePathId).lastModified;
}
void FileStatusCache::update(FilePathId filePathId)
{
auto found = std::lower_bound(m_cacheEntries.begin(),
m_cacheEntries.end(),
Internal::FileStatusCacheEntry{filePathId},
[] (const auto &first, const auto &second) {
return first.filePathId < second.filePathId;
});
if (found != m_cacheEntries.end() && found->filePathId == filePathId) {
QFileInfo fileInfo = qFileInfo(filePathId);
found->lastModified = fileInfo.lastModified().toMSecsSinceEpoch() / 1000;
}
}
FileStatusCache::size_type FileStatusCache::size() const
{
return m_cacheEntries.size();
}
Internal::FileStatusCacheEntry FileStatusCache::findEntry(FilePathId filePathId) const
{
auto found = std::lower_bound(m_cacheEntries.begin(),
m_cacheEntries.end(),
Internal::FileStatusCacheEntry{filePathId},
[] (const auto &first, const auto &second) {
return first.filePathId < second.filePathId;
});
if (found != m_cacheEntries.end() && found->filePathId == filePathId)
return *found;
QFileInfo fileInfo = qFileInfo(filePathId);
auto inserted = m_cacheEntries.emplace(found,
filePathId,
fileInfo.lastModified().toMSecsSinceEpoch() / 1000);
return *inserted;
}
QFileInfo FileStatusCache::qFileInfo(FilePathId filePathId) const
{
QFileInfo fileInfo(QString(m_filePathCache.filePath(filePathId)));
fileInfo.refresh();
return fileInfo;
}
} // namespace ClangBackEnd

View File

@@ -1,76 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <filepathcachinginterface.h>
QT_FORWARD_DECLARE_CLASS(QFileInfo)
namespace ClangBackEnd {
namespace Internal {
class FileStatusCacheEntry
{
public:
FileStatusCacheEntry(ClangBackEnd::FilePathId filePathId,
long long lastModified = 0)
: filePathId(filePathId),
lastModified(lastModified)
{}
public:
ClangBackEnd::FilePathId filePathId;
long long lastModified;
};
using FileStatusCacheEntries = std::vector<FileStatusCacheEntry>;
}
class FileStatusCache
{
public:
using size_type = Internal::FileStatusCacheEntries::size_type;
FileStatusCache(FilePathCachingInterface &filePathCache);
FileStatusCache &operator=(const FileStatusCache &) = delete;
FileStatusCache(const FileStatusCache &) = delete;
long long lastModifiedTime(ClangBackEnd::FilePathId filePathId) const;
void update(ClangBackEnd::FilePathId filePathId);
size_type size() const;
private:
Internal::FileStatusCacheEntry findEntry(ClangBackEnd::FilePathId filePathId) const;
QFileInfo qFileInfo(ClangBackEnd::FilePathId filePathId) const;
private:
mutable Internal::FileStatusCacheEntries m_cacheEntries;
FilePathCachingInterface &m_filePathCache;
};
} // namespace ClangBackEnd

View File

@@ -39,6 +39,7 @@
#include <projectpartsstorage.h>
#include <filepathcachingfwd.h>
#include <filesystem.h>
#include <modifiedtimechecker.h>
#include <refactoringdatabaseinitializer.h>
@@ -142,8 +143,9 @@ private:
PrecompiledHeaderStorage<Sqlite::Database> m_precompiledHeaderStorage;
ProjectPartsStorage<Sqlite::Database> m_projectPartsStorage;
SymbolStorage m_symbolStorage;
ClangPathWatcher<QFileSystemWatcher, QTimer> m_sourceWatcher{m_filePathCache};
FileStatusCache m_fileStatusCache{m_filePathCache};
FileSystem m_fileSytem{m_filePathCache};
ClangPathWatcher<QFileSystemWatcher, QTimer> m_sourceWatcher{m_filePathCache, m_fileSytem};
FileStatusCache m_fileStatusCache{m_fileSytem};
SymbolsCollectorManager m_collectorManger;
ProgressCounter m_progressCounter;
std::function<TimeStamp(FilePathView filePath)> getModifiedTime{