mirror of
https://github.com/lubosz/overte.git
synced 2025-04-14 03:06:20 +02:00
Add file logging to perf tool
This commit is contained in:
parent
f33d3a3b36
commit
2a058fa419
3 changed files with 110 additions and 62 deletions
|
@ -9,14 +9,29 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <qdir.h>
|
||||
#include <qfileinfo.h>
|
||||
#include <qdesktopservices.h>
|
||||
#include <qprocess.h>
|
||||
#include <qurl.h>
|
||||
|
||||
#include "FileUtils.h"
|
||||
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QProcess>
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtCore/QTextStream>
|
||||
#include <QtCore/QRegularExpression>
|
||||
#include <QtGui/QDesktopServices>
|
||||
|
||||
|
||||
QString FileUtils::readFile(const QString& filename) {
|
||||
QFile file(filename);
|
||||
file.open(QFile::Text | QFile::ReadOnly);
|
||||
QString result;
|
||||
result.append(QTextStream(&file).readAll());
|
||||
return result;
|
||||
}
|
||||
|
||||
QStringList FileUtils::readLines(const QString& filename, QString::SplitBehavior splitBehavior) {
|
||||
return readFile(filename).split(QRegularExpression("[\\r\\n]"), QString::SkipEmptyParts);
|
||||
}
|
||||
|
||||
void FileUtils::locateFile(QString filePath) {
|
||||
|
||||
|
|
|
@ -19,7 +19,8 @@ class FileUtils {
|
|||
public:
|
||||
static void locateFile(QString fileName);
|
||||
static QString standardPath(QString subfolder);
|
||||
|
||||
static QString readFile(const QString& filename);
|
||||
static QStringList readLines(const QString& filename, QString::SplitBehavior splitBehavior = QString::KeepEmptyParts);
|
||||
};
|
||||
|
||||
#endif // hifi_FileUtils_h
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <QtCore/QDir>
|
||||
#include <QtCore/QElapsedTimer>
|
||||
#include <QtCore/QLoggingCategory>
|
||||
#include <QtCore/QRegularExpression>
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtCore/QThread>
|
||||
#include <QtCore/QThreadPool>
|
||||
|
@ -34,6 +35,7 @@
|
|||
#include <shared/RateCounter.h>
|
||||
#include <shared/NetworkUtils.h>
|
||||
#include <shared/FileLogger.h>
|
||||
#include <shared/FileUtils.h>
|
||||
#include <LogHandler.h>
|
||||
#include <AssetClient.h>
|
||||
|
||||
|
@ -98,57 +100,6 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
#if 0
|
||||
class GlfwCamera : public Camera {
|
||||
Key forKey(int key) {
|
||||
switch (key) {
|
||||
case GLFW_KEY_W: return FORWARD;
|
||||
case GLFW_KEY_S: return BACK;
|
||||
case GLFW_KEY_A: return LEFT;
|
||||
case GLFW_KEY_D: return RIGHT;
|
||||
case GLFW_KEY_E: return UP;
|
||||
case GLFW_KEY_C: return DOWN;
|
||||
case GLFW_MOUSE_BUTTON_LEFT: return MLEFT;
|
||||
case GLFW_MOUSE_BUTTON_RIGHT: return MRIGHT;
|
||||
case GLFW_MOUSE_BUTTON_MIDDLE: return MMIDDLE;
|
||||
default: break;
|
||||
}
|
||||
return INVALID;
|
||||
}
|
||||
|
||||
vec2 _lastMouse;
|
||||
public:
|
||||
void keyHandler(int key, int scancode, int action, int mods) {
|
||||
Key k = forKey(key);
|
||||
if (k == INVALID) {
|
||||
return;
|
||||
}
|
||||
if (action == GLFW_PRESS) {
|
||||
keys.set(k);
|
||||
} else if (action == GLFW_RELEASE) {
|
||||
keys.reset(k);
|
||||
}
|
||||
}
|
||||
|
||||
//static void MouseMoveHandler(GLFWwindow* window, double posx, double posy);
|
||||
//static void MouseScrollHandler(GLFWwindow* window, double xoffset, double yoffset);
|
||||
void onMouseMove(double posx, double posy) {
|
||||
vec2 mouse = vec2(posx, posy);
|
||||
vec2 delta = mouse - _lastMouse;
|
||||
if (keys.at(Key::MRIGHT)) {
|
||||
dolly(delta.y * 0.01f);
|
||||
} else if (keys.at(Key::MLEFT)) {
|
||||
rotate(delta.x * -0.01f);
|
||||
} else if (keys.at(Key::MMIDDLE)) {
|
||||
delta.y *= -1.0f;
|
||||
translate(delta * -0.01f);
|
||||
}
|
||||
_lastMouse = mouse;
|
||||
}
|
||||
|
||||
};
|
||||
#else
|
||||
|
||||
class QWindowCamera : public Camera {
|
||||
Key forKey(int key) {
|
||||
switch (key) {
|
||||
|
@ -198,7 +149,6 @@ public:
|
|||
_lastMouse = mouse;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
static QString toHumanSize(size_t size, size_t maxUnit = std::numeric_limits<size_t>::max()) {
|
||||
static const std::vector<QString> SUFFIXES{ { "B", "KB", "MB", "GB", "TB", "PB" } };
|
||||
|
@ -241,7 +191,7 @@ public:
|
|||
std::mutex _mutex;
|
||||
std::shared_ptr<gpu::Backend> _backend;
|
||||
std::vector<uint64_t> _frameTimes;
|
||||
size_t _frameIndex;
|
||||
size_t _frameIndex { 0 };
|
||||
std::mutex _frameLock;
|
||||
std::queue<gpu::FramePointer> _pendingFrames;
|
||||
gpu::FramePointer _activeFrame;
|
||||
|
@ -253,7 +203,6 @@ public:
|
|||
_pendingFrames.push(frame);
|
||||
}
|
||||
|
||||
|
||||
void initialize(QWindow* window, gl::Context& initContext) {
|
||||
setObjectName("RenderThread");
|
||||
_context.setWindow(window);
|
||||
|
@ -372,7 +321,6 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
bool process() override {
|
||||
std::queue<gpu::FramePointer> pendingFrames;
|
||||
{
|
||||
|
@ -590,6 +538,16 @@ public:
|
|||
DependencyManager::destroy<NodeList>();
|
||||
}
|
||||
|
||||
void loadCommands(const QString& filename) {
|
||||
QFileInfo fileInfo(filename);
|
||||
if (!fileInfo.exists()) {
|
||||
return;
|
||||
}
|
||||
_commandPath = fileInfo.absolutePath();
|
||||
_commands = FileUtils::readLines(filename);
|
||||
_commandIndex = 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
bool eventFilter(QObject *obj, QEvent *event) override {
|
||||
|
@ -780,10 +738,76 @@ private:
|
|||
#endif
|
||||
}
|
||||
|
||||
void runCommand(const QString& command) {
|
||||
QStringList commandParams = command.split(QRegularExpression(QString("\\s")));
|
||||
QString verb = commandParams[0].toLower();
|
||||
if (verb == "loop") {
|
||||
if (commandParams.length() > 1) {
|
||||
int maxLoops = commandParams[1].toInt();
|
||||
if (maxLoops > ++_commandLoops) {
|
||||
qDebug() << "Exceeded loop count";
|
||||
return;
|
||||
}
|
||||
}
|
||||
_commandIndex = 0;
|
||||
} else if (verb == "wait") {
|
||||
if (commandParams.length() < 2) {
|
||||
qDebug() << "No wait time specified";
|
||||
return;
|
||||
}
|
||||
int seconds = commandParams[1].toInt();
|
||||
_nextCommandTime = usecTimestampNow() + seconds * USECS_PER_SECOND;
|
||||
} else if (verb == "load") {
|
||||
if (commandParams.length() < 2) {
|
||||
qDebug() << "No load file specified";
|
||||
return;
|
||||
}
|
||||
QString file = commandParams[1];
|
||||
if (QFileInfo(file).isRelative()) {
|
||||
file = _commandPath + "/" + file;
|
||||
}
|
||||
if (!QFileInfo(file).exists()) {
|
||||
qDebug() << "Cannot find scene file " + file;
|
||||
return;
|
||||
}
|
||||
|
||||
importScene(file);
|
||||
} else if (verb == "go") {
|
||||
if (commandParams.length() < 2) {
|
||||
qDebug() << "No destination specified for go command";
|
||||
return;
|
||||
}
|
||||
parsePath(commandParams[1]);
|
||||
} else {
|
||||
qDebug() << "Unknown command " << command;
|
||||
}
|
||||
}
|
||||
|
||||
void runNextCommand(quint64 now) {
|
||||
if (_commands.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_commandIndex >= _commands.size()) {
|
||||
_commands.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (now < _nextCommandTime) {
|
||||
return;
|
||||
}
|
||||
|
||||
_nextCommandTime = 0;
|
||||
QString command = _commands[_commandIndex++];
|
||||
runCommand(command);
|
||||
}
|
||||
|
||||
void update() {
|
||||
auto now = usecTimestampNow();
|
||||
static auto last = now;
|
||||
|
||||
runNextCommand(now);
|
||||
|
||||
float delta = now - last;
|
||||
// Update the camera
|
||||
_camera.update(delta / USECS_PER_SECOND);
|
||||
|
@ -936,7 +960,6 @@ private:
|
|||
QString atpUrl = QUrl::fromLocalFile(atpPath).toString();
|
||||
ResourceManager::setUrlPrefixOverride("atp:/", atpUrl + "/");
|
||||
}
|
||||
_settings.setValue(LAST_SCENE_KEY, fileName);
|
||||
_octree->clear();
|
||||
_octree->getTree()->readFromURL(fileName);
|
||||
}
|
||||
|
@ -955,6 +978,7 @@ private:
|
|||
if (fileName.isNull()) {
|
||||
return;
|
||||
}
|
||||
_settings.setValue(LAST_SCENE_KEY, fileName);
|
||||
importScene(fileName);
|
||||
}
|
||||
|
||||
|
@ -1054,6 +1078,13 @@ private:
|
|||
model::SunSkyStage _sunSkyStage;
|
||||
model::LightPointer _globalLight { std::make_shared<model::Light>() };
|
||||
bool _ready { false };
|
||||
|
||||
QStringList _commands;
|
||||
QString _commandPath;
|
||||
int _commandLoops { 0 };
|
||||
int _commandIndex { -1 };
|
||||
uint64_t _nextCommandTime { 0 };
|
||||
|
||||
//TextOverlay* _textOverlay;
|
||||
static bool _cullingEnabled;
|
||||
|
||||
|
@ -1097,6 +1128,7 @@ int main(int argc, char** argv) {
|
|||
QLoggingCategory::setFilterRules(LOG_FILTER_RULES);
|
||||
QTestWindow::setup();
|
||||
QTestWindow window;
|
||||
window.loadCommands("C:/Users/bdavis/Git/dreaming/exports/commands.txt");
|
||||
app.exec();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue