forked from Minki/linux
kmemtrace: small cleanups
Cc: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro> LKML-Reference: <161be9ca8a27b432c4a6ab79f47788c4521652ae.1237813499.git.eduard.munteanu@linux360.ro> Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
parent
42af9054c0
commit
c826e3cd0c
@ -6,15 +6,16 @@
|
|||||||
* Copyright (C) 2008 Frederic Weisbecker <fweisbec@gmail.com>
|
* Copyright (C) 2008 Frederic Weisbecker <fweisbec@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/dcache.h>
|
|
||||||
#include <linux/debugfs.h>
|
|
||||||
#include <linux/fs.h>
|
|
||||||
#include <linux/seq_file.h>
|
|
||||||
#include <linux/tracepoint.h>
|
#include <linux/tracepoint.h>
|
||||||
|
#include <linux/seq_file.h>
|
||||||
|
#include <linux/debugfs.h>
|
||||||
|
#include <linux/dcache.h>
|
||||||
|
#include <linux/fs.h>
|
||||||
|
|
||||||
#include <trace/kmemtrace.h>
|
#include <trace/kmemtrace.h>
|
||||||
|
|
||||||
#include "trace.h"
|
|
||||||
#include "trace_output.h"
|
#include "trace_output.h"
|
||||||
|
#include "trace.h"
|
||||||
|
|
||||||
/* Select an alternative, minimalistic output than the original one */
|
/* Select an alternative, minimalistic output than the original one */
|
||||||
#define TRACE_KMEM_OPT_MINIMAL 0x1
|
#define TRACE_KMEM_OPT_MINIMAL 0x1
|
||||||
@ -26,8 +27,8 @@ static struct tracer_opt kmem_opts[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static struct tracer_flags kmem_tracer_flags = {
|
static struct tracer_flags kmem_tracer_flags = {
|
||||||
.val = 0,
|
.val = 0,
|
||||||
.opts = kmem_opts
|
.opts = kmem_opts
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct trace_array *kmemtrace_array;
|
static struct trace_array *kmemtrace_array;
|
||||||
@ -41,24 +42,25 @@ static inline void kmemtrace_alloc(enum kmemtrace_type_id type_id,
|
|||||||
gfp_t gfp_flags,
|
gfp_t gfp_flags,
|
||||||
int node)
|
int node)
|
||||||
{
|
{
|
||||||
struct ring_buffer_event *event;
|
|
||||||
struct kmemtrace_alloc_entry *entry;
|
|
||||||
struct trace_array *tr = kmemtrace_array;
|
struct trace_array *tr = kmemtrace_array;
|
||||||
|
struct kmemtrace_alloc_entry *entry;
|
||||||
|
struct ring_buffer_event *event;
|
||||||
|
|
||||||
event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry));
|
event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry));
|
||||||
if (!event)
|
if (!event)
|
||||||
return;
|
return;
|
||||||
entry = ring_buffer_event_data(event);
|
|
||||||
|
entry = ring_buffer_event_data(event);
|
||||||
tracing_generic_entry_update(&entry->ent, 0, 0);
|
tracing_generic_entry_update(&entry->ent, 0, 0);
|
||||||
|
|
||||||
entry->ent.type = TRACE_KMEM_ALLOC;
|
entry->ent.type = TRACE_KMEM_ALLOC;
|
||||||
entry->type_id = type_id;
|
entry->type_id = type_id;
|
||||||
entry->call_site = call_site;
|
entry->call_site = call_site;
|
||||||
entry->ptr = ptr;
|
entry->ptr = ptr;
|
||||||
entry->bytes_req = bytes_req;
|
entry->bytes_req = bytes_req;
|
||||||
entry->bytes_alloc = bytes_alloc;
|
entry->bytes_alloc = bytes_alloc;
|
||||||
entry->gfp_flags = gfp_flags;
|
entry->gfp_flags = gfp_flags;
|
||||||
entry->node = node;
|
entry->node = node;
|
||||||
|
|
||||||
ring_buffer_unlock_commit(tr->buffer, event);
|
ring_buffer_unlock_commit(tr->buffer, event);
|
||||||
|
|
||||||
@ -69,9 +71,9 @@ static inline void kmemtrace_free(enum kmemtrace_type_id type_id,
|
|||||||
unsigned long call_site,
|
unsigned long call_site,
|
||||||
const void *ptr)
|
const void *ptr)
|
||||||
{
|
{
|
||||||
struct ring_buffer_event *event;
|
|
||||||
struct kmemtrace_free_entry *entry;
|
|
||||||
struct trace_array *tr = kmemtrace_array;
|
struct trace_array *tr = kmemtrace_array;
|
||||||
|
struct kmemtrace_free_entry *entry;
|
||||||
|
struct ring_buffer_event *event;
|
||||||
|
|
||||||
event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry));
|
event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry));
|
||||||
if (!event)
|
if (!event)
|
||||||
@ -79,10 +81,10 @@ static inline void kmemtrace_free(enum kmemtrace_type_id type_id,
|
|||||||
entry = ring_buffer_event_data(event);
|
entry = ring_buffer_event_data(event);
|
||||||
tracing_generic_entry_update(&entry->ent, 0, 0);
|
tracing_generic_entry_update(&entry->ent, 0, 0);
|
||||||
|
|
||||||
entry->ent.type = TRACE_KMEM_FREE;
|
entry->ent.type = TRACE_KMEM_FREE;
|
||||||
entry->type_id = type_id;
|
entry->type_id = type_id;
|
||||||
entry->call_site = call_site;
|
entry->call_site = call_site;
|
||||||
entry->ptr = ptr;
|
entry->ptr = ptr;
|
||||||
|
|
||||||
ring_buffer_unlock_commit(tr->buffer, event);
|
ring_buffer_unlock_commit(tr->buffer, event);
|
||||||
|
|
||||||
@ -216,48 +218,50 @@ static void kmemtrace_headers(struct seq_file *s)
|
|||||||
#define KMEMTRACE_USER_FREE 1
|
#define KMEMTRACE_USER_FREE 1
|
||||||
|
|
||||||
struct kmemtrace_user_event {
|
struct kmemtrace_user_event {
|
||||||
u8 event_id;
|
u8 event_id;
|
||||||
u8 type_id;
|
u8 type_id;
|
||||||
u16 event_size;
|
u16 event_size;
|
||||||
u32 cpu;
|
u32 cpu;
|
||||||
u64 timestamp;
|
u64 timestamp;
|
||||||
unsigned long call_site;
|
unsigned long call_site;
|
||||||
unsigned long ptr;
|
unsigned long ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct kmemtrace_user_event_alloc {
|
struct kmemtrace_user_event_alloc {
|
||||||
size_t bytes_req;
|
size_t bytes_req;
|
||||||
size_t bytes_alloc;
|
size_t bytes_alloc;
|
||||||
unsigned gfp_flags;
|
unsigned gfp_flags;
|
||||||
int node;
|
int node;
|
||||||
};
|
};
|
||||||
|
|
||||||
static enum print_line_t
|
static enum print_line_t
|
||||||
kmemtrace_print_alloc_user(struct trace_iterator *iter,
|
kmemtrace_print_alloc_user(struct trace_iterator *iter,
|
||||||
struct kmemtrace_alloc_entry *entry)
|
struct kmemtrace_alloc_entry *entry)
|
||||||
{
|
{
|
||||||
|
struct kmemtrace_user_event_alloc *ev_alloc;
|
||||||
struct trace_seq *s = &iter->seq;
|
struct trace_seq *s = &iter->seq;
|
||||||
struct kmemtrace_user_event *ev;
|
struct kmemtrace_user_event *ev;
|
||||||
struct kmemtrace_user_event_alloc *ev_alloc;
|
|
||||||
|
|
||||||
ev = trace_seq_reserve(s, sizeof(*ev));
|
ev = trace_seq_reserve(s, sizeof(*ev));
|
||||||
if (!ev)
|
if (!ev)
|
||||||
return TRACE_TYPE_PARTIAL_LINE;
|
return TRACE_TYPE_PARTIAL_LINE;
|
||||||
ev->event_id = KMEMTRACE_USER_ALLOC;
|
|
||||||
ev->type_id = entry->type_id;
|
ev->event_id = KMEMTRACE_USER_ALLOC;
|
||||||
ev->event_size = sizeof(*ev) + sizeof(*ev_alloc);
|
ev->type_id = entry->type_id;
|
||||||
ev->cpu = iter->cpu;
|
ev->event_size = sizeof(*ev) + sizeof(*ev_alloc);
|
||||||
ev->timestamp = iter->ts;
|
ev->cpu = iter->cpu;
|
||||||
ev->call_site = entry->call_site;
|
ev->timestamp = iter->ts;
|
||||||
ev->ptr = (unsigned long) entry->ptr;
|
ev->call_site = entry->call_site;
|
||||||
|
ev->ptr = (unsigned long)entry->ptr;
|
||||||
|
|
||||||
ev_alloc = trace_seq_reserve(s, sizeof(*ev_alloc));
|
ev_alloc = trace_seq_reserve(s, sizeof(*ev_alloc));
|
||||||
if (!ev_alloc)
|
if (!ev_alloc)
|
||||||
return TRACE_TYPE_PARTIAL_LINE;
|
return TRACE_TYPE_PARTIAL_LINE;
|
||||||
ev_alloc->bytes_req = entry->bytes_req;
|
|
||||||
ev_alloc->bytes_alloc = entry->bytes_alloc;
|
ev_alloc->bytes_req = entry->bytes_req;
|
||||||
ev_alloc->gfp_flags = entry->gfp_flags;
|
ev_alloc->bytes_alloc = entry->bytes_alloc;
|
||||||
ev_alloc->node = entry->node;
|
ev_alloc->gfp_flags = entry->gfp_flags;
|
||||||
|
ev_alloc->node = entry->node;
|
||||||
|
|
||||||
return TRACE_TYPE_HANDLED;
|
return TRACE_TYPE_HANDLED;
|
||||||
}
|
}
|
||||||
@ -272,13 +276,14 @@ kmemtrace_print_free_user(struct trace_iterator *iter,
|
|||||||
ev = trace_seq_reserve(s, sizeof(*ev));
|
ev = trace_seq_reserve(s, sizeof(*ev));
|
||||||
if (!ev)
|
if (!ev)
|
||||||
return TRACE_TYPE_PARTIAL_LINE;
|
return TRACE_TYPE_PARTIAL_LINE;
|
||||||
ev->event_id = KMEMTRACE_USER_FREE;
|
|
||||||
ev->type_id = entry->type_id;
|
ev->event_id = KMEMTRACE_USER_FREE;
|
||||||
ev->event_size = sizeof(*ev);
|
ev->type_id = entry->type_id;
|
||||||
ev->cpu = iter->cpu;
|
ev->event_size = sizeof(*ev);
|
||||||
ev->timestamp = iter->ts;
|
ev->cpu = iter->cpu;
|
||||||
ev->call_site = entry->call_site;
|
ev->timestamp = iter->ts;
|
||||||
ev->ptr = (unsigned long) entry->ptr;
|
ev->call_site = entry->call_site;
|
||||||
|
ev->ptr = (unsigned long)entry->ptr;
|
||||||
|
|
||||||
return TRACE_TYPE_HANDLED;
|
return TRACE_TYPE_HANDLED;
|
||||||
}
|
}
|
||||||
@ -354,7 +359,7 @@ kmemtrace_print_alloc_compress(struct trace_iterator *iter,
|
|||||||
|
|
||||||
static enum print_line_t
|
static enum print_line_t
|
||||||
kmemtrace_print_free_compress(struct trace_iterator *iter,
|
kmemtrace_print_free_compress(struct trace_iterator *iter,
|
||||||
struct kmemtrace_free_entry *entry)
|
struct kmemtrace_free_entry *entry)
|
||||||
{
|
{
|
||||||
struct trace_seq *s = &iter->seq;
|
struct trace_seq *s = &iter->seq;
|
||||||
int ret;
|
int ret;
|
||||||
@ -415,6 +420,7 @@ static enum print_line_t kmemtrace_print_line(struct trace_iterator *iter)
|
|||||||
switch (entry->type) {
|
switch (entry->type) {
|
||||||
case TRACE_KMEM_ALLOC: {
|
case TRACE_KMEM_ALLOC: {
|
||||||
struct kmemtrace_alloc_entry *field;
|
struct kmemtrace_alloc_entry *field;
|
||||||
|
|
||||||
trace_assign_type(field, entry);
|
trace_assign_type(field, entry);
|
||||||
if (kmem_tracer_flags.val & TRACE_KMEM_OPT_MINIMAL)
|
if (kmem_tracer_flags.val & TRACE_KMEM_OPT_MINIMAL)
|
||||||
return kmemtrace_print_alloc_compress(iter, field);
|
return kmemtrace_print_alloc_compress(iter, field);
|
||||||
@ -424,6 +430,7 @@ static enum print_line_t kmemtrace_print_line(struct trace_iterator *iter)
|
|||||||
|
|
||||||
case TRACE_KMEM_FREE: {
|
case TRACE_KMEM_FREE: {
|
||||||
struct kmemtrace_free_entry *field;
|
struct kmemtrace_free_entry *field;
|
||||||
|
|
||||||
trace_assign_type(field, entry);
|
trace_assign_type(field, entry);
|
||||||
if (kmem_tracer_flags.val & TRACE_KMEM_OPT_MINIMAL)
|
if (kmem_tracer_flags.val & TRACE_KMEM_OPT_MINIMAL)
|
||||||
return kmemtrace_print_free_compress(iter, field);
|
return kmemtrace_print_free_compress(iter, field);
|
||||||
@ -437,12 +444,12 @@ static enum print_line_t kmemtrace_print_line(struct trace_iterator *iter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct tracer kmem_tracer __read_mostly = {
|
static struct tracer kmem_tracer __read_mostly = {
|
||||||
.name = "kmemtrace",
|
.name = "kmemtrace",
|
||||||
.init = kmem_trace_init,
|
.init = kmem_trace_init,
|
||||||
.reset = kmem_trace_reset,
|
.reset = kmem_trace_reset,
|
||||||
.print_line = kmemtrace_print_line,
|
.print_line = kmemtrace_print_line,
|
||||||
.print_header = kmemtrace_headers,
|
.print_header = kmemtrace_headers,
|
||||||
.flags = &kmem_tracer_flags
|
.flags = &kmem_tracer_flags
|
||||||
};
|
};
|
||||||
|
|
||||||
void kmemtrace_init(void)
|
void kmemtrace_init(void)
|
||||||
@ -454,5 +461,4 @@ static int __init init_kmem_tracer(void)
|
|||||||
{
|
{
|
||||||
return register_tracer(&kmem_tracer);
|
return register_tracer(&kmem_tracer);
|
||||||
}
|
}
|
||||||
|
|
||||||
device_initcall(init_kmem_tracer);
|
device_initcall(init_kmem_tracer);
|
||||||
|
Loading…
Reference in New Issue
Block a user