summaryrefslogtreecommitdiff
path: root/chromium/content/browser/tcmalloc_internals_request_job.h
blob: 20b2d4fc5f75c8bb9d704ed62221c9e7a619aa32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_TCMALLOC_INTERNALS_REQUEST_JOB_H_
#define CONTENT_BROWSER_TCMALLOC_INTERNALS_REQUEST_JOB_H_

#include <map>
#include "base/basictypes.h"
#include "base/memory/singleton.h"
#include "base/process/process.h"
#include "build/build_config.h"  // USE_TCMALLOC
#include "net/url_request/url_request_simple_job.h"

namespace content {

class AboutTcmallocOutputs {
 public:
  // Returns the singleton instance.
  static AboutTcmallocOutputs* GetInstance();

  // Records the output for a specified header string.
  void SetOutput(const std::string& header, const std::string& output);

  void DumpToHTMLTable(std::string* data);

  // Callback for output returned from a child process.  Adds
  // the output for a canonical process-specific header string that
  // incorporates the pid.
  void OnStatsForChildProcess(base::ProcessId pid,
                              int process_type,
                              const std::string& output);

 private:
  AboutTcmallocOutputs();
  ~AboutTcmallocOutputs();

  // A map of header strings (e.g. "Browser", "Renderer PID 123")
  // to the tcmalloc output collected for each process.
  typedef std::map<std::string, std::string> AboutTcmallocOutputsType;
  AboutTcmallocOutputsType outputs_;

  friend struct DefaultSingletonTraits<AboutTcmallocOutputs>;

  DISALLOW_COPY_AND_ASSIGN(AboutTcmallocOutputs);
};

class TcmallocInternalsRequestJob : public net::URLRequestSimpleJob {
 public:
  TcmallocInternalsRequestJob(net::URLRequest* request,
                              net::NetworkDelegate* network_delegate);

  virtual int GetData(std::string* mime_type,
                      std::string* charset,
                      std::string* data,
                      const net::CompletionCallback& callback) const OVERRIDE;

 protected:
  virtual ~TcmallocInternalsRequestJob() {}

 private:
  DISALLOW_IMPLICIT_CONSTRUCTORS(TcmallocInternalsRequestJob);
};

}  // namespace content

#endif  // CONTENT_BROWSER_TCMALLOC_INTERNALS_REQUEST_JOB_H_