diff options
author | halcanary <halcanary@google.com> | 2014-08-07 13:13:54 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-08-07 13:13:54 -0700 |
commit | 6274baae7fe82ce6481da367687aa6168356e1e1 (patch) | |
tree | fec4af39d1a812d0d28be4fb7d982845ca3c1948 | |
parent | 0898e2b420fd497bbb85e9546b80453c77c45a6b (diff) |
Process Statistics header, add max RSS to render_pdfs
R=mtklein@google.com
Author: halcanary@google.com
Review URL: https://codereview.chromium.org/448993003
-rw-r--r-- | dm/DMReporter.cpp | 21 | ||||
-rw-r--r-- | gyp/dm.gypi | 1 | ||||
-rw-r--r-- | gyp/tools.gyp | 12 | ||||
-rw-r--r-- | tools/ProcStats.cpp | 31 | ||||
-rw-r--r-- | tools/ProcStats.h | 25 | ||||
-rw-r--r-- | tools/render_pdfs_main.cpp | 10 |
6 files changed, 82 insertions, 18 deletions
diff --git a/dm/DMReporter.cpp b/dm/DMReporter.cpp index 14f5087102..12bcfac0f3 100644 --- a/dm/DMReporter.cpp +++ b/dm/DMReporter.cpp @@ -3,21 +3,7 @@ #include "SkDynamicAnnotations.h" #include "SkCommonFlags.h" #include "OverwriteLine.h" - -#if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_ANDROID) - #include <sys/resource.h> - static long get_max_rss_kb() { - struct rusage ru; - getrusage(RUSAGE_SELF, &ru); - #if defined(SK_BUILD_FOR_MAC) - return ru.ru_maxrss / 1024; // Darwin reports bytes. - #else - return ru.ru_maxrss; // Linux reports kilobytes. - #endif - } -#else - static long get_max_rss_kb() { return 0; } -#endif +#include "ProcStats.h" namespace DM { @@ -36,8 +22,9 @@ void Reporter::printStatus(SkString name, SkMSec timeMs) const { status.appendf(", %d failed", failed); } if (FLAGS_verbose) { - if (long max_rss_kb = get_max_rss_kb()) { - status.appendf("\t%4ldM peak", max_rss_kb / 1024); + int max_rss_kb = sk_tools::getMaxResidentSetSizeKB(); + if (max_rss_kb >= 0) { + status.appendf("\t%4dM peak", max_rss_kb / 1024); } status.appendf("\t%5dms\t%s", timeMs, name.c_str()); } diff --git a/gyp/dm.gypi b/gyp/dm.gypi index 1f11e17872..2a13c80e66 100644 --- a/gyp/dm.gypi +++ b/gyp/dm.gypi @@ -19,6 +19,7 @@ 'jsoncpp.gyp:jsoncpp', 'skia_lib.gyp:skia_lib', 'tools.gyp:crash_handler', + 'tools.gyp:sk_tool_proc_stats', 'tools.gyp:sk_tool_utils', ], 'includes': [ diff --git a/gyp/tools.gyp b/gyp/tools.gyp index f36c523435..f4d927cd89 100644 --- a/gyp/tools.gyp +++ b/gyp/tools.gyp @@ -530,6 +530,7 @@ 'pdf.gyp:pdf', 'skia_lib.gyp:skia_lib', 'tools.gyp:picture_utils', + 'tools.gyp:sk_tool_proc_stats', ], 'conditions': [ ['skia_win_debuggers_path and skia_os == "win"', @@ -646,6 +647,17 @@ 'skia_lib.gyp:skia_lib', ], }, + { + 'target_name': 'sk_tool_proc_stats', + 'type': 'static_library', + 'sources': [ + '../tools/ProcStats.h', + '../tools/ProcStats.cpp', + ], + 'direct_dependent_settings': { + 'include_dirs': [ '../tools', ], + }, + }, ], 'conditions': [ ['skia_shared_lib', diff --git a/tools/ProcStats.cpp b/tools/ProcStats.cpp new file mode 100644 index 0000000000..94660394f8 --- /dev/null +++ b/tools/ProcStats.cpp @@ -0,0 +1,31 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "ProcStats.h" + +#if defined(SK_BUILD_FOR_UNIX) || \ + defined(SK_BUILD_FOR_MAC) || \ + defined(SK_BUILD_FOR_ANDROID) + + #include <sys/resource.h> + int sk_tools::getMaxResidentSetSizeKB() { + struct rusage ru; + getrusage(RUSAGE_SELF, &ru); + #if defined(SK_BUILD_FOR_MAC) + return static_cast<int>(ru.ru_maxrss / 1024); // Darwin reports bytes. + #else + return static_cast<int>(ru.ru_maxrss); // Linux reports kilobytes. + #endif + } + +#else + + int sk_tools::getMaxResidentSetSizeKB() { + return -1; + } + +#endif diff --git a/tools/ProcStats.h b/tools/ProcStats.h new file mode 100644 index 0000000000..42849f1401 --- /dev/null +++ b/tools/ProcStats.h @@ -0,0 +1,25 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef ProcStats_DEFINED +#define ProcStats_DEFINED + +/** + * ProcStats - Process Statistics Functions + */ + +namespace sk_tools { + +/** + * If not implemented for this OS, returns -1. Otherwise, return + * the maximum resident set size, as reported by getrusage(). + */ +int getMaxResidentSetSizeKB(); + +} // namespace sk_tools + +#endif // ProcStats_DEFINED diff --git a/tools/render_pdfs_main.cpp b/tools/render_pdfs_main.cpp index be294399ec..34e5e58f53 100644 --- a/tools/render_pdfs_main.cpp +++ b/tools/render_pdfs_main.cpp @@ -18,6 +18,7 @@ #include "SkTArray.h" #include "SkTSort.h" #include "PdfRenderer.h" +#include "ProcStats.h" #include "picture_utils.h" __SK_FORCE_IMAGE_DECODER_LINKING; @@ -219,7 +220,9 @@ static int process_input( } } } - SkTQSort<SkString>(files.begin(), files.end() - 1); + if (files.count() > 0) { + SkTQSort<SkString>(files.begin(), files.end() - 1); + } int failures = 0; for (int i = 0; i < files.count(); i ++) { if (!render_pdf(files[i], outputDir, renderer)) { @@ -246,6 +249,11 @@ int tool_main_core(int argc, char** argv) { int failures = process_input(FLAGS_inputPaths, outputDir, *renderer); + int max_rss_kb = sk_tools::getMaxResidentSetSizeKB(); + if (max_rss_kb >= 0) { + SkDebugf("%4dM peak ResidentSetSize\n", max_rss_kb / 1024); + } + if (failures != 0) { SkDebugf("Failed to render %i PDFs.\n", failures); return 1; |