From 95ea778b4411bbd46b21f93e391f3bbd3e798342 Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Tue, 11 Jul 2017 16:42:43 -0400 Subject: Added Callgrind instrumentation delimiters to pdfium_test. Change-Id: I664497b5bab640e642bde3f80aaeb62467237407 Reviewed-on: https://pdfium-review.googlesource.com/7281 Reviewed-by: dsinclair Reviewed-by: Lei Zhang Commit-Queue: Henrique Nakashima --- samples/BUILD.gn | 5 +++++ samples/pdfium_test.cc | 32 +++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) (limited to 'samples') diff --git a/samples/BUILD.gn b/samples/BUILD.gn index 59ab4b4a11..8fbf5d552f 100644 --- a/samples/BUILD.gn +++ b/samples/BUILD.gn @@ -32,6 +32,11 @@ config("pdfium_samples_config") { if (is_asan) { defines += [ "PDF_ENABLE_ASAN" ] } + + if (enable_callgrind) { + defines += [ "ENABLE_CALLGRIND" ] + } + if (use_coverage && is_clang) { cflags += [ "--coverage", diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc index 85cc0d3526..93821d963a 100644 --- a/samples/pdfium_test.cc +++ b/samples/pdfium_test.cc @@ -37,6 +37,10 @@ #include #endif +#ifdef ENABLE_CALLGRIND +#include +#endif // ENABLE_CALLGRIND + #ifdef PDF_ENABLE_V8 #include "v8/include/libplatform/libplatform.h" #include "v8/include/v8.h" @@ -76,13 +80,20 @@ struct Options { : show_config(false), show_metadata(false), send_events(false), +#ifdef ENABLE_CALLGRIND + callgrind_delimiters(false), +#endif // ENABLE_CALLGRIND pages(false), md5(false), - output_format(OUTPUT_NONE) {} + output_format(OUTPUT_NONE) { + } bool show_config; bool show_metadata; bool send_events; +#ifdef ENABLE_CALLGRIND + bool callgrind_delimiters; +#endif // ENABLE_CALLGRIND bool pages; bool md5; OutputFormat output_format; @@ -624,6 +635,10 @@ bool ParseCommandLine(const std::vector& args, options->show_metadata = true; } else if (cur_arg == "--send-events") { options->send_events = true; +#ifdef ENABLE_CALLGRIND + } else if (cur_arg == "--callgrind-delim") { + options->callgrind_delimiters = true; +#endif // ENABLE_CALLGRIND } else if (cur_arg == "--ppm") { if (options->output_format != OUTPUT_NONE) { fprintf(stderr, "Duplicate or conflicting --ppm argument\n"); @@ -1201,8 +1216,12 @@ static void ShowConfig() { static const char kUsageString[] = "Usage: pdfium_test [OPTION] [FILE]...\n" " --show-config - print build options and exit\n" + " --show-metadata - print the file metadata\n" " --show-structure - print the structure elements from the document\n" " --send-events - send input described by .evt file\n" +#ifdef ENABLE_CALLGRIND + " --callgrind-delim - delimit interesting section when using callgrind\n" +#endif // ENABLE_CALLGRIND " --bin-dir= - override path to v8 external data\n" " --font-dir= - override path to external fonts\n" " --scale= - scale output size by number (e.g. 0.5)\n" @@ -1281,6 +1300,12 @@ int main(int argc, const char* argv[]) { if (!file_contents) continue; fprintf(stderr, "Rendering PDF file %s.\n", filename.c_str()); + +#ifdef ENABLE_CALLGRIND + if (options.callgrind_delimiters) + CALLGRIND_START_INSTRUMENTATION; +#endif // ENABLE_CALLGRIND + std::string events; if (options.send_events) { std::string event_filename = filename; @@ -1301,6 +1326,11 @@ int main(int argc, const char* argv[]) { } } RenderPdf(filename, file_contents.get(), file_length, options, events); + +#ifdef ENABLE_CALLGRIND + if (options.callgrind_delimiters) + CALLGRIND_STOP_INSTRUMENTATION; +#endif // ENABLE_CALLGRIND } FPDF_DestroyLibrary(); -- cgit v1.2.3