summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-modernize/Core/PerfSupport.h
blob: 58ddded22076473807458e7d15bdcfab6198f918 (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
//===-- Core/PerfSupport.h - Perf measurement helpers -----------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief This file provides helper functionality for measuring performance and
/// recording data to file.
///
//===----------------------------------------------------------------------===//

#ifndef CPP11_MIGRATE_PERFSUPPORT_H
#define CPP11_MIGRATE_PERFSUPPORT_H

#include "Transform.h"
#include "llvm/ADT/StringRef.h"

#include <map>
#include <vector>

/// \brief A single piece of performance data: a duration in milliseconds and a
/// label for that duration.
struct PerfItem {
  PerfItem(const llvm::StringRef Label, float Duration)
      : Label(Label), Duration(Duration) {}

  /// Label for this performance measurement.
  std::string Label;

  /// Duration in milliseconds.
  float Duration;
};

/// Maps source file names to a vector of durations/labels.
typedef std::map<std::string, std::vector<PerfItem> > SourcePerfData;

/// Extracts durations collected by a Transform for all sources and adds them
/// to a SourcePerfData map where data is organized by source file.
extern void collectSourcePerfData(const Transform &T, SourcePerfData &Data);

/// Write timing results to a JSON formatted file.
///
/// File is placed in the directory given by \p DirectoryName. File is named in
/// a unique way with time and process ID to avoid naming collisions with
/// existing files or files being generated by other migrator processes.
void writePerfDataJSON(
    const llvm::StringRef DirectoryName,
    const SourcePerfData &TimingResults);

/// Dump a SourcePerfData map to llvm::errs().
extern void dumpPerfData(const SourcePerfData &Data);

#endif // CPP11_MIGRATE_PERFSUPPORT_H
OpenPOWER on IntegriCloud