Back to index

indicator-appmenu  12.10.0
Classes | Defines | Typedefs | Functions | Variables
hud-performance.c File Reference
#include "hudsettings.h"
#include "hudquery.h"
#include "hudtoken.h"
#include "hudsource.h"
#include <glib-object.h>
#include "word-list.h"

Go to the source code of this file.

Classes

struct  RandomSource

Defines

#define MAX_DEPTH   6
#define MAX_ITEMS   20
#define MAX_WORDS   4
#define MAX_LETTERS   20

Typedefs

typedef GObjectClass RandomSourceClass

Functions

static void random_source_iface_init (HudSourceInterface *iface)
 G_DEFINE_TYPE_WITH_CODE (RandomSource, random_source, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(HUD_TYPE_SOURCE, random_source_iface_init))
static void random_source_ignore_use (HudSource *source)
static gchar * make_word (GRand *rand, gchar *buffer)
static gchar * make_words (GRand *rand, gint n_words)
static HudStringList * random_source_make_name (GRand *rand, HudStringList *context)
static void random_source_populate_table (GRand *rand, GHashTable *items, HudStringList *context, gint depth)
static void random_source_finalize (GObject *object)
static void random_source_init (RandomSource *source)
static void random_source_class_init (RandomSourceClass *class)
static HudSource * random_source_new (GRand *rand)
void test_query_performance (void)
int main (int argc, char **argv)

Variables

HudSettings hud_settings
 SECTION:hudsettings : HudSettings : tunable parameters.

Class Documentation

struct RandomSource

Definition at line 53 of file hud-performance.c.

Class Members
GHashTable * items
GObject object

Define Documentation

#define MAX_DEPTH   6

Definition at line 29 of file hud-performance.c.

#define MAX_ITEMS   20

Definition at line 32 of file hud-performance.c.

#define MAX_LETTERS   20

Definition at line 40 of file hud-performance.c.

#define MAX_WORDS   4

Definition at line 37 of file hud-performance.c.


Typedef Documentation

typedef GObjectClass RandomSourceClass

Definition at line 60 of file hud-performance.c.


Function Documentation

