mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 13:09:40 +00:00
Log time spent on document operations in editor
This commit is contained in:
parent
18d488d968
commit
8383fa3547
2 changed files with 46 additions and 3 deletions
|
@ -6,12 +6,40 @@
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include <components/debug/debuglog.hpp>
|
||||||
|
|
||||||
#include <apps/opencs/model/doc/messages.hpp>
|
#include <apps/opencs/model/doc/messages.hpp>
|
||||||
|
|
||||||
#include "../world/universalid.hpp"
|
#include "../world/universalid.hpp"
|
||||||
|
|
||||||
#include "stage.hpp"
|
#include "stage.hpp"
|
||||||
|
|
||||||
|
namespace CSMDoc
|
||||||
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
std::string_view operationToString(State value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case State_Saving:
|
||||||
|
return "Saving";
|
||||||
|
case State_Merging:
|
||||||
|
return "Merging";
|
||||||
|
case State_Verifying:
|
||||||
|
return "Verifying";
|
||||||
|
case State_Searching:
|
||||||
|
return "Searching";
|
||||||
|
case State_Loading:
|
||||||
|
return "Loading";
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CSMDoc::Operation::prepareStages()
|
void CSMDoc::Operation::prepareStages()
|
||||||
{
|
{
|
||||||
mCurrentStage = mStages.begin();
|
mCurrentStage = mStages.begin();
|
||||||
|
@ -27,7 +55,7 @@ void CSMDoc::Operation::prepareStages()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMDoc::Operation::Operation(int type, bool ordered, bool finalAlways)
|
CSMDoc::Operation::Operation(State type, bool ordered, bool finalAlways)
|
||||||
: mType(type)
|
: mType(type)
|
||||||
, mStages(std::vector<std::pair<Stage*, int>>())
|
, mStages(std::vector<std::pair<Stage*, int>>())
|
||||||
, mCurrentStage(mStages.begin())
|
, mCurrentStage(mStages.begin())
|
||||||
|
@ -61,6 +89,7 @@ void CSMDoc::Operation::run()
|
||||||
}
|
}
|
||||||
|
|
||||||
mPrepared = false;
|
mPrepared = false;
|
||||||
|
mStart = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
mTimer->start(0);
|
mTimer->start(0);
|
||||||
}
|
}
|
||||||
|
@ -140,7 +169,17 @@ void CSMDoc::Operation::executeStage()
|
||||||
emit reportMessage(*iter, mType);
|
emit reportMessage(*iter, mType);
|
||||||
|
|
||||||
if (mCurrentStage == mStages.end())
|
if (mCurrentStage == mStages.end())
|
||||||
|
{
|
||||||
|
if (mStart.has_value())
|
||||||
|
{
|
||||||
|
const auto duration = std::chrono::steady_clock::now() - *mStart;
|
||||||
|
Log(Debug::Verbose) << operationToString(mType) << " operation is completed in "
|
||||||
|
<< std::chrono::duration_cast<std::chrono::duration<double>>(duration).count() << 's';
|
||||||
|
mStart.reset();
|
||||||
|
}
|
||||||
|
|
||||||
operationDone();
|
operationDone();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMDoc::Operation::operationDone()
|
void CSMDoc::Operation::operationDone()
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
#ifndef CSM_DOC_OPERATION_H
|
#ifndef CSM_DOC_OPERATION_H
|
||||||
#define CSM_DOC_OPERATION_H
|
#define CSM_DOC_OPERATION_H
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <optional>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "messages.hpp"
|
#include "messages.hpp"
|
||||||
|
#include "state.hpp"
|
||||||
|
|
||||||
class QTimer;
|
class QTimer;
|
||||||
|
|
||||||
|
@ -18,7 +21,7 @@ namespace CSMDoc
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
int mType;
|
State mType;
|
||||||
std::vector<std::pair<Stage*, int>> mStages; // stage, number of steps
|
std::vector<std::pair<Stage*, int>> mStages; // stage, number of steps
|
||||||
std::vector<std::pair<Stage*, int>>::iterator mCurrentStage;
|
std::vector<std::pair<Stage*, int>>::iterator mCurrentStage;
|
||||||
int mCurrentStep;
|
int mCurrentStep;
|
||||||
|
@ -31,11 +34,12 @@ namespace CSMDoc
|
||||||
QTimer* mTimer;
|
QTimer* mTimer;
|
||||||
bool mPrepared;
|
bool mPrepared;
|
||||||
Message::Severity mDefaultSeverity;
|
Message::Severity mDefaultSeverity;
|
||||||
|
std::optional<std::chrono::steady_clock::time_point> mStart;
|
||||||
|
|
||||||
void prepareStages();
|
void prepareStages();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Operation(int type, bool ordered, bool finalAlways = false);
|
Operation(State type, bool ordered, bool finalAlways = false);
|
||||||
///< \param ordered Stages must be executed in the given order.
|
///< \param ordered Stages must be executed in the given order.
|
||||||
/// \param finalAlways Execute last stage even if an error occurred during earlier stages.
|
/// \param finalAlways Execute last stage even if an error occurred during earlier stages.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue