HawkTracer  0.9.0
memory_usage.h File Reference
#include <hawktracer/base_types.h>
#include <hawktracer/ht_config.h>

Go to the source code of this file.

Macros

#define HT_MEMORY_USAGE_INVALID_VALUE   ((size_t)-1)
 Defines an invalid value for memory which is returned when getting a memory usage fails. More...
 

Typedefs

typedef struct _HT_MemoryUsageContext HT_MemoryUsageContext
 A forward declaration for memory usage context. More...
 

Functions

HT_API HT_MemoryUsageContextht_memory_usage_context_create (void *process_id)
 Creates a context for a memory usage feature. More...
 
HT_API void ht_memory_usage_context_destroy (HT_MemoryUsageContext *context)
 Destroys memory context. More...
 
HT_API HT_ErrorCode ht_memory_usage_get_usage (HT_MemoryUsageContext *context, size_t *virtual_memory_bytes, size_t *shared_memory_bytes, size_t *resident_memory_bytes)
 Gets a memory usage of the process in kilobytes. More...
 

Macro Definition Documentation

◆ HT_MEMORY_USAGE_INVALID_VALUE

#define HT_MEMORY_USAGE_INVALID_VALUE   ((size_t)-1)

Defines an invalid value for memory which is returned when getting a memory usage fails.

Typedef Documentation

◆ HT_MemoryUsageContext

typedef struct _HT_MemoryUsageContext HT_MemoryUsageContext

A forward declaration for memory usage context.

This structure should be defined in the implementation file.

Function Documentation

◆ ht_memory_usage_context_create()

HT_API HT_MemoryUsageContext* ht_memory_usage_context_create ( void *  process_id)

Creates a context for a memory usage feature.

This context is used for getting memory usage, and the structure is platform specific. The context should always be destroyed using ht_memory_usage_context_destroy().

Parameters
process_ida platform specific description of process ID, or NULL to get memory usage of the current process. For linux-based platforms, it should be a pointer to a variable of type integer (int), which holds the process ID.
Returns
the memory usage context or NULL if the function failed to create a context.

◆ ht_memory_usage_context_destroy()

HT_API void ht_memory_usage_context_destroy ( HT_MemoryUsageContext context)

Destroys memory context.

Parameters
contexta pointer to the context.

◆ ht_memory_usage_get_usage()

HT_API HT_ErrorCode ht_memory_usage_get_usage ( HT_MemoryUsageContext context,
size_t *  virtual_memory_bytes,
size_t *  shared_memory_bytes,
size_t *  resident_memory_bytes 
)

Gets a memory usage of the process in kilobytes.

The process ID should be specified in ht_memory_usage_context_create().

Parameters
contexta memory usage context.
Returns
a memory usage of a specified process in kilobytes, or HT_MEMORY_USAGE_INVALID_VALUE value on error. Gets a memory usage of the process in bytes.
Parameters
contexta memory usage context.
virtual_memory_bytesa pointer to a variable where virtual memory used by the process will be stored, or NULL if the value should not be read.
shared_memory_bytesa pointer to a variable where shared memory used by the process will be stored, or NULL if the value should not be read.
resident_memory_bytesa pointer to a variable where resident memory used by the process will be stored, or NULL if the value should not be read.
Returns
HT_ERR_OK, if memory has been read succesfully; otherwise, appropriate error code.