Re: [PATCH 05/15] kernel-shark: Introduce libkshark-hash

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 29 Sep 2020 16:41:13 +0300
"Yordan Karadzhov (VMware)" <y.karadz@xxxxxxxxx> wrote:

> +/**
> + * Create new hash table of Ids.
> + */
> +struct kshark_hash_id *kshark_hash_id_alloc(size_t n_bits)
> +{
> +	struct kshark_hash_id *hash;
> +	size_t size;
> +
> +	hash = calloc(1, sizeof(*hash));
> +	assert(hash);

For failed memory, is the general plan to just crash? (assert) or return
NULL?

> +
> +	hash->n_bits = n_bits;
> +	hash->count = 0;
> +
> +	size = hash_size(hash);
> +	hash->hash = calloc(size, sizeof(*hash->hash));

In either case, this needs to be checked too.

> +
> +	return hash;
> +}
> +
> +/** Free the hash table of Ids. */
> +void kshark_hash_id_free(struct kshark_hash_id *hash)
> +{
> +	if (!hash)
> +		return;
> +
> +	kshark_hash_id_clear(hash);
> +	free(hash->hash);
> +	free(hash);
> +}
> +

> diff --git a/src/libkshark.h b/src/libkshark.h
> index 9eecc2d..57bd5e5 100644
> --- a/src/libkshark.h
> +++ b/src/libkshark.h
> @@ -33,6 +33,7 @@ extern "C" {
>  // KernelShark
>  #include "libkshark-plugin.h"
>  
> +

Extra white space.

>  /**
>   * Kernel Shark entry contains all information from one trace record needed
>   * in order to  visualize the time-series of trace records. The part of the
> @@ -72,6 +73,52 @@ struct kshark_entry {
>  	int64_t		ts;
>  };
>  
> +/** Size of the task'c hash table in terms of bits being used by the key. */

 "task'c" ?

-- Steve


> +#define KS_TASK_HASH_NBITS	16
> +
> +/** Size of the hash table of Ids in terms of bits being used by the key. */
> +#define KS_FILTER_HASH_NBITS	8
> +
> +/** A bucket for the hash table of integer Id numbers (kshark_hash_id). */
> +struct kshark_hash_id_item {
> +	/** Pointer to the Id in this bucket. */
> +	struct kshark_hash_id_item	*next;
> +
> +	/** The Id value. */
> +	int				id;
> +};
> +
> +/**
> + * Hash table of integer Id numbers. To be used for fast filter of trace
> + * entries.
> + */
> +struct kshark_hash_id {
> +	/** Array of buckets. */
> +	struct kshark_hash_id_item	**hash;
> +
> +	/** The number of Ids in the table. */
> +	size_t	count;
> +
> +	/**
> +	 * The number of bits used by the hashing function.
> +	 * Note that the number of buckets in the table if given by
> +	 * 1 << n_bits.
> +	 */
> +	size_t	n_bits;
> +};



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux