a
    L±Ögú  ã                   @   sL   d Z dZdZdZdZdZddlZddlZdd	d
„Zdd„ Z	G dd„ dƒZ
dS )aú  
Backend management.


Creating new backends
---------------------

A new backend named 'foo-bar' corresponds to Python module
'tracetool/backend/foo_bar.py'.

A backend module should provide a docstring, whose first non-empty line will be
considered its short description.

All backends must generate their contents through the 'tracetool.out' routine.


Backend attributes
------------------

========= ====================================================================
Attribute Description
========= ====================================================================
PUBLIC    If exists and is set to 'True', the backend is considered "public".
========= ====================================================================


Backend functions
-----------------

All the following functions are optional, and no output will be generated if
they do not exist.

=============================== ==============================================
Function                        Description
=============================== ==============================================
generate_<format>_begin(events) Generate backend- and format-specific file
                                header contents.
generate_<format>_end(events)   Generate backend- and format-specific file
                                footer contents.
generate_<format>(event)        Generate backend- and format-specific contents
                                for the given event.
=============================== ==============================================

u%   LluÃ­s Vilanova <vilanova@ac.upc.edu>u:   Copyright 2012-2014, LluÃ­s Vilanova <vilanova@ac.upc.edu>z3GPL version 2 or (at your option) any later versionzStefan Hajnoczizstefanha@redhat.comé    NFc           	      C   sÐ   dg}g }t  tjjd ¡D ],}| d¡r|dkr| | dd¡d ¡ qt|ƒD ]x}t 	d| ¡}|d snqR|d }t
|dd	ƒ}| rŒ|sŒqR|j}|d
u ržd}| ¡  d¡d }| dd¡}| ||f¡ qR|S )z(Get a list of (name, description) pairs.)ÚnopzTracing disabled.r   z.pyz__init__.pyÚ.é   útracetool.backend.ZPUBLICFNÚ Ú
Ú_ú-)ÚosÚlistdirÚ	tracetoolÚbackendÚ__path__ÚendswithÚappendÚrsplitÚsortedÚ
try_importÚgetattrÚ__doc__ÚstripÚsplitÚreplace)	Úonly_publicÚresÚmodnamesÚfilenameÚmodnameÚmoduleZpublicÚdocÚname© r!   úM/home2/Puru_Virtio_Blk/virtio-demo/qemu/scripts/tracetool/backend/__init__.pyÚget_list=   s(    r#   c                 C   s:   t | ƒdkrdS | dkrdS |  dd¡} t d|  ¡d S )	z(Return whether the given backend exists.r   Fr   Tr	   r   r   r   )Úlenr   r   r   )r    r!   r!   r"   ÚexistsZ   s    r%   c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚWrapperc                 C   sL   dd„ |D ƒ| _ | dd¡| _| j D ]}t|ƒs$J ‚q$tj | j¡sHJ ‚d S )Nc                 S   s   g | ]}|  d d¡‘qS )r	   r   )r   )Ú.0r   r!   r!   r"   Ú
<listcomp>f   ó    z$Wrapper.__init__.<locals>.<listcomp>r	   r   )Ú	_backendsr   Ú_formatr%   r   Úformat)ÚselfÚbackendsr,   r   r!   r!   r"   Ú__init__e   s
    
zWrapper.__init__c                 O   sB   | j D ]6}t d| || j d ¡d }|d ur||i |¤Ž qd S )Nr   r   )r*   r   r   r+   )r-   r    ÚargsÚkwargsr   Úfuncr!   r!   r"   Ú_run_functionl   s    


ÿÿzWrapper._run_functionc                 C   s   |   d||¡ d S )Nzgenerate_%s_begin©r3   ©r-   ÚeventsÚgroupr!   r!   r"   Úgenerate_begins   s    zWrapper.generate_beginc                 C   s   |   d||¡ d S )Nzgenerate_%sr4   ©r-   Úeventr7   r!   r!   r"   Úgeneratev   s    zWrapper.generatec                 C   s   |   d||¡ d S )Nzgenerate_%s_backend_dstater4   r9   r!   r!   r"   Úgenerate_backend_dstatey   s    zWrapper.generate_backend_dstatec                 C   s   |   d||¡ d S )Nzgenerate_%s_endr4   r5   r!   r!   r"   Úgenerate_end|   s    zWrapper.generate_endN)	Ú__name__Ú
__module__Ú__qualname__r/   r3   r8   r;   r<   r=   r!   r!   r!   r"   r&   d   s   r&   )F)r   Ú
__author__Ú__copyright__Ú__license__Ú__maintainer__Ú	__email__r
   r   r#   r%   r&   r!   r!   r!   r"   Ú<module>   s   -

