summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-xray/xray-color-helper.cc
diff options
context:
space:
mode:
authorDean Michael Berris <dberris@google.com>2017-04-24 05:54:33 +0000
committerDean Michael Berris <dberris@google.com>2017-04-24 05:54:33 +0000
commitca780b5a279d41a5a7b4ce77505083cb7ed7b624 (patch)
treeb1099eb030b4c9139024832422794d045b62c2d5 /llvm/tools/llvm-xray/xray-color-helper.cc
parentfc03d2d21f9f364b2d5ab41f42625a1c98eab351 (diff)
downloadbcm5719-llvm-ca780b5a279d41a5a7b4ce77505083cb7ed7b624.tar.gz
bcm5719-llvm-ca780b5a279d41a5a7b4ce77505083cb7ed7b624.zip
[XRay] A tool for Comparing xray function call graphs
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
Diffstat (limited to 'llvm/tools/llvm-xray/xray-color-helper.cc')
-rw-r--r--llvm/tools/llvm-xray/xray-color-helper.cc34
1 files changed, 30 insertions, 4 deletions
diff --git a/llvm/tools/llvm-xray/xray-color-helper.cc b/llvm/tools/llvm-xray/xray-color-helper.cc
index 925bb7483d8..7b6a73a5552 100644
--- a/llvm/tools/llvm-xray/xray-color-helper.cc
+++ b/llvm/tools/llvm-xray/xray-color-helper.cc
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
#include <algorithm>
+#include <iostream>
#include "xray-color-helper.h"
#include "llvm/Support/FormatVariadic.h"
@@ -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.
@@ -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
@@ -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;
@@ -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;
OpenPOWER on IntegriCloud