forked from rostedt/trace-cmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace-view-store.c
1527 lines (1166 loc) · 39.3 KB
/
trace-view-store.c
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "trace-view-store.h"
#include <stdlib.h>
#include <string.h>
#include "cpu.h"
#include "trace-filter.h"
/* boring declarations of local functions */
static void trace_view_store_init (TraceViewStore *pkg_tree);
static void trace_view_store_class_init (TraceViewStoreClass *klass);
static void trace_view_store_tree_model_init (GtkTreeModelIface *iface);
static void trace_view_store_finalize (GObject *object);
static gboolean trace_view_store_get_iter (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreePath *path);
static GtkTreePath *trace_view_store_get_path (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gboolean trace_view_store_iter_next (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gboolean trace_view_store_iter_children (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent);
static gboolean trace_view_store_iter_has_child (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gint trace_view_store_iter_n_children (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gboolean trace_view_store_iter_nth_child (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent,
gint n);
static gboolean trace_view_store_iter_parent (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *child);
static GObjectClass *parent_class = NULL; /* GObject stuff - nothing to worry about */
/*****************************************************************************
*
* trace_view_store_get_type: here we register our new type and its interfaces
* with the type system. If you want to implement
* additional interfaces like GtkTreeSortable, you
* will need to do it here.
*
*****************************************************************************/
GType
trace_view_store_get_type (void)
{
static GType trace_view_store_type = 0;
/* Some boilerplate type registration stuff */
if (trace_view_store_type == 0)
{
static const GTypeInfo trace_view_store_info =
{
sizeof (TraceViewStoreClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) trace_view_store_class_init,
NULL, /* class finalize */
NULL, /* class_data */
sizeof (TraceViewStore),
0, /* n_preallocs */
(GInstanceInitFunc) trace_view_store_init
};
static const GInterfaceInfo tree_model_info =
{
(GInterfaceInitFunc) trace_view_store_tree_model_init,
NULL,
NULL
};
/* First register the new derived type with the GObject type system */
trace_view_store_type = g_type_register_static (G_TYPE_OBJECT, "TraceViewStore",
&trace_view_store_info, (GTypeFlags)0);
/* Now register our GtkTreeModel interface with the type system */
g_type_add_interface_static (trace_view_store_type, GTK_TYPE_TREE_MODEL, &tree_model_info);
}
return trace_view_store_type;
}
/*****************************************************************************
*
* trace_view_store_class_init: more boilerplate GObject/GType stuff.
* Init callback for the type system,
* called once when our new class is created.
*
*****************************************************************************/
static void
trace_view_store_class_init (TraceViewStoreClass *klass)
{
GObjectClass *object_class;
parent_class = (GObjectClass*) g_type_class_peek_parent (klass);
object_class = (GObjectClass*) klass;
object_class->finalize = trace_view_store_finalize;
}
/*****************************************************************************
*
* trace_view_store_tree_model_init: init callback for the interface registration
* in trace_view_store_get_type. Here we override
* the GtkTreeModel interface functions that
* we implement.
*
*****************************************************************************/
static void
trace_view_store_tree_model_init (GtkTreeModelIface *iface)
{
iface->get_flags = trace_view_store_get_flags;
iface->get_n_columns = trace_view_store_get_n_columns;
iface->get_column_type = trace_view_store_get_column_type;
iface->get_iter = trace_view_store_get_iter;
iface->get_path = trace_view_store_get_path;
iface->get_value = trace_view_store_get_value;
iface->iter_next = trace_view_store_iter_next;
iface->iter_children = trace_view_store_iter_children;
iface->iter_has_child = trace_view_store_iter_has_child;
iface->iter_n_children = trace_view_store_iter_n_children;
iface->iter_nth_child = trace_view_store_iter_nth_child;
iface->iter_parent = trace_view_store_iter_parent;
}
/*****************************************************************************
*
* trace_view_store_init: this is called everytime a new trace view store object
* instance is created (we do that in trace_view_store_new).
* Initialise the list structure's fields here.
*
*****************************************************************************/
static void
trace_view_store_init (TraceViewStore *trace_view_store)
{
trace_view_store->n_columns = TRACE_VIEW_STORE_N_COLUMNS;
trace_view_store->column_types[0] = G_TYPE_UINT; /* INDEX */
trace_view_store->column_types[1] = G_TYPE_UINT; /* CPU */
trace_view_store->column_types[2] = G_TYPE_STRING; /* TS */
trace_view_store->column_types[3] = G_TYPE_STRING; /* COMM */
trace_view_store->column_types[4] = G_TYPE_UINT; /* PID */
trace_view_store->column_types[5] = G_TYPE_STRING; /* LAT */
trace_view_store->column_types[6] = G_TYPE_STRING; /* EVENT */
trace_view_store->column_types[7] = G_TYPE_STRING; /* INFO */
g_assert (TRACE_VIEW_STORE_N_COLUMNS == 8);
trace_view_store->num_rows = 0;
trace_view_store->rows = NULL;
trace_view_store->spin = NULL;
trace_view_store->page = 1;
trace_view_store->pages = 1;
trace_view_store->rows_per_page = TRACE_VIEW_DEFAULT_MAX_ROWS;
trace_view_store->num_rows = 0;
trace_view_store->start_row = 0;
trace_view_store->visible_rows = 0;
trace_view_store->actual_rows = 0;
/* Set all columns visible */
trace_view_store->visible_column_mask = (1 << TRACE_VIEW_STORE_N_COLUMNS) - 1;
trace_view_store->stamp = g_random_int(); /* Random int to check whether an iter belongs to our model */
}
/*****************************************************************************
*
* trace_view_store_finalize: this is called just before a trace view store is
* destroyed. Free dynamically allocated memory here.
*
*****************************************************************************/
static void
trace_view_store_finalize (GObject *object)
{
TraceViewStore *store = TRACE_VIEW_STORE(object);
gint cpu;
/* free all records and free all memory used by the list */
for (cpu = 0; cpu < store->cpus; cpu++)
g_free(store->cpu_list[cpu]);
g_free(store->cpu_list);
g_free(store->cpu_mask);
g_free(store->rows);
g_free(store->cpu_items);
filter_task_hash_free(store->task_filter);
if (store->spin) {
g_object_unref(store->spin);
store->spin = NULL;
}
tracecmd_close(store->handle);
/* must chain up - finalize parent */
(* parent_class->finalize) (object);
}
/*****************************************************************************
*
* trace_view_store_get_flags: tells the rest of the world whether our tree model
* has any special characteristics. In our case,
* we have a list model (instead of a tree), and each
* tree iter is valid as long as the row in question
* exists, as it only contains a pointer to our struct.
*
*****************************************************************************/
GtkTreeModelFlags
trace_view_store_get_flags (GtkTreeModel *tree_model)
{
g_return_val_if_fail (TRACE_VIEW_IS_LIST(tree_model), (GtkTreeModelFlags)0);
return (GTK_TREE_MODEL_LIST_ONLY | GTK_TREE_MODEL_ITERS_PERSIST);
}
/*****************************************************************************
*
* trace_view_store_get_n_columns: tells the rest of the world how many data
* columns we export via the tree model interface
*
*****************************************************************************/
gint
trace_view_store_get_n_columns (GtkTreeModel *tree_model)
{
g_return_val_if_fail (TRACE_VIEW_IS_LIST(tree_model), 0);
return TRACE_VIEW_STORE(tree_model)->n_columns;
}
/*****************************************************************************
*
* get_visible_column: Return the index of the visible columns
*
*****************************************************************************/
static gint get_visible_column(TraceViewStore *trace_view, gint column)
{
guint i;
/* If all columns are visible just use what was passed in */
if (trace_view->visible_column_mask == ((1 << TRACE_VIEW_STORE_N_COLUMNS) - 1))
return column;
column++; /* make 0 drop out */
for (i = 0; column && i < TRACE_VIEW_STORE_N_COLUMNS; i++) {
if (!(trace_view->visible_column_mask & (1 << i)))
continue;
column--;
}
g_assert(column == 0);
/* We upped column, so me must dec the return */
return i - 1;
}
/*****************************************************************************
*
* trace_view_store_get_column_type: tells the rest of the world which type of
* data an exported model column contains
*
*****************************************************************************/
GType
trace_view_store_get_column_type (GtkTreeModel *tree_model,
gint index)
{
g_return_val_if_fail (TRACE_VIEW_IS_LIST(tree_model), G_TYPE_INVALID);
g_return_val_if_fail (index < TRACE_VIEW_STORE(tree_model)->n_columns && index >= 0, G_TYPE_INVALID);
index = get_visible_column(TRACE_VIEW_STORE(tree_model), index);
return TRACE_VIEW_STORE(tree_model)->column_types[index];
}
/*****************************************************************************
*
* trace_view_store_get_iter: converts a tree path (physical position) into a
* tree iter structure (the content of the iter
* fields will only be used internally by our model).
* We simply store a pointer to our TraceViewRecord
* structure that represents that row in the tree iter.
*
*****************************************************************************/
static gboolean
trace_view_store_get_iter (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreePath *path)
{
TraceViewStore *trace_view_store;
TraceViewRecord *record;
gint *indices, n, depth;
g_assert(TRACE_VIEW_IS_LIST(tree_model));
g_assert(path!=NULL);
trace_view_store = TRACE_VIEW_STORE(tree_model);
indices = gtk_tree_path_get_indices(path);
depth = gtk_tree_path_get_depth(path);
/* we do not allow children */
g_assert(depth == 1); /* depth 1 = top level; a list only has top level nodes and no children */
n = indices[0]; /* the n-th top level row */
record = trace_view_store_get_visible_row(trace_view_store, n);
if (!record)
return FALSE;
/* We simply store a pointer to our custom record in the iter */
iter->stamp = trace_view_store->stamp;
iter->user_data = record;
iter->user_data2 = NULL; /* unused */
iter->user_data3 = NULL; /* unused */
return TRUE;
}
/*****************************************************************************
*
* trace_view_store_get_path: converts a tree iter into a tree path (ie. the
* physical position of that row in the list).
*
*****************************************************************************/
static GtkTreePath *
trace_view_store_get_path (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
GtkTreePath *path;
TraceViewRecord *record;
TraceViewStore *trace_view_store;
g_return_val_if_fail (TRACE_VIEW_IS_LIST(tree_model), NULL);
g_return_val_if_fail (iter != NULL, NULL);
g_return_val_if_fail (iter->user_data != NULL, NULL);
trace_view_store = TRACE_VIEW_STORE(tree_model);
record = (TraceViewRecord*) iter->user_data;
path = gtk_tree_path_new();
gtk_tree_path_append_index(path, record->pos);
return path;
}
/*****************************************************************************
*
* trace_view_store_get_value: Returns a row's exported data columns
* (_get_value is what gtk_tree_model_get uses)
*
*****************************************************************************/
void
trace_view_store_get_value (GtkTreeModel *tree_model,
GtkTreeIter *iter,
gint column,
GValue *value)
{
TraceViewRecord *record;
TraceViewStore *trace_view_store;
struct trace_seq s;
struct pevent *pevent;
struct event_format *event;
struct record *data;
const gchar *comm;
gchar *str;
guint64 secs, usecs;
gint val, pos;
int cpu;
g_return_if_fail (TRACE_VIEW_IS_LIST (tree_model));
g_return_if_fail (iter != NULL);
g_return_if_fail (column < TRACE_VIEW_STORE(tree_model)->n_columns);
g_value_init (value, TRACE_VIEW_STORE(tree_model)->column_types[column]);
trace_view_store = TRACE_VIEW_STORE(tree_model);
pevent = tracecmd_get_pevent(trace_view_store->handle);
record = (TraceViewRecord*)iter->user_data;
g_return_if_fail ( record != NULL );
pos = record->pos - trace_view_store->start_row;
if(pos >= trace_view_store->num_rows)
g_return_if_reached();
column = get_visible_column(TRACE_VIEW_STORE(tree_model), column);
switch(column)
{
case TRACE_VIEW_STORE_COL_INDEX:
g_value_set_uint(value, record->pos);
break;
case TRACE_VIEW_STORE_COL_CPU:
g_value_set_uint(value, record->cpu);
break;
case TRACE_VIEW_STORE_COL_TS:
usecs = record->timestamp;
usecs /= 1000;
secs = usecs / 1000000ULL;
usecs -= secs * 1000000ULL;
str = g_strdup_printf("%llu.%06llu",
(long long)secs, (long long)usecs);
g_value_set_string(value, str);
g_free(str);
break;
case TRACE_VIEW_STORE_COL_COMM:
case TRACE_VIEW_STORE_COL_PID:
case TRACE_VIEW_STORE_COL_LAT:
case TRACE_VIEW_STORE_COL_EVENT:
case TRACE_VIEW_STORE_COL_INFO:
data = tracecmd_read_at(trace_view_store->handle, record->offset, &cpu);
g_assert(data != NULL);
if (cpu != record->cpu) {
free_record(data);
return;
}
switch (column) {
case TRACE_VIEW_STORE_COL_COMM:
case TRACE_VIEW_STORE_COL_PID:
val = pevent_data_pid(pevent, data);
if (column == TRACE_VIEW_STORE_COL_PID)
g_value_set_uint(value, val);
else {
comm = pevent_data_comm_from_pid(pevent, val);
g_value_set_string(value, comm);
}
break;
case TRACE_VIEW_STORE_COL_LAT:
trace_seq_init(&s);
pevent_data_lat_fmt(pevent, &s, data);
g_value_set_string(value, s.buffer);
break;
case TRACE_VIEW_STORE_COL_EVENT:
case TRACE_VIEW_STORE_COL_INFO:
val = pevent_data_type(pevent, data);
event = pevent_data_event_from_type(pevent, val);
if (column == TRACE_VIEW_STORE_COL_EVENT) {
g_value_set_string(value, event->name);
break;
}
trace_seq_init(&s);
pevent_event_info(&s, event, data);
g_value_set_string(value, s.buffer);
break;
}
free_record(data);
}
}
gboolean trace_view_store_system_enabled(TraceViewStore *store, const gchar *system)
{
const gchar **sys = &system;
g_return_val_if_fail (TRACE_VIEW_IS_LIST (store), FALSE);
if (store->all_events)
return TRUE;
if (!store->systems)
return FALSE;
sys = bsearch(sys, store->systems, store->systems_size,
sizeof(system), str_cmp);
return sys != NULL;
}
gboolean trace_view_store_event_enabled(TraceViewStore *store, gint event_id)
{
gint key = event_id;
gint *ret;
g_return_val_if_fail (TRACE_VIEW_IS_LIST (store), FALSE);
if (store->all_events)
return TRUE;
/* TODO: search for the system of the event? */
if (!store->event_types)
return FALSE;
ret = bsearch(&key, store->event_types, store->event_types_size,
sizeof(gint), id_cmp);
return ret != NULL;
}
static void clear_all_events(TraceViewStore *store)
{
gint i;
if (store->systems_size) {
for (i = 0; i < store->systems_size; i++)
g_free(store->systems[i]);
g_free(store->systems);
store->systems = NULL;
store->systems_size = 0;
}
g_free(store->event_types);
store->event_types = NULL;
store->event_types_size = 0;
}
void trace_view_store_clear_all_events_enabled(TraceViewStore *store)
{
g_return_if_fail (TRACE_VIEW_IS_LIST (store));
clear_all_events(store);
store->all_events = 0;
}
void trace_view_store_set_all_events_enabled(TraceViewStore *store)
{
g_return_if_fail (TRACE_VIEW_IS_LIST (store));
if (store->all_events)
return;
/*
* All enabled means that we don't need to look at
* the system events, so free those arrays.
*/
clear_all_events(store);
store->all_events = 1;
}
static void remove_system(TraceViewStore *store, const gchar *system)
{
const gchar **sys = &system;
if (!store->systems)
return;
sys = bsearch(sys, store->systems, store->systems_size,
sizeof(system), str_cmp);
if (!sys)
return;
g_free(*((gchar **)sys));
g_memmove(sys, sys+1, sizeof(*sys) * (store->systems_size -
((gchar **)sys - store->systems)));
store->systems_size--;
store->systems[store->systems_size] = NULL;
}
void trace_view_store_set_system_enabled(TraceViewStore *store, const gchar *system)
{
g_return_if_fail (TRACE_VIEW_IS_LIST (store));
if (store->all_events)
/*
* We are adding a new filter, so this is the
* only system enabled.
*/
store->all_events = 0;
if (trace_view_store_system_enabled(store, system))
return;
if (!store->systems) {
store->systems = g_new0(gchar *, 2);
store->systems[0] = g_strdup(system);
store->systems_size++;
return;
}
store->systems_size++;
store->systems = g_realloc(store->systems,
sizeof(*store->systems) * (store->systems_size+1));
store->systems[store->systems_size - 1] = g_strdup(system);
store->systems[store->systems_size] = NULL;
qsort(store->systems, store->systems_size, sizeof(gchar *), str_cmp);
}
void trace_view_store_set_event_enabled(TraceViewStore *store, gint event_id)
{
struct pevent *pevent;
struct event_format *event;
g_return_if_fail (TRACE_VIEW_IS_LIST (store));
pevent = tracecmd_get_pevent(store->handle);
event = pevent_find_event(pevent, event_id);
if (!event)
return;
if (store->all_events)
/*
* We are adding a new filter, so this is the
* only system enabled.
*/
store->all_events = 0;
remove_system(store, event->system);
if (trace_view_store_event_enabled(store, event_id))
return;
if (!store->event_types) {
store->event_types = g_new0(gint, 2);
store->event_types[0] = event_id;
store->event_types[1] = -1;
store->event_types_size++;
return;
}
store->event_types_size++;
store->event_types = g_realloc(store->event_types,
sizeof(*store->event_types) * (store->event_types_size+1));
store->event_types[store->event_types_size - 1] = event_id;
store->event_types[store->event_types_size] = -1;
qsort(store->event_types, store->event_types_size, sizeof(gint), id_cmp);
}
/*****************************************************************************
*
* trace_view_store_iter_next: Takes an iter structure and sets it to point
* to the next row.
*
*****************************************************************************/
static gboolean
trace_view_store_iter_next (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
TraceViewRecord *record, *nextrecord;
TraceViewStore *trace_view_store;
gint pos;
g_return_val_if_fail (TRACE_VIEW_IS_LIST (tree_model), FALSE);
if (iter == NULL || iter->user_data == NULL)
return FALSE;
trace_view_store = TRACE_VIEW_STORE(tree_model);
record = (TraceViewRecord *) iter->user_data;
pos = record->pos - trace_view_store->start_row;
/* Is this the last record in the list? */
if ((pos + 1) >= trace_view_store->num_rows)
return FALSE;
nextrecord = trace_view_store->rows[(record->pos + 1)];
g_assert ( nextrecord != NULL );
g_assert ( nextrecord->pos == (record->pos + 1) );
iter->stamp = trace_view_store->stamp;
iter->user_data = nextrecord;
return TRUE;
}
/*****************************************************************************
*
* trace_view_store_iter_children: Returns TRUE or FALSE depending on whether
* the row specified by 'parent' has any children.
* If it has children, then 'iter' is set to
* point to the first child. Special case: if
* 'parent' is NULL, then the first top-level
* row should be returned if it exists.
*
*****************************************************************************/
static gboolean
trace_view_store_iter_children (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent)
{
TraceViewStore *trace_view_store;
g_return_val_if_fail (parent == NULL || parent->user_data != NULL, FALSE);
/* this is a list, nodes have no children */
if (parent)
return FALSE;
/* parent == NULL is a special case; we need to return the first top-level row */
g_return_val_if_fail (TRACE_VIEW_IS_LIST (tree_model), FALSE);
trace_view_store = TRACE_VIEW_STORE(tree_model);
/* No rows => no first row */
if (trace_view_store->num_rows == 0)
return FALSE;
/* Set iter to first item in list */
iter->stamp = trace_view_store->stamp;
iter->user_data = trace_view_store->rows[0];
return TRUE;
}
/*****************************************************************************
*
* trace_view_store_iter_has_child: Returns TRUE or FALSE depending on whether
* the row specified by 'iter' has any children.
* We only have a list and thus no children.
*
*****************************************************************************/
static gboolean
trace_view_store_iter_has_child (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
return FALSE;
}
/*****************************************************************************
*
* trace_view_store_iter_n_children: Returns the number of children the row
* specified by 'iter' has. This is usually 0,
* as we only have a list and thus do not have
* any children to any rows. A special case is
* when 'iter' is NULL, in which case we need
* to return the number of top-level nodes,
* ie. the number of rows in our list.
*
*****************************************************************************/
static gint
trace_view_store_iter_n_children (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
TraceViewStore *trace_view_store;
g_return_val_if_fail (TRACE_VIEW_IS_LIST (tree_model), -1);
g_return_val_if_fail (iter == NULL || iter->user_data != NULL, FALSE);
trace_view_store = TRACE_VIEW_STORE(tree_model);
/* special case: if iter == NULL, return number of top-level rows */
if (!iter)
return trace_view_store->num_rows;
return 0; /* otherwise, this is easy again for a list */
}
/*****************************************************************************
*
* trace_view_store_iter_nth_child: If the row specified by 'parent' has any
* children, set 'iter' to the n-th child and
* return TRUE if it exists, otherwise FALSE.
* A special case is when 'parent' is NULL, in
* which case we need to set 'iter' to the n-th
* row if it exists.
*
*****************************************************************************/
static gboolean
trace_view_store_iter_nth_child (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent,
gint n)
{
TraceViewRecord *record;
TraceViewStore *trace_view_store;
g_return_val_if_fail (TRACE_VIEW_IS_LIST (tree_model), FALSE);
trace_view_store = TRACE_VIEW_STORE(tree_model);
/* a list has only top-level rows */
if(parent)
return FALSE;
/* special case: if parent == NULL, set iter to n-th top-level row */
if( n >= trace_view_store->num_rows )
return FALSE;
record = trace_view_store->rows[trace_view_store->start_row + n];
g_assert( record != NULL );
g_assert( record->pos - trace_view_store->start_row == n );
iter->stamp = trace_view_store->stamp;
iter->user_data = record;
return TRUE;
}
/*****************************************************************************
*
* trace_view_store_iter_parent: Point 'iter' to the parent node of 'child'. As
* we have a list and thus no children and no
* parents of children, we can just return FALSE.
*
*****************************************************************************/
static gboolean
trace_view_store_iter_parent (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *child)
{
return FALSE;
}
static int mask_cpu_isset(TraceViewStore *store, gint cpu)
{
return cpu_isset(store->cpu_mask, cpu);
}
static void mask_cpu_set(TraceViewStore *store, gint cpu)
{
cpu_set(store->cpu_mask, cpu);
}
static void mask_cpu_clear(TraceViewStore *store, gint cpu)
{
cpu_clear(store->cpu_mask, cpu);
}
static void mask_set_cpus(TraceViewStore *store, gint cpus)
{
set_cpus(store->cpu_mask, cpus);
}
static void update_page(TraceViewStore *store)
{
if (!store->spin)
return;
gtk_spin_button_set_range(GTK_SPIN_BUTTON(store->spin),
1, store->pages);
}
/*****************************************************************************
*
* merge_sort_rows_ts: Merge sort the data by time stamp.
*
*
*****************************************************************************/
static void merge_sort_rows_ts(TraceViewStore *store)
{
guint64 ts;
gint next;
guint *indexes;
guint count = 0;
gint cpu;
guint i;
indexes = g_new0(guint, store->cpus);
/* Now sort these by timestamp */
do {
next = -1;
ts = 0;
for (cpu = 0; cpu < store->cpus; cpu++) {
if (!store->all_cpus && !mask_cpu_isset(store, cpu))
continue;
try_again:
if (indexes[cpu] == store->cpu_items[cpu])
continue;
i = indexes[cpu];
if (!store->cpu_list[cpu][i].visible) {
indexes[cpu]++;
goto try_again;
}
if (!ts || store->cpu_list[cpu][i].timestamp < ts) {
ts = store->cpu_list[cpu][i].timestamp;
next = cpu;
}
}
if (next >= 0) {
i = indexes[next]++;
store->rows[count] = &store->cpu_list[next][i];
store->cpu_list[next][i].pos = count++;
}
} while (next >= 0);
store->visible_rows = count;
store->start_row = 0;
store->pages = (count / store->rows_per_page) + 1;
if (store->page > 1) {
if (count < store->page * store->rows_per_page)
store->page = store->pages;
/* still greater? */
if (store->page > 1) {
store->start_row =
(store->page - 1) * store->rows_per_page;
g_assert(store->start_row < count);
}
}
store->num_rows = count > (store->start_row + store->rows_per_page) ?
store->rows_per_page :
count - store->start_row;
update_page(store);
g_free(indexes);
}
/*****************************************************************************
*
* trace_view_store_new: This is what you use in your own code to create a
* new trace view store tree model for you to use.
*
*****************************************************************************/
TraceViewStore *
trace_view_store_new (struct tracecmd_input *handle)
{
TraceViewStore *newstore;
struct record *data;
gint cpu, count, total=0;
struct temp {
guint64 offset;
guint64 ts;
struct temp *next;
} *list, **next, *rec;
newstore = (TraceViewStore*) g_object_new (TRACE_VIEW_STORE_TYPE, NULL);
g_assert( newstore != NULL );
newstore->handle = handle;
newstore->cpus = tracecmd_cpus(handle);
tracecmd_ref(handle);
newstore->cpu_list = g_new(TraceViewRecord *, newstore->cpus);
g_assert(newstore->cpu_list != NULL);