diff options
author | Yordan Karadzhov (VMware) <y.karadz@gmail.com> | 2020-12-09 15:45:22 +0200 |
---|---|---|
committer | Steven Rostedt (VMware) <rostedt@goodmis.org> | 2020-12-22 10:52:35 -0500 |
commit | 2bbf4339b73c3ad0e744cc73f8695ee58437d3ee (patch) | |
tree | 806f24e85b38b784872eac1bcc15550bec3a3e10 | |
parent | e27dae06dbcbda8f48faa06468ee7d722adf03a4 (diff) | |
download | kernel-shark-2bbf4339b73c3ad0e744cc73f8695ee58437d3ee.tar.gz |
kernel-shark: Add getStreamColorTable()
This method provides a hash table that maps the stream Ids to
rainbow-like colors.
Link: https://lore.kernel.org/linux-trace-devel/20201209134530.428368-3-y.karadz@gmail.com
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rw-r--r-- | src/KsPlotTools.cpp | 33 | ||||
-rw-r--r-- | src/KsPlotTools.hpp | 2 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/KsPlotTools.cpp b/src/KsPlotTools.cpp index 3f86f16a..cfaec77d 100644 --- a/src/KsPlotTools.cpp +++ b/src/KsPlotTools.cpp @@ -200,6 +200,39 @@ ColorTable getCPUColorTable() } /** + * @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). * * @param colors: Input location for the ColorTable instance. diff --git a/src/KsPlotTools.hpp b/src/KsPlotTools.hpp index 7f83af2d..b64aaf5b 100644 --- a/src/KsPlotTools.hpp +++ b/src/KsPlotTools.hpp @@ -80,6 +80,8 @@ ColorTable getTaskColorTable(); ColorTable getCPUColorTable(); +ColorTable getStreamColorTable(); + Color getColor(ColorTable *colors, int pid); /** Represents an abstract graphical element. */ |