Skip to content

Commit

Permalink
[XRay] A tool for Comparing xray function call graphs
Browse files Browse the repository at this point in the history
Summary:
This is a tool for comparing the function graphs produced by the
llvm-xray graph too. It takes the form of a new subcommand of the
llvm-xray tool 'graph-diff'.

This initial version of the patch is very rough, but it is close to
feature complete.

Depends on D29363

Reviewers: dblaikie, dberris

Reviewed By: dberris

Subscribers: mgorny, llvm-commits

Differential Revision: https://reviews.llvm.org/D29320

llvm-svn: 301160
  • Loading branch information
deanberris committed Apr 24, 2017
1 parent fc03d2d commit ca780b5
Show file tree
Hide file tree
Showing 11 changed files with 1,087 additions and 132 deletions.
29 changes: 29 additions & 0 deletions llvm/test/tools/llvm-xray/X86/Inputs/graph-diff-A.yaml
@@ -0,0 +1,29 @@
---
header:
version: 1
type: 0
constant-tsc: true
nonstop-tsc: true
cycle-frequency: 1
records:
- { type: 0, func-id: 1, cpu: 1, thread: 111, kind: function-enter, tsc: 10000 }
- { type: 0, func-id: 1, cpu: 1, thread: 111, kind: function-exit, tsc: 10010 }
- { type: 0, func-id: 2, cpu: 1, thread: 111, kind: function-enter, tsc: 10100 }
- { type: 0, func-id: 2, cpu: 1, thread: 111, kind: function-exit, tsc: 10120 }
- { type: 0, func-id: 3, cpu: 1, thread: 111, kind: function-enter, tsc: 10200 }
- { type: 0, func-id: 3, cpu: 1, thread: 111, kind: function-exit, tsc: 10230 }
- { type: 0, func-id: 4, cpu: 1, thread: 111, kind: function-enter, tsc: 10300 }
- { type: 0, func-id: 4, cpu: 1, thread: 111, kind: function-exit, tsc: 10340 }
- { type: 0, func-id: 5, cpu: 1, thread: 111, kind: function-enter, tsc: 10400 }
- { type: 0, func-id: 5, cpu: 1, thread: 111, kind: function-exit, tsc: 10450 }
- { type: 0, func-id: 6, cpu: 1, thread: 111, kind: function-enter, tsc: 10500 }
- { type: 0, func-id: 6, cpu: 1, thread: 111, kind: function-exit, tsc: 10560 }
- { type: 0, func-id: 7, cpu: 1, thread: 111, kind: function-enter, tsc: 10600 }
- { type: 0, func-id: 7, cpu: 1, thread: 111, kind: function-exit, tsc: 10670 }
- { type: 0, func-id: 8, cpu: 1, thread: 111, kind: function-enter, tsc: 10700 }
- { type: 0, func-id: 8, cpu: 1, thread: 111, kind: function-exit, tsc: 10780 }
- { type: 0, func-id: 9, cpu: 1, thread: 111, kind: function-enter, tsc: 10800 }
- { type: 0, func-id: 9, cpu: 1, thread: 111, kind: function-exit, tsc: 10890 }
- { type: 0, func-id: 11, cpu: 1, thread: 111, kind: function-enter, tsc: 10900 }
- { type: 0, func-id: 11, cpu: 1, thread: 111, kind: function-exit, tsc: 10910 }
---
30 changes: 30 additions & 0 deletions llvm/test/tools/llvm-xray/X86/Inputs/graph-diff-B.yaml
@@ -0,0 +1,30 @@
---
header:
version: 1
type: 0
constant-tsc: true
nonstop-tsc: true
cycle-frequency: 1
records:
- { type: 0, func-id: 1, cpu: 1, thread: 111, kind: function-enter, tsc: 10000 }
- { type: 0, func-id: 1, cpu: 1, thread: 111, kind: function-exit, tsc: 10090 }
- { type: 0, func-id: 2, cpu: 1, thread: 111, kind: function-enter, tsc: 10100 }
- { type: 0, func-id: 2, cpu: 1, thread: 111, kind: function-exit, tsc: 10180 }
- { type: 0, func-id: 3, cpu: 1, thread: 111, kind: function-enter, tsc: 10200 }
- { type: 0, func-id: 3, cpu: 1, thread: 111, kind: function-exit, tsc: 10270 }
- { type: 0, func-id: 4, cpu: 1, thread: 111, kind: function-enter, tsc: 10300 }
- { type: 0, func-id: 4, cpu: 1, thread: 111, kind: function-exit, tsc: 10360 }
- { type: 0, func-id: 5, cpu: 1, thread: 111, kind: function-enter, tsc: 10400 }
- { type: 0, func-id: 5, cpu: 1, thread: 111, kind: function-exit, tsc: 10450 }
- { type: 0, func-id: 6, cpu: 1, thread: 111, kind: function-enter, tsc: 10500 }
- { type: 0, func-id: 6, cpu: 1, thread: 111, kind: function-exit, tsc: 10540 }
- { type: 0, func-id: 7, cpu: 1, thread: 111, kind: function-enter, tsc: 10600 }
- { type: 0, func-id: 7, cpu: 1, thread: 111, kind: function-exit, tsc: 10630 }
- { type: 0, func-id: 8, cpu: 1, thread: 111, kind: function-enter, tsc: 10700 }
- { type: 0, func-id: 8, cpu: 1, thread: 111, kind: function-exit, tsc: 10720 }
- { type: 0, func-id: 9, cpu: 1, thread: 111, kind: function-enter, tsc: 10800 }
- { type: 0, func-id: 9, cpu: 1, thread: 111, kind: function-exit, tsc: 10810 }
- { type: 0, func-id: 10, cpu: 1, thread: 111, kind: function-enter, tsc: 10900 }
- { type: 0, func-id: 10, cpu: 1, thread: 111, kind: function-exit, tsc: 10910 }
---

