Browse Source

sceneconverter: add a --profile option.

pull/441/head
Vladimír Vondruš 6 years ago
parent
commit
08a51215b6
  1. 49
      src/Magnum/MeshTools/sceneconverter.cpp

49
src/Magnum/MeshTools/sceneconverter.cpp

@ -24,6 +24,7 @@
*/ */
#include <algorithm> #include <algorithm>
#include <chrono>
#include <Corrade/Containers/Optional.h> #include <Corrade/Containers/Optional.h>
#include <Corrade/Utility/Arguments.h> #include <Corrade/Utility/Arguments.h>
#include <Corrade/Utility/DebugStl.h> #include <Corrade/Utility/DebugStl.h>
@ -63,8 +64,8 @@ information.
@code{.sh} @code{.sh}
magnum-sceneconverter [-h|--help] [--importer IMPORTER] [--plugin-dir DIR] magnum-sceneconverter [-h|--help] [--importer IMPORTER] [--plugin-dir DIR]
[-i|--importer-options key=val,key2=val2,] [--info] [-v|--verbose] [--] [-i|--importer-options key=val,key2=val2,] [--info] [-v|--verbose]
input [--profile] [--] input
@endcode @endcode
Arguments: Arguments:
@ -78,6 +79,7 @@ Arguments:
pass to the importer pass to the importer
- `--info` --- print info about the input file and exit - `--info` --- print info about the input file and exit
- `-v`, `--verbose` --- verbose output from importer plugins - `-v`, `--verbose` --- verbose output from importer plugins
- `--profile` --- measure import time
If `--info` is given, the utility will print information about all meshes If `--info` is given, the utility will print information about all meshes
and images present in the file. **This option is currently mandatory.** and images present in the file. **This option is currently mandatory.**
@ -92,6 +94,22 @@ character is omitted, it's equivalent to saying `key=true`.
using namespace Magnum; using namespace Magnum;
namespace {
struct Duration {
explicit Duration(std::chrono::high_resolution_clock::duration& output): _output(output), _t{std::chrono::high_resolution_clock::now()} {}
~Duration() {
_output += std::chrono::high_resolution_clock::now() - _t;
}
private:
std::chrono::high_resolution_clock::duration& _output;
std::chrono::high_resolution_clock::time_point _t;
};
}
int main(int argc, char** argv) { int main(int argc, char** argv) {
Utility::Arguments args; Utility::Arguments args;
args.addArgument("input").setHelp("input", "input file") args.addArgument("input").setHelp("input", "input file")
@ -100,6 +118,7 @@ int main(int argc, char** argv) {
.addOption('i', "importer-options").setHelp("importer-options", "configuration options to pass to the importer", "key=val,key2=val2,…") .addOption('i', "importer-options").setHelp("importer-options", "configuration options to pass to the importer", "key=val,key2=val2,…")
.addBooleanOption("info").setHelp("info", "print info about the input file and exit") .addBooleanOption("info").setHelp("info", "print info about the input file and exit")
.addBooleanOption('v', "verbose").setHelp("verbose", "verbose output from importer plugins") .addBooleanOption('v', "verbose").setHelp("verbose", "verbose output from importer plugins")
.addBooleanOption("profile").setHelp("profile", "measure import time")
/** @todo add the parse error callback from imageconverter once there's /** @todo add the parse error callback from imageconverter once there's
an output argument, also remove the "mandatory" from all docs */ an output argument, also remove the "mandatory" from all docs */
.setGlobalHelp(R"(Converts scenes of different formats. .setGlobalHelp(R"(Converts scenes of different formats.
@ -126,14 +145,19 @@ is omitted, it's equivalent to saying key=true.)")
if(args.isSet("verbose")) importer->setFlags(Trade::ImporterFlag::Verbose); if(args.isSet("verbose")) importer->setFlags(Trade::ImporterFlag::Verbose);
Trade::Implementation::setOptions(*importer, args.value("importer-options")); Trade::Implementation::setOptions(*importer, args.value("importer-options"));
/* Print file info, if requested */ std::chrono::high_resolution_clock::duration importTime;
if(args.isSet("info")) {
/* Open the file, but don't fail when an image can't be opened */ /* Open the file */
{
Duration d{importTime};
if(!importer->openFile(args.value("input"))) { if(!importer->openFile(args.value("input"))) {
Error() << "Cannot open file" << args.value("input"); Error() << "Cannot open file" << args.value("input");
return 3; return 3;
} }
}
/* Print file info, if requested */
if(args.isSet("info")) {
if(!importer->meshCount() && !importer->image1DCount() && !importer->image2DCount() && !importer->image2DCount()) { if(!importer->meshCount() && !importer->image1DCount() && !importer->image2DCount() && !importer->image2DCount()) {
Debug{} << "No meshes or images found."; Debug{} << "No meshes or images found.";
return 0; return 0;
@ -162,10 +186,13 @@ is omitted, it's equivalent to saying key=true.)")
Containers::Array<MeshInfo> meshInfos; Containers::Array<MeshInfo> meshInfos;
for(UnsignedInt i = 0; i != importer->meshCount(); ++i) { for(UnsignedInt i = 0; i != importer->meshCount(); ++i) {
for(UnsignedInt j = 0; j != importer->meshLevelCount(i); ++j) { for(UnsignedInt j = 0; j != importer->meshLevelCount(i); ++j) {
Containers::Optional<Trade::MeshData> mesh = importer->mesh(i, j); Containers::Optional<Trade::MeshData> mesh;
if(!mesh) { {
error = true; Duration d{importTime};
continue; if(!(mesh = importer->mesh(i, j))) {
error = true;
continue;
}
} }
MeshInfo info{}; MeshInfo info{};
@ -248,6 +275,10 @@ is omitted, it's equivalent to saying key=true.)")
else d << Math::Vector<1, Int>(info.size.x()); else d << Math::Vector<1, Int>(info.size.x());
} }
if(args.isSet("profile")) {
Debug{} << "Import took" << UnsignedInt(std::chrono::duration_cast<std::chrono::milliseconds>(importTime).count())/1.0e3f << "seconds";
}
return error ? 1 : 0; return error ? 1 : 0;
} }

Loading…
Cancel
Save