Add heap usage of SkSL::Compiler to nanobench output
This will let us track a new metric that measures the heap usage of constructing a default compiler object. I anticipate adding similar stats about the heap usage from compiling simple vs. complex SkSL. Change-Id: Idb814c0b5d210d00a06ce5dc7147437aabcba1bb Reviewed-on: https://skia-review.googlesource.com/c/skia/+/301359 Reviewed-by: Mike Klein <mtklein@google.com> Reviewed-by: Joe Gregorio <jcgregorio@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
6669b01267
commit
68870aa5d1
@ -5,7 +5,10 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
#include "bench/Benchmark.h"
|
||||
#include "bench/ResultsWriter.h"
|
||||
#include "bench/SkSLBench.h"
|
||||
#include "src/sksl/SkSLCompiler.h"
|
||||
#include "tools/ProcStats.h"
|
||||
|
||||
class SkSLBench : public Benchmark {
|
||||
public:
|
||||
@ -115,3 +118,24 @@ DEF_BENCH(return new SkSLBench("huge", R"(
|
||||
}
|
||||
}
|
||||
)"); )
|
||||
|
||||
// These benchmarks aren't timed, they produce memory usage statistics. They run standalone, and
|
||||
// directly add their results to the nanobench log.
|
||||
void RunSkSLMemoryBenchmarks(NanoJSONResultsWriter* log) {
|
||||
auto bench = [log](const char* name, int64_t bytes) {
|
||||
log->beginObject(name); // test
|
||||
log->beginObject("meta"); // config
|
||||
log->appendS64("bytes", bytes); // sub_result
|
||||
log->endObject(); // config
|
||||
log->endObject(); // test
|
||||
};
|
||||
|
||||
{
|
||||
int64_t before = sk_tools::getCurrResidentSetSizeBytes();
|
||||
SkSL::Compiler compiler;
|
||||
int64_t after = sk_tools::getCurrResidentSetSizeBytes();
|
||||
if (before > 0 && after > 0) {
|
||||
bench("sksl_compiler_baseline", after - before);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
16
bench/SkSLBench.h
Normal file
16
bench/SkSLBench.h
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2020 Google LLC
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
#ifndef SkSLBench_DEFINED
|
||||
#define SkSLBench_DEFINED
|
||||
|
||||
#include "include/core/SkTypes.h"
|
||||
|
||||
class NanoJSONResultsWriter;
|
||||
|
||||
void RunSkSLMemoryBenchmarks(NanoJSONResultsWriter*);
|
||||
|
||||
#endif
|
@ -19,6 +19,7 @@
|
||||
#include "bench/SKPAnimationBench.h"
|
||||
#include "bench/SKPBench.h"
|
||||
#include "bench/SkGlyphCacheBench.h"
|
||||
#include "bench/SkSLBench.h"
|
||||
#include "include/codec/SkAndroidCodec.h"
|
||||
#include "include/codec/SkCodec.h"
|
||||
#include "include/core/SkCanvas.h"
|
||||
@ -1465,6 +1466,8 @@ int main(int argc, char** argv) {
|
||||
log.endObject(); // config
|
||||
log.endBench();
|
||||
|
||||
RunSkSLMemoryBenchmarks(&log);
|
||||
|
||||
log.endObject(); // results
|
||||
log.endObject(); // root
|
||||
log.flush();
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include <zircon/syscalls/object.h>
|
||||
#include <zircon/types.h>
|
||||
|
||||
int sk_tools::getMaxResidentSetSizeMB() {
|
||||
int64_t sk_tools::getMaxResidentSetSizeBytes() {
|
||||
zx_info_task_stats_t task_stats;
|
||||
zx_handle_t process = zx_process_self();
|
||||
zx_status_t status = zx_object_get_info(
|
||||
@ -22,46 +22,46 @@
|
||||
if (status != ZX_OK) {
|
||||
return -1;
|
||||
}
|
||||
return (task_stats.mem_private_bytes + task_stats.mem_shared_bytes) / (1 << 20);
|
||||
return (task_stats.mem_private_bytes + task_stats.mem_shared_bytes);
|
||||
}
|
||||
#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) || defined(SK_BUILD_FOR_ANDROID)
|
||||
#include <sys/resource.h>
|
||||
int sk_tools::getMaxResidentSetSizeMB() {
|
||||
int64_t sk_tools::getMaxResidentSetSizeBytes() {
|
||||
struct rusage ru;
|
||||
getrusage(RUSAGE_SELF, &ru);
|
||||
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
|
||||
return static_cast<int>(ru.ru_maxrss / 1024 / 1024); // Darwin reports bytes.
|
||||
return ru.ru_maxrss; // Darwin reports bytes.
|
||||
#else
|
||||
return static_cast<int>(ru.ru_maxrss / 1024); // Linux reports kilobytes.
|
||||
return ru.ru_maxrss * 1024; // Linux reports kilobytes.
|
||||
#endif
|
||||
}
|
||||
#elif defined(SK_BUILD_FOR_WIN)
|
||||
#include <windows.h>
|
||||
#include <psapi.h>
|
||||
int sk_tools::getMaxResidentSetSizeMB() {
|
||||
int64_t sk_tools::getMaxResidentSetSizeBytes() {
|
||||
PROCESS_MEMORY_COUNTERS info;
|
||||
GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
|
||||
return static_cast<int>(info.PeakWorkingSetSize / 1024 / 1024); // Windows reports bytes.
|
||||
return info.PeakWorkingSetSize;
|
||||
}
|
||||
#else
|
||||
int sk_tools::getMaxResidentSetSizeMB() { return -1; }
|
||||
int64_t sk_tools::getMaxResidentSetSizeBytes() { return -1; }
|
||||
#endif
|
||||
|
||||
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
|
||||
#include <mach/mach.h>
|
||||
int sk_tools::getCurrResidentSetSizeMB() {
|
||||
int64_t sk_tools::getCurrResidentSetSizeBytes() {
|
||||
mach_task_basic_info info;
|
||||
mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
|
||||
if (KERN_SUCCESS !=
|
||||
task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&info, &count)) {
|
||||
return -1;
|
||||
}
|
||||
return info.resident_size / 1024 / 1024; // Darwin reports bytes.
|
||||
return info.resident_size;
|
||||
}
|
||||
#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID) // N.B. /proc is Linux-only.
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
int sk_tools::getCurrResidentSetSizeMB() {
|
||||
int64_t sk_tools::getCurrResidentSetSizeBytes() {
|
||||
const long pageSize = sysconf(_SC_PAGESIZE);
|
||||
long long rssPages = 0;
|
||||
if (FILE* statm = fopen("/proc/self/statm", "r")) {
|
||||
@ -72,15 +72,24 @@
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return rssPages * pageSize / 1024 / 1024;
|
||||
return rssPages * pageSize;
|
||||
}
|
||||
|
||||
#elif defined(SK_BUILD_FOR_WIN)
|
||||
int sk_tools::getCurrResidentSetSizeMB() {
|
||||
int64_t sk_tools::getCurrResidentSetSizeBytes() {
|
||||
PROCESS_MEMORY_COUNTERS info;
|
||||
GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
|
||||
return static_cast<int>(info.WorkingSetSize / 1024 / 1024); // Windows reports bytes.
|
||||
return info.WorkingSetSize;
|
||||
}
|
||||
#else
|
||||
int sk_tools::getCurrResidentSetSizeMB() { return -1; }
|
||||
int64_t sk_tools::getCurrResidentSetSizeBytes() { return -1; }
|
||||
#endif
|
||||
|
||||
int sk_tools::getMaxResidentSetSizeMB() {
|
||||
int64_t bytes = sk_tools::getMaxResidentSetSizeBytes();
|
||||
return bytes < 0 ? -1 : static_cast<int>(bytes / 1024 / 1024);
|
||||
}
|
||||
|
||||
int sk_tools::getCurrResidentSetSizeMB() {
|
||||
int64_t bytes = sk_tools::getCurrResidentSetSizeBytes();
|
||||
return bytes < 0 ? -1 : static_cast<int>(bytes / 1024 / 1024);
|
||||
}
|
||||
|
@ -8,12 +8,26 @@
|
||||
#ifndef ProcStats_DEFINED
|
||||
#define ProcStats_DEFINED
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* ProcStats - Process Statistics Functions
|
||||
*/
|
||||
|
||||
namespace sk_tools {
|
||||
|
||||
/**
|
||||
* If implemented, returns the current resident set size in bytes.
|
||||
* If not, returns -1.
|
||||
*/
|
||||
int64_t getCurrResidentSetSizeBytes();
|
||||
|
||||
/**
|
||||
* If implemented, returns the maximum resident set size in MB.
|
||||
* If not, returns -1.
|
||||
*/
|
||||
int64_t getMaxResidentSetSizeBytes();
|
||||
|
||||
/**
|
||||
* If implemented, returns the maximum resident set size in MB.
|
||||
* If not, returns -1.
|
||||
|
Loading…
Reference in New Issue
Block a user