4 changes: 4 additions & 0 deletions llvm/test/tools/llvm-xray/X86/Inputs/simple-instrmap.yaml
Expand Up @@ -19,4 +19,8 @@
- { id: 8, address: 0x9, function: 0x8, kind: function-exit, always-instrument: true}
- { id: 9, address: 0x9, function: 0x9, kind: function-enter, always-instrument: true}
- { id: 9, address: 0xA, function: 0x9, kind: function-exit, always-instrument: true}
- { id: 10, address: 0xA, function: 0xA, kind: function-enter, always-instrument: true}
- { id: 10, address: 0xB, function: 0xA, kind: function-exit, always-instrument: true}
- { id: 11, address: 0xB, function: 0xB, kind: function-enter, always-instrument: true}
- { id: 11, address: 0xC, function: 0xB, kind: function-exit, always-instrument: true}
...
238 changes: 238 additions & 0 deletions llvm/test/tools/llvm-xray/X86/graph-diff-simple.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions llvm/tools/llvm-xray/CMakeLists.txt
Expand Up @@ -14,6 +14,7 @@ set(LLVM_XRAY_TOOLS
xray-extract.cc
xray-extract.cc
xray-graph.cc
xray-graph-diff.cc
xray-registry.cc)

add_llvm_tool(llvm-xray llvm-xray.cc ${LLVM_XRAY_TOOLS})
34 changes: 30 additions & 4 deletions llvm/tools/llvm-xray/xray-color-helper.cc
Expand Up @@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
#include <algorithm>
#include <iostream>

#include "xray-color-helper.h"
#include "llvm/Support/FormatVariadic.h"
Expand Down Expand Up @@ -42,8 +43,18 @@ static const std::tuple<uint8_t, uint8_t, uint8_t> SequentialMaps[][9] = {
std::make_tuple(5, 112, 176), std::make_tuple(4, 90, 141),
std::make_tuple(2, 56, 88)}};

// Sequential Maps extend the last colors given out of range inputs.
static const std::tuple<uint8_t, uint8_t, uint8_t> SequentialBounds[][2] = {
{// The Bounds for the greys color scheme
std::make_tuple(255, 255, 255), std::make_tuple(0, 0, 0)},
{// The Bounds for the OrRd color Scheme
std::make_tuple(255, 247, 236), std::make_tuple(127, 0, 0)},
{// The Bounds for the PuBu color Scheme
std::make_tuple(255, 247, 251), std::make_tuple(2, 56, 88)}};

