1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_TEST_PERF_PERF_TEST_H_
6#define CHROME_TEST_PERF_PERF_TEST_H_
7
8#include <stdio.h>
9#include <string>
10
11#include "chrome/test/base/chrome_process_util.h"
12
13namespace perf_test {
14
15// Prints numerical information to stdout in a controlled format, for
16// post-processing. |measurement| is a description of the quantity being
17// measured, e.g. "vm_peak"; |modifier| is provided as a convenience and
18// will be appended directly to the name of the |measurement|, e.g.
19// "_browser"; |trace| is a description of the particular data point, e.g.
20// "reference"; |value| is the measured value; and |units| is a description
21// of the units of measure, e.g. "bytes". If |important| is true, the output
22// line will be specially marked, to notify the post-processor. The strings
23// may be empty.  They should not contain any colons (:) or equals signs (=).
24// A typical post-processing step would be to produce graphs of the data
25// produced for various builds, using the combined |measurement| + |modifier|
26// string to specify a particular graph and the |trace| to identify a trace
27// (i.e., data series) on that graph.
28void PrintResult(const std::string& measurement,
29                 const std::string& modifier,
30                 const std::string& trace,
31                 size_t value,
32                 const std::string& units,
33                 bool important);
34
35void AppendResult(std::string& output,
36                  const std::string& measurement,
37                  const std::string& modifier,
38                  const std::string& trace,
39                  size_t value,
40                  const std::string& units,
41                  bool important);
42
43// Like the above version of PrintResult(), but takes a std::string value
44// instead of a size_t.
45void PrintResult(const std::string& measurement,
46                 const std::string& modifier,
47                 const std::string& trace,
48                 const std::string& value,
49                 const std::string& units,
50                 bool important);
51
52void AppendResult(std::string& output,
53                  const std::string& measurement,
54                  const std::string& modifier,
55                  const std::string& trace,
56                  const std::string& value,
57                  const std::string& units,
58                  bool important);
59
60// Like PrintResult(), but prints a (mean, standard deviation) result pair.
61// The |<values>| should be two comma-separated numbers, the mean and
62// standard deviation (or other error metric) of the measurement.
63void PrintResultMeanAndError(const std::string& measurement,
64                             const std::string& modifier,
65                             const std::string& trace,
66                             const std::string& mean_and_error,
67                             const std::string& units,
68                             bool important);
69
70void AppendResultMeanAndError(std::string& output,
71                              const std::string& measurement,
72                              const std::string& modifier,
73                              const std::string& trace,
74                              const std::string& mean_and_error,
75                              const std::string& units,
76                              bool important);
77
78// Like PrintResult(), but prints an entire list of results. The |values|
79// will generally be a list of comma-separated numbers. A typical
80// post-processing step might produce plots of their mean and standard
81// deviation.
82void PrintResultList(const std::string& measurement,
83                     const std::string& modifier,
84                     const std::string& trace,
85                     const std::string& values,
86                     const std::string& units,
87                     bool important);
88
89void AppendResultList(std::string& output,
90                      const std::string& measurement,
91                      const std::string& modifier,
92                      const std::string& trace,
93                      const std::string& values,
94                      const std::string& units,
95                      bool important);
96
97// Prints IO performance data for use by perf graphs.
98void PrintIOPerfInfo(const std::string& test_name,
99                     const ChromeProcessList& chrome_processes,
100                     base::ProcessId browser_pid);
101
102void PrintIOPerfInfo(FILE* target,
103                     const std::string& test_name,
104                     const ChromeProcessList& chrome_processes,
105                     base::ProcessId browser_pid);
106
107std::string IOPerfInfoToString(const std::string& test_name,
108                               const ChromeProcessList& chrome_processes,
109                               base::ProcessId browser_pid);
110
111// Prints memory usage data for use by perf graphs.
112void PrintMemoryUsageInfo(const std::string& test_name,
113                          const ChromeProcessList& chrome_processes,
114                          base::ProcessId browser_pid);
115
116void PrintMemoryUsageInfo(FILE* target,
117                          const std::string& test_name,
118                          const ChromeProcessList& chrome_processes,
119                          base::ProcessId browser_pid);
120
121std::string MemoryUsageInfoToString(const std::string& test_name,
122                                    const ChromeProcessList& chrome_processes,
123                                    base::ProcessId browser_pid);
124
125// Prints memory commit charge stats for use by perf graphs.
126void PrintSystemCommitCharge(const std::string& test_name,
127                             size_t charge,
128                             bool important);
129
130void PrintSystemCommitCharge(FILE* target,
131                             const std::string& test_name,
132                             size_t charge,
133                             bool important);
134
135std::string SystemCommitChargeToString(const std::string& test_name,
136                                       size_t charge,
137                                       bool important);
138
139}  // namespace perf_test
140
141#endif  // CHROME_TEST_PERF_PERF_TEST_H_
142