forked from qt-creator/qt-creator
Since we also license under GPL-3.0 WITH Qt-GPL-exception-1.0,
this applies only to a hypothetical newer version of GPL, that doesn't
exist yet. If such a version emerges, we can still decide to relicense...
While at it, replace (deprecated) GPL-3.0 with more explicit GPL-3.0-only
Change was done by running
find . -type f -exec perl -pi -e "s/LicenseRef-Qt-Commercial OR GPL-3.0\+ OR GPL-3.0 WITH Qt-GPL-exception-1.0/LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0/g" {} \;
Change-Id: I5097e6ce8d10233993ee30d7e25120e2659eb10b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
69 lines
1.5 KiB
C++
69 lines
1.5 KiB
C++
// Copyright (C) 2022 The Qt Company Ltd.
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
|
|
#pragma once
|
|
|
|
#include <QElapsedTimer>
|
|
#include <QLoggingCategory>
|
|
#include <QString>
|
|
|
|
namespace ClangCodeModel::Internal {
|
|
|
|
Q_DECLARE_LOGGING_CATEGORY(clangdLogTiming);
|
|
|
|
// TODO: Generalize, document interface and move to Utils?
|
|
class TaskTimer
|
|
{
|
|
public:
|
|
TaskTimer(const QString &task) : m_task(task) {}
|
|
|
|
void stopTask();
|
|
void startSubtask();
|
|
void stopSubtask(bool isFinalizing);
|
|
|
|
QElapsedTimer startTimer() const { return m_startTimer; }
|
|
|
|
private:
|
|
const QString m_task;
|
|
QElapsedTimer m_timer;
|
|
QElapsedTimer m_startTimer;
|
|
qint64 m_elapsedMs = 0;
|
|
int m_subtasks = 0;
|
|
bool m_started = false;
|
|
bool m_finalized = false;
|
|
};
|
|
|
|
class SubtaskTimer
|
|
{
|
|
public:
|
|
SubtaskTimer(TaskTimer &timer) : m_timer(timer) { m_timer.startSubtask(); }
|
|
~SubtaskTimer() { m_timer.stopSubtask(m_isFinalizing); }
|
|
|
|
protected:
|
|
void makeFinalizing() { m_isFinalizing = true; }
|
|
|
|
private:
|
|
TaskTimer &m_timer;
|
|
bool m_isFinalizing = false;
|
|
};
|
|
|
|
class FinalizingSubtaskTimer : public SubtaskTimer
|
|
{
|
|
public:
|
|
FinalizingSubtaskTimer(TaskTimer &timer) : SubtaskTimer(timer) { makeFinalizing(); }
|
|
};
|
|
|
|
class ThreadedSubtaskTimer
|
|
{
|
|
public:
|
|
ThreadedSubtaskTimer(const QString &task, const TaskTimer &taskTimer);
|
|
~ThreadedSubtaskTimer();
|
|
|
|
private:
|
|
const QString m_task;
|
|
QElapsedTimer m_timer;
|
|
const TaskTimer &m_taskTimer;
|
|
};
|
|
|
|
} // namespace ClangCodeModel::Internal
|