ColorHelper::ColorHelper(ColorHelper::SequentialScheme S)
: MinIn(0.0), MaxIn(1.0), ColorMap(SequentialMaps[static_cast<int>(S)]) {}
: MinIn(0.0), MaxIn(1.0), ColorMap(SequentialMaps[static_cast<int>(S)]),
BoundMap(SequentialBounds[static_cast<int>(S)]) {}

// Diverging ColorMaps, which are used to represent information
// representing differenes, or a range that goes from negative to positive.
Expand All @@ -58,8 +69,16 @@ static const std::tuple<uint8_t, uint8_t, uint8_t> DivergingCoeffs[][11] = {
std::make_tuple(127, 188, 65), std::make_tuple(77, 146, 33),
std::make_tuple(39, 100, 25)}};

// Diverging maps use out of bounds ranges to show missing data. Missing Right
// Being below min, and missing left being above max.
static const std::tuple<uint8_t, uint8_t, uint8_t> DivergingBounds[][2] = {
{// The PiYG color scheme has green and red for missing right and left
// respectively.
std::make_tuple(255, 0, 0), std::make_tuple(0, 255, 0)}};

ColorHelper::ColorHelper(ColorHelper::DivergingScheme S)
: MinIn(-1.0), MaxIn(1.0), ColorMap(DivergingCoeffs[static_cast<int>(S)]) {}
: MinIn(-1.0), MaxIn(1.0), ColorMap(DivergingCoeffs[static_cast<int>(S)]),
BoundMap(DivergingBounds[static_cast<int>(S)]) {}

// Takes a tuple of uint8_ts representing a color in RGB and converts them to
// HSV represented by a tuple of doubles
Expand All @@ -78,12 +97,12 @@ convertToHSV(const std::tuple<uint8_t, uint8_t, uint8_t> &Color) {

double C = Scaled[Max] - Scaled[Min];

double HPrime = (Scaled[(Max + 1) % 3] - Scaled[(Max + 2) % 3]) / C;
double HPrime =
(C == 0) ? 0 : (Scaled[(Max + 1) % 3] - Scaled[(Max + 2) % 3]) / C;
HPrime = HPrime + 2.0 * Max;

double H = (HPrime < 0) ? (HPrime + 6.0) * 60
: HPrime * 60; // Scale to between 0 and 360

double V = Scaled[Max];

double S = (V == 0.0) ? 0.0 : C / V;
Expand Down Expand Up @@ -164,6 +183,13 @@ interpolateHSV(const std::tuple<double, double, double> &C0,
std::tuple<uint8_t, uint8_t, uint8_t>
ColorHelper::getColorTuple(double Point) const {
assert(!ColorMap.empty() && "ColorMap must not be empty!");
assert(!BoundMap.empty() && "BoundMap must not be empty!");

if (Point < MinIn)
return BoundMap[0];
if (Point > MaxIn)
return BoundMap[1];

size_t MaxIndex = ColorMap.size() - 1;
double IntervalWidth = MaxIn - MinIn;
double OffsetP = Point - MinIn;
Expand Down
12 changes: 10 additions & 2 deletions llvm/tools/llvm-xray/xray-color-helper.h
Expand Up @@ -46,6 +46,7 @@ class ColorHelper {
double MaxIn;

ArrayRef<std::tuple<uint8_t, uint8_t, uint8_t>> ColorMap;
ArrayRef<std::tuple<uint8_t, uint8_t, uint8_t>> BoundMap;

public:
/// Enum of the availible Sequential Color Schemes
Expand Down Expand Up @@ -73,9 +74,16 @@ class ColorHelper {

std::string getColorString(double Point) const;

// Get the Default color, at the moment allways black.
std::tuple<uint8_t, uint8_t, uint8_t> getDefaultColorTuple() const {
return std::make_tuple(0, 0, 0);
}

std::string getDefaultColorString() const { return "black"; }

// Convert a tuple to a string
static std::string getColorString(std::tuple<uint8_t, uint8_t, uint8_t> t);
};
}
}
} // namespace xray
} // namespace llvm
#endif

0 comments on commit ca780b5

Please sign in to comment.