summaryrefslogtreecommitdiff
path: root/indra/newview/llviewermenufile.cpp
diff options
context:
space:
mode:
authorAndrey Kleshchev <andreykproductengine@lindenlab.com>2021-09-10 23:59:41 +0300
committerAndrey Kleshchev <andreykproductengine@lindenlab.com>2021-09-11 17:08:10 +0300
commit1b529bfb73d4640323983dbb7851f0434cd7cac1 (patch)
tree0a93bfcc78a79eb0a9987d092b3590f8f571aed0 /indra/newview/llviewermenufile.cpp
parentb7dc69f147a2ff4a61667fce2e302f2b1602f3db (diff)
SL-15964 Simple test for compression library
Diffstat (limited to 'indra/newview/llviewermenufile.cpp')
-rw-r--r--indra/newview/llviewermenufile.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/indra/newview/llviewermenufile.cpp b/indra/newview/llviewermenufile.cpp
index 15181dcd9f..43f99fc13a 100644
--- a/indra/newview/llviewermenufile.cpp
+++ b/indra/newview/llviewermenufile.cpp
@@ -775,6 +775,94 @@ void handle_compress_image(void*)
}
}
+// No convinient check in LLFile, and correct way would be something
+// like GetFileSizeEx, which is too OS specific for current purpose
+// so doing dirty, but OS independent fopen and fseek
+size_t get_file_size(std::string &filename)
+{
+ LLFILE* file = LLFile::fopen(filename, "rb"); /*Flawfinder: ignore*/
+ if (!file)
+ {
+ LL_WARNS() << "Error opening " << filename << LL_ENDL;
+ return 0;
+ }
+
+ // read in the whole file
+ fseek(file, 0L, SEEK_END);
+ size_t file_length = (size_t)ftell(file);
+ fclose(file);
+ return file_length;
+}
+
+void handle_compress_file_test(void*)
+{
+ LLFilePicker& picker = LLFilePicker::instance();
+ if (picker.getOpenFile())
+ {
+ std::string infile = picker.getFirstFile();
+ if (!infile.empty())
+ {
+ std::string packfile = infile + ".pack_test";
+ std::string unpackfile = infile + ".unpack_test";
+
+ S64Bytes initial_size = S64Bytes(get_file_size(infile));
+
+ BOOL success;
+
+ F64 total_seconds = LLTimer::getTotalSeconds();
+ success = gzip_file(infile, packfile);
+ F64 result_pack_seconds = LLTimer::getTotalSeconds() - total_seconds;
+
+ if (success)
+ {
+ S64Bytes packed_size = S64Bytes(get_file_size(packfile));
+
+ LL_INFOS() << "Packing complete, time: " << result_pack_seconds << " size: " << packed_size << LL_ENDL;
+ total_seconds = LLTimer::getTotalSeconds();
+ success = gunzip_file(packfile, unpackfile);
+ F64 result_unpack_seconds = LLTimer::getTotalSeconds() - total_seconds;
+
+ if (success)
+ {
+ S64Bytes unpacked_size = S64Bytes(get_file_size(unpackfile));
+
+ LL_INFOS() << "Unpacking complete, time: " << result_unpack_seconds << " size: " << unpacked_size << LL_ENDL;
+
+ LLSD args;
+ args["FILE"] = infile;
+ args["PACK_TIME"] = result_pack_seconds;
+ args["UNPACK_TIME"] = result_unpack_seconds;
+ args["SIZE"] = LLSD::Integer(initial_size.valueInUnits<LLUnits::Kilobytes>());
+ args["PSIZE"] = LLSD::Integer(packed_size.valueInUnits<LLUnits::Kilobytes>());
+ args["USIZE"] = LLSD::Integer(unpacked_size.valueInUnits<LLUnits::Kilobytes>());
+ LLNotificationsUtil::add("CompressionTestResults", args);
+
+ LLFile::remove(packfile);
+ LLFile::remove(unpackfile);
+ }
+ else
+ {
+ LL_INFOS() << "Failed to uncompress file: " << packfile << LL_ENDL;
+ LLFile::remove(packfile);
+ }
+
+ }
+ else
+ {
+ LL_INFOS() << "Failed to compres file: " << infile << LL_ENDL;
+ }
+ }
+ else
+ {
+ LL_INFOS() << "Failed to open file" << LL_ENDL;
+ }
+ }
+ else
+ {
+ LL_INFOS() << "Failed to open file" << LL_ENDL;
+ }
+}
+
LLUUID upload_new_resource(
const std::string& src_filename,