G_DEFINE_TYPE_WITH_CODE ( RandomSource  ,
random_source  ,
G_TYPE_OBJECT  ,
G_IMPLEMENT_INTERFACE(HUD_TYPE_SOURCE, random_source_iface_init  
)

Definition at line 63 of file hud-performance.c.

{
  RandomSource *source = (RandomSource *) hud_source;
  GHashTableIter iter;
  gpointer item;

  g_hash_table_iter_init (&iter, source->items);
  while (g_hash_table_iter_next (&iter, &item, NULL))
    {
      HudResult *result;

      result = hud_result_get_if_matched (item, search_tokens, 0);
      if (result)
        g_ptr_array_add (results_array, result);
    }
}

Here is the call graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 270 of file hud-performance.c.

{
  g_type_init ();

  g_test_init (&argc, &argv, NULL);
  if (g_test_perf ())
    g_test_add_func ("/hud/query-performance", test_query_performance);

  return g_test_run ();
}

Here is the call graph for this function:

static gchar* make_word ( GRand *  rand,
gchar *  buffer 
) [static]

Definition at line 92 of file hud-performance.c.

{
  const gchar *word;
  gint choice;
  gint len;

  choice = g_rand_int_range (rand, 0, G_N_ELEMENTS (word_list));
  word = word_list[choice];

  while (*word)
    *buffer++ = *word++;

  return buffer;
}

Here is the caller graph for this function:

static gchar* make_words ( GRand *  rand,
gint  n_words 
) [static]

Definition at line 109 of file hud-performance.c.

{
  gchar *buffer;
  gchar *ptr;
  gint i;

  buffer = g_malloc ((MAX_LETTERS + 1) * n_words);

  ptr = buffer;
  for (i = 0; i < n_words; i++)
    {
      if (i)
        *ptr++ = ' ';

      ptr = make_word (rand, ptr);
    }

  *ptr = '\0';

  return buffer;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void random_source_class_init ( RandomSourceClass class) [static]

Definition at line 210 of file hud-performance.c.

{
  class->finalize = random_source_finalize;
}

Here is the call graph for this function:

static void random_source_finalize ( GObject *  object) [static]

Definition at line 185 of file hud-performance.c.

{
  RandomSource *source = (RandomSource *) object;

  g_hash_table_unref (source->items);

  G_OBJECT_CLASS (random_source_parent_class)
    ->finalize (object);
}

Here is the caller graph for this function:

static void random_source_iface_init ( HudSourceInterface *  iface) [static]

Definition at line 202 of file hud-performance.c.

{
  iface->use = random_source_ignore_use;
  iface->unuse = random_source_ignore_use;
  iface->search = random_source_search;
}

Here is the call graph for this function:

static void random_source_ignore_use ( HudSource *  source) [static]

Definition at line 87 of file hud-performance.c.

{
}

Here is the caller graph for this function:

static void random_source_init ( RandomSource source) [static]

Definition at line 196 of file hud-performance.c.

{
  source->items = g_hash_table_new_full (NULL, NULL, g_object_unref, NULL);
}
static HudStringList* random_source_make_name ( GRand *  rand,
HudStringList *  context 
) [static]

Definition at line 133 of file hud-performance.c.

{
  HudStringList *name;
  gchar *label;

  label = make_words (rand, g_rand_int_range (rand, 1, MAX_WORDS + 1));
  name = hud_string_list_cons (label, context);
  g_free (label);

  return name;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static HudSource* random_source_new ( GRand *  rand) [static]

Definition at line 216 of file hud-performance.c.

{
  RandomSource *source;

  source = g_object_new (random_source_get_type (), NULL);
  random_source_populate_table (rand, source->items, NULL, 0);

  return HUD_SOURCE (source);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void random_source_populate_table ( GRand *  rand,
GHashTable *  items,
HudStringList *  context,
gint  depth 
) [static]

Definition at line 147 of file hud-performance.c.

{
  gint n_items;
  gint i;

  n_items = g_rand_int_range (rand, 1, MAX_ITEMS + 1);

  for (i = 0; i < n_items; i++)
    {
      HudStringList *name;
      gboolean is_submenu;
      HudItem *item;

      name = random_source_make_name (rand, context);

      if (depth != MAX_DEPTH)
        /* Decrease the chances of a particular item being a submenu as we
         * go deeper into the menu structure.
         */
        is_submenu = g_rand_int_range (rand, 0, depth + 1) == 0;
      else
        /* At the maximum depth, prevent any items from being submenus. */
        is_submenu = FALSE;

      item = hud_item_new (name, NULL, NULL, !is_submenu);
      g_hash_table_add (items, item);

      if (is_submenu)
        random_source_populate_table (rand, items, name, depth + 1);

      hud_string_list_unref (name);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void test_query_performance ( void  )

Definition at line 227 of file hud-performance.c.

{
  HudSource *source;
  HudQuery *query;
  GRand *rand;
  gint i;

  rand = g_rand_new_with_seed (1234);
  source = random_source_new (rand);

  for (i = 1; i <= 6; i++)
    {
      guint64 start_time;
      gchar *search;
      gint j;

      g_print ("\n");

      search = make_words (rand, i);

      /* simulate the user typing it in, one character at a time */
      for (j = 1; search[j - 1]; j++)
        {
          gchar *part_search = g_strndup (search, j);

          start_time = g_get_monotonic_time ();
          query = hud_query_new (source, part_search, 1u<<30);
          g_print ("%-60s: %dus (%d hits)\n", part_search,
                   (int) (g_get_monotonic_time () - start_time),
                   hud_query_get_n_results (query));
          hud_query_close (query);
          g_object_unref (query);
          g_free (part_search);
        }

      g_free (search);
    }

  g_object_unref (source);
  g_rand_free (rand);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

HudSettings hud_settings
Initial value:
 {
  .indicator_penalty = 50,
  .add_penalty = 10,
  .drop_penalty = 10,
  .end_drop_penalty = 1,
  .swap_penalty = 15,
  .max_distance = 30
}

SECTION:hudsettings : HudSettings : tunable parameters.

HudSettings is a structure that contains the value of several

tunable parameters that affect the behaviour of various components of the HUD.

This structure exists for two reasons.

The first reason is that caching these values in local variables eliminates the need to look them up from #GSettings on each use. This vastly improves the performance of the matching algorithms (as many of these values are used quite a lot from within them).

The second reason is to improve testability. The testcases are able to hardcode sane values for the settings without worrying about changes that the user may have made to their local configuration (which could otherwise cause spurious test failures). HudSettings: : if usage tracking should be performed : the percentage by which to increase the distance of indicators when sorting the results list : the maximum distance value we consider as being a matching result : the penalty incurred by a character in the search term that does not exist in the item being matched : the penalty incurred by a character missing from the search string as compared to the item being matched : the penalty incurred by a character missing from the search string as compared to the item being matched when the character is at the end of the item (ie: the search term is a prefix of the item) : the penalty incurred for the substitution of one character for another

This structure contains the value of several tunable parameters that affect the behaviour of various components of the HUD. hud_settings:

The #HudSettings in effect.

hud_settings_init() can be used to keep these values in sync with

GSettings. For testing, it may make sense to set these values

directly.

Definition at line 44 of file hud-performance.c.