Avoid doing a strcmp for each field at each event.
Signed-off-by: Julien Desfossez <julien.desfossez@efficios.com>
struct perfcounter *get_perf_counter(const char *name, struct processtop *proc,
struct cputime *cpu)
{
struct perfcounter *get_perf_counter(const char *name, struct processtop *proc,
struct cputime *cpu)
{
- struct perfcounter *ret, *global;
+ struct perfcounter *ret;
GHashTable *table;
if (proc)
GHashTable *table;
if (proc)
ret->visible = 1;
g_hash_table_insert(table, (gpointer) strdup(name), ret);
ret->visible = 1;
g_hash_table_insert(table, (gpointer) strdup(name), ret);
- global = g_hash_table_lookup(global_perf_liszt, (gpointer) name);
- if (!global) {
- global = g_new0(struct perfcounter, 1);
- memcpy(global, ret, sizeof(struct perfcounter));
- /* by default, sort on the first perf context */
- if (g_hash_table_size(global_perf_liszt) == 0)
- global->sort = 1;
- g_hash_table_insert(global_perf_liszt, (gpointer) strdup(name), global);
- }
-
struct cputime *cpu)
{
struct definition const * const *list = NULL;
struct cputime *cpu)
{
struct definition const * const *list = NULL;
+ const struct definition *field;
+ struct perfcounter *perfcounter;
+ GHashTableIter iter;
+ gpointer key;
+ int ret;
- for (i = 0; i < count; i++) {
- const char *name = bt_ctf_field_name(list[i]);
- if (strncmp(name, "perf_", 5) == 0) {
- int value = bt_ctf_get_uint64(list[i]);
+ if (count == 0)
+ goto end;
+
+ g_hash_table_iter_init(&iter, global_perf_liszt);
+ while (g_hash_table_iter_next (&iter, &key, (gpointer) &perfcounter)) {
+ field = bt_ctf_get_field(event, scope, (char *) key);
+ if (field) {
+ int value = bt_ctf_get_uint64(field);
if (bt_ctf_field_get_error())
continue;
if (bt_ctf_field_get_error())
continue;
- update_perf_value(proc, cpu, name, value);
+ update_perf_value(proc, cpu, (char *) key, value);
int *procname_check, int *ppid_check)
{
int j;
int *procname_check, int *ppid_check)
{
int j;
+ struct perfcounter *global;
+ const char *name;
for (j = 0; j < field_cnt; j++) {
for (j = 0; j < field_cnt; j++) {
+ name = bt_ctf_get_decl_field_name(field_list[j]);
- if (strncmp(bt_ctf_get_decl_field_name(field_list[j]), "tid", 3) == 0) {
+ if (strncmp(name, "tid", 3) == 0)
- if (strncmp(bt_ctf_get_decl_field_name(field_list[j]), "pid", 3) == 0)
+ if (strncmp(name, "tid", 3) == 0)
(*pid_check)++;
}
if (*ppid_check == 0) {
(*pid_check)++;
}
if (*ppid_check == 0) {
- if (strncmp(bt_ctf_get_decl_field_name(field_list[j]), "ppid", 4) == 0)
+ if (strncmp(name, "ppid", 4) == 0)
(*ppid_check)++;
}
if (*procname_check == 0) {
(*ppid_check)++;
}
if (*procname_check == 0) {
- if (strncmp(bt_ctf_get_decl_field_name(field_list[j]), "procname", 8) == 0)
+ if (strncmp(name, "procname", 8) == 0)
+ if (strncmp(name, "perf_", 5) == 0) {
+ global = g_hash_table_lookup(global_perf_liszt, (gpointer) name);
+ if (!global) {
+ global = g_new0(struct perfcounter, 1);
+ /* by default, sort on the first perf context */
+ if (g_hash_table_size(global_perf_liszt) == 0)
+ global->sort = 1;
+ global->visible = 1;
+ g_hash_table_insert(global_perf_liszt, (gpointer) strdup(name), global);
+ }
+ }
- /* if all checks are OK, no need to continue the checks */
if (*tid_check == 1 && *pid_check == 1 && *ppid_check == 1 &&
*procname_check == 1)
return 0;
if (*tid_check == 1 && *pid_check == 1 && *ppid_check == 1 &&
*procname_check == 1)
return 0;
ret = check_field_requirements(field_list, field_cnt,
&tid_check, &pid_check, &procname_check,
&ppid_check);
ret = check_field_requirements(field_list, field_cnt,
&tid_check, &pid_check, &procname_check,
&ppid_check);
- if (ret == 0)
- goto end;
bt_ctf_get_decl_fields(evt_list[i], BT_EVENT_CONTEXT,
&field_list, &field_cnt);
ret = check_field_requirements(field_list, field_cnt,
&tid_check, &pid_check, &procname_check,
&ppid_check);
bt_ctf_get_decl_fields(evt_list[i], BT_EVENT_CONTEXT,
&field_list, &field_cnt);
ret = check_field_requirements(field_list, field_cnt,
&tid_check, &pid_check, &procname_check,
&ppid_check);
- if (ret == 0)
- goto end;
bt_ctf_get_decl_fields(evt_list[i], BT_STREAM_PACKET_CONTEXT,
&field_list, &field_cnt);
ret = check_field_requirements(field_list, field_cnt,
&tid_check, &pid_check, &procname_check,
&ppid_check);
bt_ctf_get_decl_fields(evt_list[i], BT_STREAM_PACKET_CONTEXT,
&field_list, &field_cnt);
ret = check_field_requirements(field_list, field_cnt,
&tid_check, &pid_check, &procname_check,
&ppid_check);
- if (ret == 0)
- goto end;
fprintf(stderr, "[error] missing procname context information\n");
}
fprintf(stderr, "[error] missing procname context information\n");
}