Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit 7cba265

Browse files
authored
Add CaptureWindowDebugInterface (#4401)
1 parent ac4a2e0 commit 7cba265

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

src/OrbitGl/CaptureWindow.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
#include <ostream>
1919
#include <string_view>
2020
#include <tuple>
21+
#include <type_traits>
2122

2223
#include "App.h"
24+
#include "CaptureClient/AppInterface.h"
2325
#include "CaptureViewElement.h"
2426
#include "ClientData/CallstackData.h"
2527
#include "ClientData/CaptureData.h"
@@ -38,6 +40,7 @@
3840
#include "OrbitBase/ThreadConstants.h"
3941
#include "TextRenderer.h"
4042
#include "TimeGraphLayout.h"
43+
#include "absl/strings/str_format.h"
4144

4245
using orbit_accessibility::AccessibleInterface;
4346
using orbit_accessibility::AccessibleWidgetBridge;
@@ -651,6 +654,62 @@ void CaptureWindow::RenderImGuiDebugUI() {
651654
}
652655
}
653656

657+
std::string CaptureWindow::GetCaptureInfo() const {
658+
std::string capture_info;
659+
660+
const auto append_variable = [&capture_info](std::string_view name, const auto& value) {
661+
if constexpr (std::is_floating_point_v<std::decay_t<decltype(value)>>) {
662+
absl::StrAppendFormat(&capture_info, "%s: %f\n", name, value);
663+
} else if constexpr (std::is_integral_v<std::decay_t<decltype(value)>>) {
664+
absl::StrAppendFormat(&capture_info, "%s: %d\n", name, value);
665+
} else {
666+
static_assert(!std::is_same_v<decltype(value), decltype(value)>,
667+
"Value type is not supported.");
668+
}
669+
};
670+
671+
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
672+
#define APPEND_VARIABLE(name) append_variable(#name, name)
673+
674+
APPEND_VARIABLE(viewport_.GetScreenWidth());
675+
APPEND_VARIABLE(viewport_.GetScreenHeight());
676+
APPEND_VARIABLE(viewport_.GetWorldWidth());
677+
APPEND_VARIABLE(viewport_.GetWorldHeight());
678+
APPEND_VARIABLE(mouse_move_pos_screen_[0]);
679+
APPEND_VARIABLE(mouse_move_pos_screen_[1]);
680+
if (time_graph_ != nullptr) {
681+
APPEND_VARIABLE(time_graph_->GetTrackContainer()->GetNumVisiblePrimitives());
682+
APPEND_VARIABLE(time_graph_->GetTrackManager()->GetAllTracks().size());
683+
APPEND_VARIABLE(time_graph_->GetMinTimeUs());
684+
APPEND_VARIABLE(time_graph_->GetMaxTimeUs());
685+
APPEND_VARIABLE(time_graph_->GetCaptureMin());
686+
APPEND_VARIABLE(time_graph_->GetCaptureMax());
687+
APPEND_VARIABLE(time_graph_->GetTimeWindowUs());
688+
const CaptureData* capture_data = time_graph_->GetCaptureData();
689+
if (capture_data != nullptr) {
690+
APPEND_VARIABLE(capture_data->GetCallstackData().GetCallstackEventsCount());
691+
}
692+
}
693+
694+
#undef APPEND_VARIABLE
695+
return capture_info;
696+
}
697+
698+
std::string CaptureWindow::GetPerformanceInfo() const {
699+
std::string performance_info;
700+
for (const auto& item : scoped_frame_times_) {
701+
absl::StrAppendFormat(&performance_info, "Avg time for %s: %f ms\n", item.first,
702+
item.second->GetAverageTimeMs());
703+
absl::StrAppendFormat(&performance_info, "Min time for %s: %f ms\n", item.first,
704+
item.second->GetMinTimeMs());
705+
absl::StrAppendFormat(&performance_info, "Max time for %s: %f ms\n", item.first,
706+
item.second->GetMaxTimeMs());
707+
}
708+
return performance_info;
709+
}
710+
711+
std::string CaptureWindow::GetSelectionSummary() const { return selection_stats_.GetSummary(); }
712+
654713
void CaptureWindow::RenderText(QPainter* painter, float layer) {
655714
ORBIT_SCOPE_FUNCTION;
656715
if (time_graph_ == nullptr) return;

src/OrbitGl/CaptureWindow.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "Batcher.h"
1515
#include "CaptureClient/AppInterface.h"
1616
#include "CaptureStats.h"
17+
#include "CaptureWindowDebugInterface.h"
1718
#include "GlCanvas.h"
1819
#include "PickingManager.h"
1920
#include "SimpleTimings.h"
@@ -23,7 +24,7 @@
2324

2425
class OrbitApp;
2526

26-
class CaptureWindow : public GlCanvas {
27+
class CaptureWindow : public GlCanvas, public orbit_gl::CaptureWindowDebugInterface {
2728
public:
2829
explicit CaptureWindow(OrbitApp* app,
2930
orbit_capture_client::CaptureControlInterface* capture_control);
@@ -58,6 +59,10 @@ class CaptureWindow : public GlCanvas {
5859
void CreateTimeGraph(orbit_client_data::CaptureData* capture_data);
5960
void ClearTimeGraph() { time_graph_.reset(nullptr); }
6061

62+
[[nodiscard]] std::string GetCaptureInfo() const override;
63+
[[nodiscard]] std::string GetPerformanceInfo() const override;
64+
[[nodiscard]] std::string GetSelectionSummary() const override;
65+
6166
protected:
6267
void Draw(QPainter* painter) override;
6368
void UpdateChildrenPosAndSize();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2022 The Orbit Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef ORBIT_GL_CAPTURE_WINDOW_DEBUG_INTERACE_H_
6+
#define ORBIT_GL_CAPTURE_WINDOW_DEBUG_INTERACE_H_
7+
8+
#include <string>
9+
10+
namespace orbit_gl {
11+
// Exposes some debug information from a CaptureWindow. All pieces are targeting developers of
12+
// Orbit and are not meant for the user of the tool.
13+
class CaptureWindowDebugInterface {
14+
public:
15+
[[nodiscard]] virtual std::string GetCaptureInfo() const = 0;
16+
[[nodiscard]] virtual std::string GetPerformanceInfo() const = 0;
17+
[[nodiscard]] virtual std::string GetSelectionSummary() const = 0;
18+
19+
virtual ~CaptureWindowDebugInterface() = default;
20+
};
21+
} // namespace orbit_gl
22+
23+
#endif // ORBIT_GL_CAPTURE_WINDOW_DEBUG_INTERFACE_H_

0 commit comments

Comments
 (0)