@@ -97,6 +97,23 @@ void Color::setRainbowColor(int n)
set(r, g, b);
}
+/** Alpha blending with white background. */
+void Color::blend(float alpha)
+{
+ if (alpha < 0 || alpha > 1.)
+ return;
+
+ auto lamBld = [alpha](int val) {
+ return val * alpha + (1 - alpha) * 255;
+ };
+
+ int r = lamBld(this->r());
+ int g = lamBld(this->g());
+ int b = lamBld(this->b());
+
+ set(r, g, b);
+}
+
/**
* @brief Create a Hash table of Rainbow colors. The sorted Pid values are
* mapped to the palette of Rainbow colors.
@@ -182,6 +199,39 @@ ColorTable getCPUColorTable()
return colors;
}
+/**
+ * @brief Create a Hash table of Rainbow colors. The Steam Ids are
+ * mapped to the palette of Rainbow colors.
+ *
+ * @returns ColorTable instance.
+ */
+ColorTable getStreamColorTable()
+{
+ kshark_context *kshark_ctx(nullptr);
+ ColorTable colors;
+ Color color;
+ float alpha(.35);
+ int *streamIds;
+
+ if (!kshark_instance(&kshark_ctx))
+ return colors;
+
+ streamIds = kshark_all_streams(kshark_ctx);
+ for (int i = 0; i < kshark_ctx->n_streams; ++i) {
+ /*
+ * Starting from index 6 provides better functioning of the
+ * color scheme slider.
+ */
+ color.setRainbowColor(i + 6);
+ color.blend(alpha);
+ colors[streamIds[i]] = color;
+ }
+
+ free(streamIds);
+
+ return colors;
+}
+
/**
* @brief Search the Hash table of Rainbow colors for a particular key (pid).
*
@@ -47,6 +47,8 @@ public:
void setRainbowColor(int n);
+ void blend(float alpha);
+
/**
* @brief Get the C struct defining the RGB color.
*/
@@ -78,6 +80,8 @@ ColorTable getTaskColorTable();
ColorTable getCPUColorTable();
+ColorTable getStreamColorTable();
+
Color getColor(ColorTable *colors, int pid);
/** Represents an abstract graphical element. */
This method provides a hash table that maps the stream Ids to rainbow-like colors. Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com> --- src/KsPlotTools.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++ src/KsPlotTools.hpp | 4 ++++ 2 files changed, 54 insertions(+)