Skip to content

Commit

Permalink
feat: Add network profiler view in debug tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Nov 27, 2024
1 parent 99e49ad commit 5451d5c
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ qt6_wrap_ui(
src/mainwindow.ui
src/widget/about/aboutfriendform.ui
src/widget/form/debug/debuglog.ui
src/widget/form/debug/debugnetprof.ui
src/widget/form/debug/debugobjecttree.ui
src/widget/form/loadhistorydialog.ui
src/widget/form/profileform.ui
Expand Down Expand Up @@ -426,6 +427,8 @@ set(${PROJECT_NAME}_SOURCES
src/widget/form/chatform.h
src/widget/form/debug/debuglog.cpp
src/widget/form/debug/debuglog.h
src/widget/form/debug/debugnetprof.cpp
src/widget/form/debug/debugnetprof.h
src/widget/form/debug/debugobjecttree.cpp
src/widget/form/debug/debugobjecttree.h
src/widget/form/debugwidget.cpp
Expand Down
1 change: 1 addition & 0 deletions src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ qt_moc(
"widget/form/conferenceinviteform.h",
"widget/form/conferenceinvitewidget.h",
"widget/form/debug/debuglog.h",
"widget/form/debug/debugnetprof.h",
"widget/form/debug/debugobjecttree.h",
"widget/form/debugwidget.h",
"widget/form/filesform.h",
Expand Down
6 changes: 0 additions & 6 deletions src/widget/form/debug/debuglog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@
#include "src/model/debug/debuglogmodel.h"
#include "src/persistence/paths.h"
#include "src/widget/style.h"
#include "src/widget/tool/recursivesignalblocker.h"
#include "src/widget/translator.h"

#include <tox/tox.h>

#include <QDebug>
#include <QDesktopServices>
#include <QFile>
#include <QMetaEnum>
#include <QPushButton>
#include <QTimer>

#include <memory>
Expand Down
44 changes: 44 additions & 0 deletions src/widget/form/debug/debugnetprof.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2014-2019 by The qTox Project Contributors
* Copyright © 2024 The TokTok team.
*/

#include "debugnetprof.h"
#include "ui_debugnetprof.h"

#include "src/model/debug/debuglogmodel.h"
#include "src/persistence/paths.h"
#include "src/widget/style.h"
#include "src/widget/translator.h"

#include <tox/tox.h>

#include <QTimer>

#include <memory>

DebugNetProfForm::DebugNetProfForm(Style& style, QWidget* parent)
: GenericForm{QPixmap(":/img/settings/general.png"), style, parent}
, ui_{std::make_unique<Ui::DebugNetProf>()}
, reloadTimer_{new QTimer(this)}

Check warning on line 23 in src/widget/form/debug/debugnetprof.cpp

View check run for this annotation

Codecov / codecov/patch

src/widget/form/debug/debugnetprof.cpp#L20-L23

Added lines #L20 - L23 were not covered by tests
{
ui_->setupUi(this);

Check warning on line 25 in src/widget/form/debug/debugnetprof.cpp

View check run for this annotation

Codecov / codecov/patch

src/widget/form/debug/debugnetprof.cpp#L25

Added line #L25 was not covered by tests

// Reload logs every 5 seconds
reloadTimer_->start(5000);

Check warning on line 28 in src/widget/form/debug/debugnetprof.cpp

View check run for this annotation

Codecov / codecov/patch

src/widget/form/debug/debugnetprof.cpp#L28

Added line #L28 was not covered by tests

Translator::registerHandler(std::bind(&DebugNetProfForm::retranslateUi, this), this);

Check warning on line 30 in src/widget/form/debug/debugnetprof.cpp

View check run for this annotation

Codecov / codecov/patch

src/widget/form/debug/debugnetprof.cpp#L30

Added line #L30 was not covered by tests
}

DebugNetProfForm::~DebugNetProfForm()

Check warning on line 33 in src/widget/form/debug/debugnetprof.cpp

View check run for this annotation

Codecov / codecov/patch

src/widget/form/debug/debugnetprof.cpp#L33

Added line #L33 was not covered by tests
{
Translator::unregister(this);

Check warning on line 35 in src/widget/form/debug/debugnetprof.cpp

View check run for this annotation

Codecov / codecov/patch

src/widget/form/debug/debugnetprof.cpp#L35

Added line #L35 was not covered by tests
}

/**
* @brief Retranslate all elements in the form.
*/
void DebugNetProfForm::retranslateUi()

Check warning on line 41 in src/widget/form/debug/debugnetprof.cpp

View check run for this annotation

Codecov / codecov/patch

src/widget/form/debug/debugnetprof.cpp#L41

Added line #L41 was not covered by tests
{
ui_->retranslateUi(this);

Check warning on line 43 in src/widget/form/debug/debugnetprof.cpp

View check run for this annotation

Codecov / codecov/patch

src/widget/form/debug/debugnetprof.cpp#L43

Added line #L43 was not covered by tests
}
36 changes: 36 additions & 0 deletions src/widget/form/debug/debugnetprof.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2024 The TokTok team.
*/

#pragma once

#include "src/widget/form/settings/genericsettings.h"

#include <memory>

class Paths;
class QTimer;
class Style;

namespace Ui {
class DebugNetProf;
}

class DebugNetProfForm : public GenericForm
{
Q_OBJECT

Check warning on line 21 in src/widget/form/debug/debugnetprof.h

View check run for this annotation

Codecov / codecov/patch

src/widget/form/debug/debugnetprof.h#L21

Added line #L21 was not covered by tests
public:
DebugNetProfForm(Style& style, QWidget* parent);
~DebugNetProfForm();
QString getFormName() final

Check warning on line 25 in src/widget/form/debug/debugnetprof.h

View check run for this annotation

Codecov / codecov/patch

src/widget/form/debug/debugnetprof.h#L25

Added line #L25 was not covered by tests
{
return tr("Network Profiler");

Check warning on line 27 in src/widget/form/debug/debugnetprof.h

View check run for this annotation

Codecov / codecov/patch

src/widget/form/debug/debugnetprof.h#L27

Added line #L27 was not covered by tests
}

private:
void retranslateUi();

private:
std::unique_ptr<Ui::DebugNetProf> ui_;
QTimer* reloadTimer_;
};
60 changes: 60 additions & 0 deletions src/widget/form/debug/debugnetprof.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DebugNetProf</class>
<widget class="QWidget" name="DebugNetProf">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>530</width>
<height>553</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string notr="true">Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0">
<item>
<widget class="QGroupBox" name="netProfGroup">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Network Profile</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="cbAutoReload">
<property name="text">
<string>Auto-reload</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTableView" name="netProf"/>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
4 changes: 2 additions & 2 deletions src/widget/form/debugwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "src/widget/contentlayout.h"
#include "src/widget/form/debug/debuglog.h"
#include "src/widget/form/debug/debugnetprof.h"
#include "src/widget/form/debug/debugobjecttree.h"
#include "src/widget/translator.h"
#include "src/widget/widget.h"
Expand All @@ -15,8 +16,6 @@
#include <QVBoxLayout>
#include <QWindow>

#include <memory>

DebugWidget::DebugWidget(Paths& paths, Style& style, Widget* parent)
: QWidget(parent, Qt::Window)
{
Expand All @@ -31,6 +30,7 @@ DebugWidget::DebugWidget(Paths& paths, Style& style, Widget* parent)
dbgForms = {
new DebugLogForm(paths, style, this),
new DebugObjectTree(style, this),
new DebugNetProfForm(style, this),

Check warning on line 33 in src/widget/form/debugwidget.cpp

View check run for this annotation

Codecov / codecov/patch

src/widget/form/debugwidget.cpp#L33

Added line #L33 was not covered by tests
};

for (auto* dbgForm : dbgForms)
Expand Down
2 changes: 1 addition & 1 deletion src/widget/form/debugwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ private slots:
private:
QVBoxLayout* bodyLayout;
QTabWidget* debugWidgets;
std::array<GenericForm*, 2> dbgForms;
std::array<GenericForm*, 3> dbgForms;
int currentIndex;
};

0 comments on commit 5451d5c

Please sign in to comment.