Commit d99dda01 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Printing: Add metrics for PDF to native format conversions on Windows.

BUG=792308

Change-Id: Iac85f6f2cf2db684b8cddb7926d4a032e154ee41
Reviewed-on: https://chromium-review.googlesource.com/1056472Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560687}
parent 1a3debc9
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted_delete_on_sequence.h" #include "base/memory/ref_counted_delete_on_sequence.h"
#include "base/metrics/histogram_macros.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/task_scheduler/post_task.h" #include "base/task_scheduler/post_task.h"
#include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
...@@ -170,6 +171,8 @@ class PdfConverterImpl : public PdfConverter { ...@@ -170,6 +171,8 @@ class PdfConverterImpl : public PdfConverter {
void OnFailed(const std::string& error_message); void OnFailed(const std::string& error_message);
void RecordConversionMetrics();
PdfRenderSettings settings_; PdfRenderSettings settings_;
// Document loaded callback. // Document loaded callback.
...@@ -181,6 +184,11 @@ class PdfConverterImpl : public PdfConverter { ...@@ -181,6 +184,11 @@ class PdfConverterImpl : public PdfConverter {
using GetPageCallbacks = base::queue<GetPageCallbackData>; using GetPageCallbacks = base::queue<GetPageCallbackData>;
GetPageCallbacks get_page_callbacks_; GetPageCallbacks get_page_callbacks_;
// Keep track of document size and page counts for metrics.
size_t bytes_generated_ = 0;
uint32_t pages_generated_ = 0;
uint32_t page_count_ = 0;
std::unique_ptr<PdfToEmfConverterClientImpl> std::unique_ptr<PdfToEmfConverterClientImpl>
pdf_to_emf_converter_client_impl_; pdf_to_emf_converter_client_impl_;
...@@ -245,6 +253,8 @@ PdfConverterImpl::PdfConverterImpl( ...@@ -245,6 +253,8 @@ PdfConverterImpl::PdfConverterImpl(
PdfConverterImpl::~PdfConverterImpl() { PdfConverterImpl::~PdfConverterImpl() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
RecordConversionMetrics();
} }
void PdfConverterImpl::Initialize( void PdfConverterImpl::Initialize(
...@@ -292,6 +302,7 @@ void PdfConverterImpl::OnPageCount(mojom::PdfToEmfConverterPtr converter, ...@@ -292,6 +302,7 @@ void PdfConverterImpl::OnPageCount(mojom::PdfToEmfConverterPtr converter,
&PdfConverterImpl::OnFailed, weak_ptr_factory_.GetWeakPtr(), &PdfConverterImpl::OnFailed, weak_ptr_factory_.GetWeakPtr(),
std::string("Connection to PdfToEmfConverter error."))); std::string("Connection to PdfToEmfConverter error.")));
std::move(start_callback_).Run(page_count); std::move(start_callback_).Run(page_count);
page_count_ = page_count;
} }
void PdfConverterImpl::GetPage( void PdfConverterImpl::GetPage(
...@@ -322,8 +333,14 @@ void PdfConverterImpl::OnPageDone(base::ReadOnlySharedMemoryRegion emf_region, ...@@ -322,8 +333,14 @@ void PdfConverterImpl::OnPageDone(base::ReadOnlySharedMemoryRegion emf_region,
std::unique_ptr<MetafilePlayer> metafile; std::unique_ptr<MetafilePlayer> metafile;
if (emf_region.IsValid()) { if (emf_region.IsValid()) {
base::ReadOnlySharedMemoryMapping mapping = emf_region.Map(); base::ReadOnlySharedMemoryMapping mapping = emf_region.Map();
if (mapping.IsValid()) if (mapping.IsValid()) {
size_t mapping_size = mapping.size();
metafile = GetMetaFileFromMapping(std::move(mapping)); metafile = GetMetaFileFromMapping(std::move(mapping));
if (metafile) {
++pages_generated_;
bytes_generated_ += mapping_size;
}
}
} }
base::WeakPtr<PdfConverterImpl> weak_this = weak_ptr_factory_.GetWeakPtr(); base::WeakPtr<PdfConverterImpl> weak_this = weak_ptr_factory_.GetWeakPtr();
...@@ -363,6 +380,41 @@ void PdfConverterImpl::OnFailed(const std::string& error_message) { ...@@ -363,6 +380,41 @@ void PdfConverterImpl::OnFailed(const std::string& error_message) {
Stop(); Stop();
} }
void PdfConverterImpl::RecordConversionMetrics() {
if (!page_count_ || page_count_ != pages_generated_) {
// TODO(thestig): Consider adding UMA to track failure rates.
return;
}
DCHECK(bytes_generated_);
size_t average_page_size_in_kb = bytes_generated_ / 1024;
average_page_size_in_kb /= page_count_;
switch (settings_.mode) {
case PdfRenderSettings::Mode::NORMAL:
UMA_HISTOGRAM_MEMORY_KB("Printing.ConversionSize.Emf",
average_page_size_in_kb);
return;
case PdfRenderSettings::Mode::TEXTONLY:
// Intentionally not logged.
return;
case PdfRenderSettings::Mode::GDI_TEXT:
UMA_HISTOGRAM_MEMORY_KB("Printing.ConversionSize.EmfWithGdiText",
average_page_size_in_kb);
return;
case PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2:
UMA_HISTOGRAM_MEMORY_KB("Printing.ConversionSize.PostScript2",
average_page_size_in_kb);
return;
case PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3:
UMA_HISTOGRAM_MEMORY_KB("Printing.ConversionSize.PostScript3",
average_page_size_in_kb);
return;
default:
NOTREACHED();
return;
}
}
} // namespace } // namespace
PdfConverter::~PdfConverter() = default; PdfConverter::~PdfConverter() = default;
......
...@@ -72887,6 +72887,37 @@ uploading your change for review. ...@@ -72887,6 +72887,37 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="Printing.ConversionSize.Emf" units="KB">
<owner>thestig@chromium.org</owner>
<summary>
On Windows, the average size of a printed page after converting to EMF.
</summary>
</histogram>
<histogram name="Printing.ConversionSize.EmfWithGdiText" units="KB">
<owner>thestig@chromium.org</owner>
<summary>
On Windows, the average size of a printed page after converting to EMF with
the GDI Text experiment turned on.
</summary>
</histogram>
<histogram name="Printing.ConversionSize.PostScript2" units="KB">
<owner>thestig@chromium.org</owner>
<summary>
On Windows, the average size of a printed page after converting to level 2
PostScript.
</summary>
</histogram>
<histogram name="Printing.ConversionSize.PostScript3" units="KB">
<owner>thestig@chromium.org</owner>
<summary>
On Windows, the average size of a printed page after converting to level 3
PostScript.
</summary>
</histogram>
<histogram name="Printing.CUPS.AddressResolutionResult" enum="BooleanSuccess"> <histogram name="Printing.CUPS.AddressResolutionResult" enum="BooleanSuccess">
<owner>skau@chromium.org</owner> <owner>skau@chromium.org</owner>
<summary> <summary>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment