1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
// C
#ifndef _GNU_SOURCE
/** Use GNU C Library. */
#define _GNU_SOURCE
#endif // _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
// KernelShark
#include "libkshark.h"
#include "libkshark-plugin.h"
static ssize_t load_entries(struct kshark_data_stream *stream,
__attribute__ ((unused)) struct kshark_context *kshark_ctx,
struct kshark_entry ***data_rows)
{
struct kshark_entry **rows;
ssize_t total = 100, i;
rows = calloc(total, sizeof(struct kshark_entry *));
for (i = 0; i < total; ++i) {
rows[i] = calloc(1, sizeof(struct kshark_entry));
rows[i]->ts = 1000 + i * 15000;
rows[i]->stream_id = stream->stream_id;
rows[i]->event_id = i % 3;
rows[i]->pid = 20;
rows[i]->visible = 0xff;
}
rows[i-1]->pid = 0;
*data_rows = rows;
return total;
}
static char *dump_entry(__attribute__ ((unused)) struct kshark_data_stream *stream,
const struct kshark_entry *entry)
{
char *entry_str;
int ret;
ret = asprintf(&entry_str, "e: time=%li evt=%i s_id=%i", entry->ts,
entry->event_id,
entry->stream_id);
if (ret <= 0)
return NULL;
return entry_str;
}
static const char *format_name = "format_b";
// static const char *format_name = "tep data";
const char *KSHARK_INPUT_FORMAT()
{
return format_name;
}
bool KSHARK_INPUT_CHECK(const char *file, __attribute__ ((unused)) char **format)
{
char *ext = strrchr(file, '.');
if (ext && strcmp(ext, ".tb") == 0)
return true;
return false;
}
static int get_pid(__attribute__ ((unused)) struct kshark_data_stream *stream,
const struct kshark_entry *entry)
{
return entry->pid;
}
static char *get_task(__attribute__ ((unused)) struct kshark_data_stream *stream,
__attribute__ ((unused)) const struct kshark_entry *entry)
{
char *entry_str;
int ret;
ret = asprintf(&entry_str, "test_b/test");
if (ret <= 0)
return NULL;
return entry_str;
}
static char *get_event_name(__attribute__ ((unused)) struct kshark_data_stream *stream,
const struct kshark_entry *entry)
{
char *evt_str;
int ret;
ret = asprintf(&evt_str, "test_b/event-%i", entry->event_id);
if (ret <= 0)
return NULL;
return evt_str;
}
int KSHARK_INPUT_INITIALIZER(struct kshark_data_stream *stream)
{
struct kshark_generic_stream_interface *interface;
stream->interface = interface = calloc(1, sizeof(*interface));
if (!interface)
return -ENOMEM;
interface->type = KS_GENERIC_DATA_INTERFACE;
stream->n_cpus = 1;
stream->n_events = 3;
stream->idle_pid = 0;
kshark_hash_id_add(stream->tasks, 20);
interface->get_pid = get_pid;
interface->get_task = get_task;
interface->get_event_name = get_event_name;
interface->dump_entry = dump_entry;
interface->load_entries = load_entries;
return 0;
}
void KSHARK_INPUT_DEINITIALIZER(__attribute__ ((unused)) struct kshark_data_stream *stream)
{}
/** Initialize the control interface of the plugin. */
void *KSHARK_MENU_PLUGIN_INITIALIZER(__attribute__ ((unused)) void *ptr)
{
return NULL;
}
|