mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof: add API to categorize callgraph
This just gets the plumbing in place with some basic categorization for callgraph information. The real work of categorizing by nick/symbol still needs to be done (some can be copied from SysprofCategoryIcon). This also adds a property and getter for SysprofCallgraphFrame which will expose the node's category to the UI code.
This commit is contained in:
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include "sysprof-callgraph-private.h"
|
#include "sysprof-callgraph-private.h"
|
||||||
#include "sysprof-callgraph-frame-private.h"
|
#include "sysprof-callgraph-frame-private.h"
|
||||||
|
#include "sysprof-enums.h"
|
||||||
#include "sysprof-symbol-private.h"
|
#include "sysprof-symbol-private.h"
|
||||||
#include "sysprof-document-bitset-index-private.h"
|
#include "sysprof-document-bitset-index-private.h"
|
||||||
|
|
||||||
@ -43,6 +44,7 @@ struct _SysprofCallgraphFrame
|
|||||||
enum {
|
enum {
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_CALLGRAPH,
|
PROP_CALLGRAPH,
|
||||||
|
PROP_CATEGORY,
|
||||||
PROP_SYMBOL,
|
PROP_SYMBOL,
|
||||||
PROP_N_ITEMS,
|
PROP_N_ITEMS,
|
||||||
N_PROPS
|
N_PROPS
|
||||||
@ -123,6 +125,10 @@ sysprof_callgraph_frame_get_property (GObject *object,
|
|||||||
g_value_set_object (value, self->callgraph);
|
g_value_set_object (value, self->callgraph);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_CATEGORY:
|
||||||
|
g_value_set_enum (value, sysprof_callgraph_frame_get_category (self));
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_N_ITEMS:
|
case PROP_N_ITEMS:
|
||||||
g_value_set_uint (value, g_list_model_get_n_items (G_LIST_MODEL (self)));
|
g_value_set_uint (value, g_list_model_get_n_items (G_LIST_MODEL (self)));
|
||||||
break;
|
break;
|
||||||
@ -149,6 +155,12 @@ sysprof_callgraph_frame_class_init (SysprofCallgraphFrameClass *klass)
|
|||||||
SYSPROF_TYPE_CALLGRAPH,
|
SYSPROF_TYPE_CALLGRAPH,
|
||||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
|
properties [PROP_CATEGORY] =
|
||||||
|
g_param_spec_enum ("category", NULL, NULL,
|
||||||
|
SYSPROF_TYPE_CALLGRAPH_CATEGORY,
|
||||||
|
SYSPROF_CALLGRAPH_CATEGORY_UNCATEGORIZED,
|
||||||
|
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
properties [PROP_N_ITEMS] =
|
properties [PROP_N_ITEMS] =
|
||||||
g_param_spec_uint ("n-items", NULL, NULL,
|
g_param_spec_uint ("n-items", NULL, NULL,
|
||||||
0, G_MAXUINT, 0,
|
0, G_MAXUINT, 0,
|
||||||
@ -475,3 +487,23 @@ sysprof_callgraph_frame_is_leaf (SysprofCallgraphFrame *self)
|
|||||||
|
|
||||||
return self->n_children == 0;
|
return self->n_children == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sysprof_callgraph_frame_get_category:
|
||||||
|
* @self: a #SysprofCallgraphFrame
|
||||||
|
*
|
||||||
|
* Gets the category of the node if %SYSPROF_CALLGRAPH_FLAGS_CATEGORIZE_FRAMES
|
||||||
|
* was set when generating the callgraph. Otherwise 0.
|
||||||
|
*
|
||||||
|
* Returns: 0 or a callgraph category
|
||||||
|
*/
|
||||||
|
SysprofCallgraphCategory
|
||||||
|
sysprof_callgraph_frame_get_category (SysprofCallgraphFrame *self)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (SYSPROF_IS_CALLGRAPH_FRAME (self), 0);
|
||||||
|
|
||||||
|
if (self->callgraph == NULL || self->node == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return self->node->category;
|
||||||
|
}
|
||||||
|
|||||||
@ -39,12 +39,13 @@ typedef struct _SysprofCallgraphSummary
|
|||||||
|
|
||||||
struct _SysprofCallgraphNode
|
struct _SysprofCallgraphNode
|
||||||
{
|
{
|
||||||
SysprofCallgraphNode *parent;
|
SysprofCallgraphNode *parent;
|
||||||
SysprofCallgraphNode *prev;
|
SysprofCallgraphNode *prev;
|
||||||
SysprofCallgraphNode *next;
|
SysprofCallgraphNode *next;
|
||||||
SysprofCallgraphNode *children;
|
SysprofCallgraphNode *children;
|
||||||
SysprofCallgraphSummary *summary;
|
SysprofCallgraphSummary *summary;
|
||||||
gpointer augment[2];
|
gpointer augment[2];
|
||||||
|
SysprofCallgraphCategory category;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _SysprofCallgraph
|
struct _SysprofCallgraph
|
||||||
|
|||||||
@ -283,6 +283,52 @@ reverse_symbols (SysprofSymbol **symbols,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sysprof_callgraph_categorize (SysprofCallgraph *self,
|
||||||
|
SysprofCallgraphNode *node)
|
||||||
|
{
|
||||||
|
SysprofSymbol *symbol = node->summary->symbol;
|
||||||
|
|
||||||
|
if (node->category)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (node->parent && node->parent->category == 0)
|
||||||
|
sysprof_callgraph_categorize (self, node->parent);
|
||||||
|
|
||||||
|
switch (symbol->kind)
|
||||||
|
{
|
||||||
|
case SYSPROF_SYMBOL_KIND_ROOT:
|
||||||
|
case SYSPROF_SYMBOL_KIND_THREAD:
|
||||||
|
case SYSPROF_SYMBOL_KIND_PROCESS:
|
||||||
|
node->category = SYSPROF_CALLGRAPH_CATEGORY_PRESENTATION;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SYSPROF_SYMBOL_KIND_CONTEXT_SWITCH:
|
||||||
|
node->category = SYSPROF_CALLGRAPH_CATEGORY_CONTEXT_SWITCH;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SYSPROF_SYMBOL_KIND_KERNEL:
|
||||||
|
node->category = SYSPROF_CALLGRAPH_CATEGORY_KERNEL;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SYSPROF_SYMBOL_KIND_UNWINDABLE:
|
||||||
|
node->category = SYSPROF_CALLGRAPH_CATEGORY_UNWINDABLE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SYSPROF_SYMBOL_KIND_USER:
|
||||||
|
|
||||||
|
G_GNUC_FALLTHROUGH;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if (node->parent)
|
||||||
|
node->category = node->parent->category;
|
||||||
|
else
|
||||||
|
node->category = SYSPROF_CALLGRAPH_CATEGORY_UNCATEGORIZED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sysprof_callgraph_add_traceable (SysprofCallgraph *self,
|
sysprof_callgraph_add_traceable (SysprofCallgraph *self,
|
||||||
SysprofDocumentTraceable *traceable,
|
SysprofDocumentTraceable *traceable,
|
||||||
@ -370,6 +416,9 @@ sysprof_callgraph_add_traceable (SysprofCallgraph *self,
|
|||||||
SYSPROF_DOCUMENT_FRAME (traceable),
|
SYSPROF_DOCUMENT_FRAME (traceable),
|
||||||
TRUE,
|
TRUE,
|
||||||
self->augment_func_data);
|
self->augment_func_data);
|
||||||
|
|
||||||
|
if ((self->flags & SYSPROF_CALLGRAPH_FLAGS_CATEGORIZE_FRAMES) != 0)
|
||||||
|
sysprof_callgraph_categorize (self, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
@ -62,46 +62,68 @@ typedef void (*SysprofAugmentationFunc) (SysprofCallgraph *callgraph,
|
|||||||
gboolean summarize,
|
gboolean summarize,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
|
typedef enum _SysprofCallgraphCategory
|
||||||
|
{
|
||||||
|
SYSPROF_CALLGRAPH_CATEGORY_UNCATEGORIZED = 1,
|
||||||
|
SYSPROF_CALLGRAPH_CATEGORY_A11Y,
|
||||||
|
SYSPROF_CALLGRAPH_CATEGORY_ACTIONS,
|
||||||
|
SYSPROF_CALLGRAPH_CATEGORY_CONSTRUCTORS,
|
||||||
|
SYSPROF_CALLGRAPH_CATEGORY_CONTEXT_SWITCH,
|
||||||
|
SYSPROF_CALLGRAPH_CATEGORY_INPUT,
|
||||||
|
SYSPROF_CALLGRAPH_CATEGORY_KERNEL,
|
||||||
|
SYSPROF_CALLGRAPH_CATEGORY_LAYOUT,
|
||||||
|
SYSPROF_CALLGRAPH_CATEGORY_MAIN_LOOP,
|
||||||
|
SYSPROF_CALLGRAPH_CATEGORY_PAINT,
|
||||||
|
SYSPROF_CALLGRAPH_CATEGORY_PRESENTATION,
|
||||||
|
SYSPROF_CALLGRAPH_CATEGORY_SIGNALS,
|
||||||
|
SYSPROF_CALLGRAPH_CATEGORY_TEMPLATES,
|
||||||
|
SYSPROF_CALLGRAPH_CATEGORY_UNWINDABLE,
|
||||||
|
SYSPROF_CALLGRAPH_CATEGORY_WINDOWING,
|
||||||
|
} SysprofCallgraphCategory;
|
||||||
|
|
||||||
typedef enum _SysprofCallgraphFlags
|
typedef enum _SysprofCallgraphFlags
|
||||||
{
|
{
|
||||||
SYSPROF_CALLGRAPH_FLAGS_NONE = 0,
|
SYSPROF_CALLGRAPH_FLAGS_NONE = 0,
|
||||||
SYSPROF_CALLGRAPH_FLAGS_INCLUDE_THREADS = 1 << 1,
|
SYSPROF_CALLGRAPH_FLAGS_INCLUDE_THREADS = 1 << 1,
|
||||||
SYSPROF_CALLGRAPH_FLAGS_HIDE_SYSTEM_LIBRARIES = 1 << 2,
|
SYSPROF_CALLGRAPH_FLAGS_HIDE_SYSTEM_LIBRARIES = 1 << 2,
|
||||||
SYSPROF_CALLGRAPH_FLAGS_BOTTOM_UP = 1 << 3,
|
SYSPROF_CALLGRAPH_FLAGS_BOTTOM_UP = 1 << 3,
|
||||||
|
SYSPROF_CALLGRAPH_FLAGS_CATEGORIZE_FRAMES = 1 << 4,
|
||||||
} SysprofCallgraphFlags;
|
} SysprofCallgraphFlags;
|
||||||
|
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
GListModel *sysprof_callgraph_list_symbols (SysprofCallgraph *self);
|
GListModel *sysprof_callgraph_list_symbols (SysprofCallgraph *self);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
GListModel *sysprof_callgraph_list_callers (SysprofCallgraph *self,
|
GListModel *sysprof_callgraph_list_callers (SysprofCallgraph *self,
|
||||||
SysprofSymbol *symbol);
|
SysprofSymbol *symbol);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
GListModel *sysprof_callgraph_list_traceables_for_symbol (SysprofCallgraph *self,
|
GListModel *sysprof_callgraph_list_traceables_for_symbol (SysprofCallgraph *self,
|
||||||
SysprofSymbol *symbol);
|
SysprofSymbol *symbol);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
GListModel *sysprof_callgraph_list_traceables_for_symbols_matching (SysprofCallgraph *self,
|
GListModel *sysprof_callgraph_list_traceables_for_symbols_matching (SysprofCallgraph *self,
|
||||||
const char *pattern);
|
const char *pattern);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
void sysprof_callgraph_descendants_async (SysprofCallgraph *self,
|
void sysprof_callgraph_descendants_async (SysprofCallgraph *self,
|
||||||
SysprofSymbol *symbol,
|
SysprofSymbol *symbol,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
GListModel *sysprof_callgraph_descendants_finish (SysprofCallgraph *self,
|
GListModel *sysprof_callgraph_descendants_finish (SysprofCallgraph *self,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
GError **error);
|
GError **error);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
gpointer sysprof_callgraph_get_augment (SysprofCallgraph *self,
|
gpointer sysprof_callgraph_get_augment (SysprofCallgraph *self,
|
||||||
SysprofCallgraphNode *node);
|
SysprofCallgraphNode *node);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
gpointer sysprof_callgraph_get_summary_augment (SysprofCallgraph *self,
|
gpointer sysprof_callgraph_get_summary_augment (SysprofCallgraph *self,
|
||||||
SysprofCallgraphNode *node);
|
SysprofCallgraphNode *node);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
SysprofCallgraphNode *sysprof_callgraph_node_parent (SysprofCallgraphNode *node);
|
SysprofCallgraphNode *sysprof_callgraph_node_parent (SysprofCallgraphNode *node);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
SysprofCallgraph *sysprof_callgraph_frame_get_callgraph (SysprofCallgraphFrame *self);
|
SysprofCallgraph *sysprof_callgraph_frame_get_callgraph (SysprofCallgraphFrame *self);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
SysprofCallgraph *sysprof_callgraph_symbol_get_callgraph (SysprofCallgraphSymbol *self);
|
SysprofCallgraphCategory sysprof_callgraph_frame_get_category (SysprofCallgraphFrame *self);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
SysprofCallgraph *sysprof_callgraph_symbol_get_callgraph (SysprofCallgraphSymbol *self);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|||||||
Reference in New Issue
Block a user