-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add export_replay for standalone replay with gapir.
- Loading branch information
Showing
20 changed files
with
506 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (C) 2017 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"path/filepath" | ||
|
||
"github.com/google/gapid/core/app" | ||
"github.com/google/gapid/core/log" | ||
) | ||
|
||
type exportReplayVerb struct{ ExportReplayFlags } | ||
|
||
func init() { | ||
verb := &exportReplayVerb{} | ||
app.AddVerb(&app.Verb{ | ||
Name: "export_replay", | ||
ShortHelp: "Export replay vm instruction and assets.", | ||
Action: verb, | ||
}) | ||
} | ||
|
||
func (verb *exportReplayVerb) Run(ctx context.Context, flags flag.FlagSet) error { | ||
if flags.NArg() != 1 { | ||
app.Usage(ctx, "Exactly one gfx trace file expected, got %d", flags.NArg()) | ||
return nil | ||
} | ||
|
||
capture, err := filepath.Abs(flags.Arg(0)) | ||
if err != nil { | ||
log.Errf(ctx, err, "Could not find capture file: %v", flags.Arg(0)) | ||
} | ||
|
||
client, err := getGapis(ctx, verb.Gapis, verb.Gapir) | ||
if err != nil { | ||
return log.Err(ctx, err, "Failed to connect to the GAPIS server") | ||
} | ||
defer client.Close() | ||
|
||
capturePath, err := client.LoadCapture(ctx, capture) | ||
if err != nil { | ||
return log.Err(ctx, err, "Failed to load the capture file") | ||
} | ||
|
||
device, err := getDevice(ctx, client, capturePath, verb.Gapir) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := client.ExportReplay(ctx, capturePath, device, verb.Out); err != nil { | ||
return log.Err(ctx, err, "Failed to export replay") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (C) 2018 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["archive.go"], | ||
cdeps = ["//core/cc"], | ||
cgo = True, | ||
clinkopts = [], # keep | ||
importpath = "github.com/google/gapid/core/archive", | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (C) 2018 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package archive | ||
|
||
/* | ||
#include <stdlib.h> | ||
#include "core/cc/archive.h" | ||
*/ | ||
import "C" | ||
import "unsafe" | ||
|
||
// Archive contains assets. | ||
type Archive = *C.archive | ||
|
||
// New creates an archive. | ||
func New(name string) Archive { | ||
cstr := C.CString(name) | ||
defer C.free(unsafe.Pointer(cstr)) | ||
return C.archive_create(cstr) | ||
} | ||
|
||
// Dispose flush and close the underlying archive. | ||
func (a Archive) Dispose() { | ||
C.archive_destroy(a) | ||
} | ||
|
||
// Write writes key-value pair to the archive. | ||
func (a Archive) Write(key string, value []byte) bool { | ||
cstr := C.CString(key) | ||
defer C.free(unsafe.Pointer(cstr)) | ||
csize := C.size_t(len(value)) | ||
return C.archive_write(a, cstr, unsafe.Pointer(&value[0]), csize) != 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (C) 2018 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "replay_archive.h" | ||
|
||
#include <grpc++/grpc++.h> | ||
#include <fstream> | ||
#include <memory> | ||
|
||
#include "gapir/replay_service/service.grpc.pb.h" | ||
|
||
namespace gapir { | ||
|
||
std::unique_ptr<ReplayArchive::Payload> ReplayArchive::getPayload() { | ||
std::fstream input(mFileprefix, std::ios::in | std::ios::binary); | ||
std::unique_ptr<replay_service::Payload> payload(new replay_service::Payload); | ||
payload->ParseFromIstream(&input); | ||
return std::unique_ptr<Payload>(new Payload(std::move(payload))); | ||
} | ||
|
||
std::unique_ptr<ReplayArchive::Resources> ReplayArchive::getResources( | ||
std::unique_ptr<ResourceRequest> req) { | ||
return nullptr; | ||
} | ||
bool ReplayArchive::sendReplayFinished() { return true; } | ||
bool ReplayArchive::sendCrashDump(const std::string& filepath, | ||
const void* crash_data, uint32_t crash_size) { | ||
return true; | ||
} | ||
bool ReplayArchive::sendPostData(std::unique_ptr<Posts> posts) { return true; } | ||
bool ReplayArchive::sendNotification(uint64_t id, uint32_t severity, | ||
uint32_t api_index, uint64_t label, | ||
const std::string& msg, const void* data, | ||
uint32_t data_size) { | ||
return true; | ||
} | ||
} // namespace gapir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (C) 2018 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef GAPIR_REPLAY_ARCHIVE_H | ||
#define GAPIR_REPLAY_ARCHIVE_H | ||
|
||
#include "core/cc/archive.h" | ||
#include "replay_connection.h" | ||
namespace gapir { | ||
|
||
// ReplayArchive implements ReplayConnection for exported replays. | ||
class ReplayArchive : public ReplayConnection { | ||
public: | ||
ReplayArchive(const std::string& fileprefix) | ||
: ReplayConnection(nullptr), mFileprefix(fileprefix) {} | ||
// Read payload from disk. | ||
virtual std::unique_ptr<Payload> getPayload() override; | ||
|
||
// We are reading from disk, so the following methods are not implemented. | ||
virtual std::unique_ptr<Resources> getResources( | ||
std::unique_ptr<ResourceRequest> req) override; | ||
virtual bool sendReplayFinished() override; | ||
virtual bool sendCrashDump(const std::string& filepath, | ||
const void* crash_data, | ||
uint32_t crash_size) override; | ||
virtual bool sendPostData(std::unique_ptr<Posts> posts) override; | ||
virtual bool sendNotification(uint64_t id, uint32_t severity, | ||
uint32_t api_index, uint64_t label, | ||
const std::string& msg, const void* data, | ||
uint32_t data_size) override; | ||
|
||
private: | ||
std::string mFileprefix; | ||
}; | ||
|
||
} // namespace gapir | ||
|
||
#endif // GAPIR_REPLAY_ARCHIVE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.