blob: 7fe9a6f789a69995704af1441178fd1b286555d8 (
plain) (
blame)
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
|
#include <stdlib.h>
#include "sched_trace.h"
#include "eheap.h"
int earlier_event(struct heap_node* _a, struct heap_node* _b)
{
struct st_event_record *a, *b;
a = heap_node_value(_a);
b = heap_node_value(_b);
if (event_time(a) == 0 && event_time(b) == 0)
/* tie break by PID for consistent ordering */
return a->hdr.pid < b->hdr.pid;
else
return event_time(a) < event_time(b);
}
struct heap* heapify_events(struct st_event_record *ev, unsigned int count)
{
struct heap_node* hn;
struct heap* h;
h = malloc(sizeof(struct heap));
hn = malloc(sizeof(struct heap_node) * count);
if (!hn || !h)
return NULL;
heap_init(h);
while (count) {
heap_node_init(hn, ev);
heap_insert(earlier_event, h, hn);
hn++;
ev++;
count--;
}
return h;
}
|