forked from qt-creator/qt-creator
Clang: Add possibility to "pgo-train" libclang with a batch file
This allows to start Qt Creator in batch processing mode:
$ export QTC_CLANG_BATCH=/path/to/file
$ export QT_LOGGING_RULES=qtc.clangcodemodel.batch=true
$ ./qtcreator -load ClangCodeModel
The batch file will be executed and Qt Creator will exit. Advanced
logging output can be activated as stated above.
Note that it is required that the project was already configured/set up
properly with the used settingspath, otherwise the wrong configuration
will be taken or a pop-up dialog will block the execution.
A small example follows that covers all the understood and so far needed
batch file commands in order to train libclang for profile guided
optimization. ${PWD} expands to the directory of the batch file.
openProject "${PWD}/calendarwidget.pro"
# Initial parsing
openDocument "${PWD}/window.cpp"
closeAllDocuments
openDocument "${PWD}/window.cpp"
# Reparse
setCursor 478 1
insertText " "
insertText " "
insertText " "
# Completion
complete
complete
complete
# Member completion
insertText "comboBox->"
complete
complete
complete
# Wait in order to inspect the result
processEvents 3000
Change-Id: Ib30526036f999e530f0c01d42a196a1e311e2c4c
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "clangcodecompletion_test.h"
|
||||
|
||||
#include "../clangautomationutils.h"
|
||||
#include "../clangbackendipcintegration.h"
|
||||
#include "../clangcompletionassistinterface.h"
|
||||
#include "../clangmodelmanagersupport.h"
|
||||
@@ -38,12 +39,8 @@
|
||||
#include <cpptools/cpptoolstestcase.h>
|
||||
#include <cpptools/modelmanagertesthelper.h>
|
||||
#include <cpptools/projectinfo.h>
|
||||
#include <texteditor/codeassist/assistinterface.h>
|
||||
#include <texteditor/codeassist/assistproposalitem.h>
|
||||
#include <texteditor/codeassist/completionassistprovider.h>
|
||||
#include <texteditor/codeassist/genericproposalmodel.h>
|
||||
#include <texteditor/codeassist/iassistprocessor.h>
|
||||
#include <texteditor/codeassist/iassistproposal.h>
|
||||
#include <texteditor/textdocument.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
|
||||
@@ -180,53 +177,6 @@ void insertTextAtTopOfEditor(TextEditor::BaseTextEditor *editor, const QByteArra
|
||||
cs.apply(&textCursor);
|
||||
}
|
||||
|
||||
class WaitForAsyncCompletions
|
||||
{
|
||||
public:
|
||||
enum WaitResult { GotResults, GotInvalidResults, Timeout };
|
||||
WaitResult wait(TextEditor::IAssistProcessor *processor,
|
||||
TextEditor::AssistInterface *assistInterface);
|
||||
|
||||
TextEditor::IAssistProposalModel *proposalModel;
|
||||
};
|
||||
|
||||
WaitForAsyncCompletions::WaitResult WaitForAsyncCompletions::wait(
|
||||
TextEditor::IAssistProcessor *processor,
|
||||
TextEditor::AssistInterface *assistInterface)
|
||||
{
|
||||
QTC_ASSERT(processor, return Timeout);
|
||||
QTC_ASSERT(assistInterface, return Timeout);
|
||||
|
||||
bool gotResults = false;
|
||||
|
||||
processor->setAsyncCompletionAvailableHandler(
|
||||
[this, &gotResults] (TextEditor::IAssistProposal *proposal) {
|
||||
QTC_ASSERT(proposal, return);
|
||||
proposalModel = proposal->model();
|
||||
delete proposal;
|
||||
gotResults = true;
|
||||
});
|
||||
|
||||
// Are there any immediate results?
|
||||
if (TextEditor::IAssistProposal *proposal = processor->perform(assistInterface)) {
|
||||
delete processor;
|
||||
proposalModel = proposal->model();
|
||||
delete proposal;
|
||||
QTC_ASSERT(proposalModel, return GotInvalidResults);
|
||||
return GotResults;
|
||||
}
|
||||
|
||||
// There are not any, so wait for async results.
|
||||
QElapsedTimer timer; timer.start();
|
||||
while (!gotResults) {
|
||||
if (timer.elapsed() >= 30 * 1000)
|
||||
return Timeout;
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
|
||||
return proposalModel ? GotResults : GotInvalidResults;
|
||||
}
|
||||
|
||||
class ChangeDocumentReloadSetting
|
||||
{
|
||||
public:
|
||||
@@ -421,51 +371,6 @@ public:
|
||||
QString senderLog;
|
||||
};
|
||||
|
||||
const CppTools::ProjectPartHeaderPaths toHeaderPaths(const QStringList &paths)
|
||||
{
|
||||
using namespace CppTools;
|
||||
|
||||
ProjectPartHeaderPaths result;
|
||||
foreach (const QString &path, paths)
|
||||
result << ProjectPartHeaderPath(path, ProjectPartHeaderPath::IncludePath);
|
||||
return result;
|
||||
}
|
||||
|
||||
using ProposalModel = QSharedPointer<TextEditor::IAssistProposalModel>;
|
||||
|
||||
ProposalModel completionResults(
|
||||
TextEditor::BaseTextEditor *textEditor,
|
||||
const QStringList &includePaths = QStringList())
|
||||
{
|
||||
using namespace TextEditor;
|
||||
|
||||
TextEditorWidget *textEditorWidget = qobject_cast<TextEditorWidget *>(textEditor->widget());
|
||||
QTC_ASSERT(textEditorWidget, return ProposalModel());
|
||||
AssistInterface *assistInterface = textEditorWidget->createAssistInterface(
|
||||
TextEditor::Completion, TextEditor::ExplicitlyInvoked);
|
||||
QTC_ASSERT(assistInterface, return ProposalModel());
|
||||
if (!includePaths.isEmpty()) {
|
||||
auto clangAssistInterface = static_cast<ClangCompletionAssistInterface *>(assistInterface);
|
||||
clangAssistInterface->setHeaderPaths(toHeaderPaths(includePaths));
|
||||
}
|
||||
|
||||
CompletionAssistProvider *assistProvider
|
||||
= textEditor->textDocument()->completionAssistProvider();
|
||||
QTC_ASSERT(qobject_cast<ClangCompletionAssistProvider *>(assistProvider),
|
||||
return ProposalModel());
|
||||
QTC_ASSERT(assistProvider, return ProposalModel());
|
||||
QTC_ASSERT(assistProvider->runType() == IAssistProvider::Asynchronous, return ProposalModel());
|
||||
|
||||
IAssistProcessor *processor = assistProvider->createProcessor();
|
||||
QTC_ASSERT(processor, return ProposalModel());
|
||||
|
||||
WaitForAsyncCompletions waitForCompletions;
|
||||
const WaitForAsyncCompletions::WaitResult result = waitForCompletions.wait(processor,
|
||||
assistInterface);
|
||||
QTC_ASSERT(result == WaitForAsyncCompletions::GotResults, return ProposalModel());
|
||||
return QSharedPointer<TextEditor::IAssistProposalModel>(waitForCompletions.proposalModel);
|
||||
}
|
||||
|
||||
class TestDocument
|
||||
{
|
||||
public:
|
||||
@@ -689,7 +594,7 @@ public:
|
||||
if (!textToInsert.isEmpty())
|
||||
openEditor.editor()->insert(textToInsert);
|
||||
|
||||
proposal = completionResults(openEditor.editor(), includePaths);
|
||||
proposal = completionResults(openEditor.editor(), includePaths, 15000);
|
||||
}
|
||||
|
||||
ProposalModel proposal;
|
||||
|
||||
Reference in New Issue
Block a user