Home | History | Annotate | Download | only in radeon
      1 /*
      2  * Copyright  2008 Jrme Glisse
      3  * All Rights Reserved.
      4  *
      5  * Permission is hereby granted, free of charge, to any person obtaining
      6  * a copy of this software and associated documentation files (the
      7  * "Software"), to deal in the Software without restriction, including
      8  * without limitation the rights to use, copy, modify, merge, publish,
      9  * distribute, sub license, and/or sell copies of the Software, and to
     10  * permit persons to whom the Software is furnished to do so, subject to
     11  * the following conditions:
     12  *
     13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     14  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
     15  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     16  * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
     17  * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
     20  * USE OR OTHER DEALINGS IN THE SOFTWARE.
     21  *
     22  * The above copyright notice and this permission notice (including the
     23  * next paragraph) shall be included in all copies or substantial portions
     24  * of the Software.
     25  */
     26 /*
     27  * Authors:
     28  *      Jrme Glisse <glisse (at) freedesktop.org>
     29  */
     30 #include <stdio.h>
     31 #include <stdlib.h>
     32 #include <string.h>
     33 #include "radeon_track.h"
     34 
     35 void radeon_track_add_event(struct radeon_track *track,
     36                             const char *file,
     37                             const char *func,
     38                             const char *op,
     39                             unsigned line)
     40 {
     41     struct radeon_track_event *event;
     42 
     43     if (track == NULL) {
     44         return;
     45     }
     46     event = (void*)calloc(1,sizeof(struct radeon_track_event));
     47     if (event == NULL) {
     48         return;
     49     }
     50     event->line = line;
     51     event->file = strdup(file);
     52     event->func = strdup(func);
     53     event->op = strdup(op);
     54     if (event->file == NULL || event->func == NULL || event->op == NULL) {
     55         free(event->file);
     56         free(event->func);
     57         free(event->op);
     58         free(event);
     59         return;
     60     }
     61     event->next = track->events;
     62     track->events = event;
     63 }
     64 
     65 struct radeon_track *radeon_tracker_add_track(struct radeon_tracker *tracker,
     66                                               unsigned key)
     67 {
     68     struct radeon_track *track;
     69 
     70     track = (struct radeon_track*)calloc(1, sizeof(struct radeon_track));
     71     if (track) {
     72         track->next = tracker->tracks.next;
     73         track->prev = &tracker->tracks;
     74         tracker->tracks.next = track;
     75         if (track->next) {
     76             track->next->prev = track;
     77         }
     78         track->key = key;
     79         track->events = NULL;
     80     }
     81     return track;
     82 }
     83 
     84 void radeon_tracker_remove_track(struct radeon_tracker *tracker,
     85                                  struct radeon_track *track)
     86 {
     87     struct radeon_track_event *event;
     88     void *tmp;
     89 
     90     if (track == NULL) {
     91         return;
     92     }
     93     track->prev->next = track->next;
     94     if (track->next) {
     95         track->next->prev = track->prev;
     96     }
     97     track->next = track->prev = NULL;
     98     event = track->events;
     99     while (event) {
    100         tmp = event;
    101         free(event->file);
    102         free(event->func);
    103         free(event->op);
    104         event = event->next;
    105         free(tmp);
    106     }
    107     track->events = NULL;
    108     free(track);
    109 }
    110 
    111 void radeon_tracker_print(struct radeon_tracker *tracker, FILE *file)
    112 {
    113     struct radeon_track *track;
    114     struct radeon_track_event *event;
    115     void *tmp;
    116 
    117     track = tracker->tracks.next;
    118     while (track) {
    119         event = track->events;
    120         fprintf(file, "[0x%08X] :\n", track->key);
    121         while (event) {
    122             tmp = event;
    123             fprintf(file, "  [0x%08X:%s](%s:%s:%d)\n",
    124                     track->key, event->op,  event->file,
    125                     event->func, event->line);
    126             free(event->file);
    127             free(event->func);
    128             free(event->op);
    129             event->file = NULL;
    130             event->func = NULL;
    131             event->op = NULL;
    132             event = event->next;
    133             free(tmp);
    134         }
    135         track->events = NULL;
    136         tmp = track;
    137         track = track->next;
    138         free(tmp);
    139     }
    140 	tracker->tracks.next = NULL;
    141 }
    142