Skip to content

Commit

Permalink
Retrieves gfxr capture file off of device
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantComm committed Dec 4, 2024
1 parent 69f880b commit 62ed845
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 19 deletions.
10 changes: 3 additions & 7 deletions capture_service/android_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,10 @@ absl::Status AndroidApplication::gfxrSetup()
RETURN_IF_ERROR(m_dev.Adb().Run(
absl::StrFormat("shell settings put global gpu_debug_layer_app %s", m_package)));

std::string capture_file_location = "/sdcard/Download/gfxr_captures/" +
m_gfxr_capture_file_directory + "/" + m_package + ".gfxr";
std::string capture_file_location = kGfxrCaptureDirectory + m_gfxr_capture_file_directory +
"/" + m_package + ".gfxr";

std::string gfxr_captures_directory = "/sdcard/Download/gfxr_captures";
RETURN_IF_ERROR(createGfxrDirectory(gfxr_captures_directory));

std::string gfxr_capture_directory = "/sdcard/Download/gfxr_captures/" +
m_gfxr_capture_file_directory;
std::string gfxr_capture_directory = kGfxrCaptureDirectory + m_gfxr_capture_file_directory;
RETURN_IF_ERROR(createGfxrDirectory(gfxr_capture_directory));

RETURN_IF_ERROR(
Expand Down
1 change: 1 addition & 0 deletions capture_service/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ inline constexpr char kVkLayerName[] = "VK_LAYER_Dive";
inline constexpr char kXrLayerName[] = "XR_APILAYER_dive";
inline constexpr char kTargetPath[] = "/data/local/tmp";
inline constexpr char kGfxrTargetPath[] = "/data/data/";
inline constexpr char kGfxrCaptureDirectory[] = "/sdcard/Download/";
inline constexpr char kManifestFileName[] = "XrApiLayer_dive.json";
inline constexpr char kManifestFilePath[] = "/system/etc/openxr/1/api_layers/implicit.d/";
inline constexpr char kVulkanGlobalPath[] = "/data/local/debug/vulkan";
Expand Down
13 changes: 9 additions & 4 deletions capture_service/device_mgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,16 @@ absl::Status DeviceManager::Cleanup(const std::string &serial, const std::string
return absl::OkStatus();
}

absl::Status AndroidDevice::RetrieveTraceFile(const std::string &trace_file_path,
const std::string &save_path)
absl::Status AndroidDevice::RetrieveTrace(const std::string &trace_path,
const std::string &save_path,
const bool isGfxrCapture)
{
RETURN_IF_ERROR(Adb().Run(absl::StrFormat("pull %s %s", trace_file_path, save_path)));
return Adb().Run(absl::StrFormat("shell rm %s", trace_file_path));
RETURN_IF_ERROR(Adb().Run(absl::StrFormat("pull %s %s", trace_path, save_path)));
if (isGfxrCapture)
{
return Adb().Run(absl::StrFormat("shell rm -rf %s", trace_path));
}
return Adb().Run(absl::StrFormat("shell rm %s", trace_path));
}

void AndroidDevice::enableGfxr(bool enableGfxr)
Expand Down
5 changes: 3 additions & 2 deletions capture_service/device_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ class AndroidDevice
AdbSession &Adb() { return m_adb; }

AndroidApplication *GetCurrentApplication() { return app.get(); }
absl::Status RetrieveTraceFile(const std::string &trace_file_path,
const std::string &save_path);
absl::Status RetrieveTrace(const std::string &trace_file_path,
const std::string &save_path,
const bool isGfxrCapture);

private:
const std::string m_serial;
Expand Down
33 changes: 29 additions & 4 deletions capture_service/dive_client_cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ limitations under the License.
#include "absl/flags/usage.h"
#include "android_application.h"
#include "client.h"
#include "constants.h"
#include "device_mgr.h"

using namespace std::chrono_literals;
Expand Down Expand Up @@ -309,8 +310,9 @@ bool trigger_capture(Dive::DeviceManager& mgr)
}
}
target_download_path /= p.filename();
auto ret = mgr.GetDevice()->RetrieveTraceFile(*trace_file_path,
target_download_path.generic_string());
auto ret = mgr.GetDevice()->RetrieveTrace(*trace_file_path,
target_download_path.generic_string(),
false);
if (ret.ok())
std::cout << "Capture saved at " << target_download_path << std::endl;
else
Expand All @@ -319,6 +321,30 @@ bool trigger_capture(Dive::DeviceManager& mgr)
return ret.ok();
}

bool retrieve_gfxr_capture(Dive::DeviceManager& mgr, const std::string& gfxr_capture_directory)
{
std::string target_str = absl::GetFlag(FLAGS_target);
std::string download_path = absl::GetFlag(FLAGS_download_path);
std::filesystem::path target_download_path(download_path);
if (!std::filesystem::exists(target_download_path))
{
std::error_code ec;
if (!std::filesystem::create_directories(target_download_path, ec))
{
std::cout << "error creating directory: " << ec << std::endl;
}
}
std::string capture_directory = Dive::kGfxrCaptureDirectory + gfxr_capture_directory;
auto ret = mgr.GetDevice()->RetrieveTrace(capture_directory,
target_download_path.generic_string(),
true);
if (ret.ok())
std::cout << "GFXR capture directory saved at " << target_download_path << std::endl;
else
std::cout << "Failed to retrieve capture directory" << std::endl;
return ret.ok();
}

bool run_and_capture(Dive::DeviceManager& mgr,
const std::string& app_type,
const std::string& package,
Expand Down Expand Up @@ -346,8 +372,7 @@ bool run_and_capture(Dive::DeviceManager& mgr,

if (isGfxrCapture)
{
std::cout << "GFXR Capture file saved in the directory "
<< "/sdcard/Download/gfxr_captures/" << gfxr_capture_directory << std::endl;
retrieve_gfxr_capture(mgr, gfxr_capture_directory);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions ui/trace_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ void TraceWorker::run()

std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
qDebug() << "Begin to download the trace file to " << target.generic_string().c_str();
auto r = device->RetrieveTraceFile(*trace_file_path, target.generic_string());
auto r = device->RetrieveTrace(*trace_file_path, target.generic_string(), false);
progress_bar_worker->terminate();
m_progress_bar->setValue(100);
if (r.ok())
Expand All @@ -581,7 +581,7 @@ void TraceWorker::run()
std::string on_device_path = *trace_file_path;
on_device_path += ".perfetto";
std::string download_path = target.generic_string() + ".perfetto";
r = device->RetrieveTraceFile(on_device_path, download_path);
r = device->RetrieveTrace(on_device_path, download_path, false);
if (r.ok())
{
qDebug() << "Capture saved at " << download_path.c_str();
Expand Down

0 comments on commit 62ed845

Please sign in to comment.