wpsamp.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,543 行 · 第 1/4 页

C
1,543
字号
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  Display profile samples in the GUI.
*
****************************************************************************/


#include <stdio.h>
#include <string.h>
#include "walloca.h"

#include "common.h"
#include "aui.h"
#include "wpaui.h"
#include "dip.h"
#include "sampinfo.h"
#include "wpsrcfil.h"
#include "wpasmfil.h"
#include "msg.h"


extern image_info *SImageGetImage(a_window *wnd,int row);
extern mod_info *SModGetModule(a_window *wnd,int row);
extern file_info *SFileGetFile(a_window *wnd,int row);
extern rtn_info *SRtnGetRoutine(a_window *wnd,int row);
extern int WPGetRow(sio_data *curr_sio);
extern wp_srcfile *WPSourceOpen(sio_data *curr_sio,bint quiet);
extern void WPSourceClose(wp_srcfile *wpsrc_file);
extern char *WPSourceGetLine(a_window *wnd,int line);
extern gui_ord WPGetClientHeight(a_window *wnd);
extern gui_ord WPGetClientWidth(a_window *wnd);
extern void WPAdjustRowHeight(a_window *wnd,bint initial_set);
extern void WPSetRowHeight(a_window *wnd);
extern gui_ord WPPixelTruncWidth(gui_ord width);
extern gui_ord WPPixelWidth(a_window *wnd);
extern void ClearSample(sio_data *curr_sio);
extern bint GetCurrentGather(sio_data *curr_sio);
extern void FlipCurrentGather(sio_data *curr_sio);
extern void GatherCurrent(sio_data *curr_sio);
extern int GetCurrentSort(sio_data *curr_sio);
extern void SetCurrentSort(sio_data *curr_sio,int sort_type);
extern void SortCurrent(sio_data *curr_sio);
extern void WPDipSetProc(process_info *dip_proc);
extern wp_asmfile *WPAsmOpen(sio_data *curr_sio,int src_row,bint quiet);
extern void WPAsmClose(wp_asmfile *wpasm_file);
extern char *WPAsmGetLine(a_window *wnd,int line);
extern int WPAsmFindSrcLine(sio_data *curr_sio,int line);
extern wp_asmline *WPGetAsmLoc(wp_asmfile *wpasm_file,int row,int *group_loc,int *row_loc);
extern void *ProfRealloc(void *p,size_t new_size);
extern bint GetCurrentAbsBar(sio_data *curr_sio);
extern bint GetCurrentRelBar(sio_data *curr_sio);
extern bint GetCurrentMaxBar(sio_data *curr_sio);
extern void FlipCurrentAbsBar(sio_data *curr_sio);
extern void FlipCurrentRelBar(sio_data *curr_sio);
extern void FlipCurrentMaxBar(sio_data *curr_sio);
extern void ErrorMsg(char *msg,... );
extern int SampleNumRows( a_window * wnd );
extern void SetCurrentMAD( mad_handle );


extern sio_data *       SIOData;
extern sio_data *       CurrSIOData;

STATIC void *           sampleCreateWin( void );
STATIC void             sampleOpenMainImage( void );
STATIC bint             sampleProcTopStatus( a_window *, int, int, wnd_line_piece * );
STATIC bint             sampleProcBotStatus( a_window *, int, int, wnd_line_piece * );
STATIC bint             sampleProcStatus( a_window *, int, int, wnd_line_piece * );
STATIC bint             sampleProcOverview( a_window *, int, int, wnd_line_piece * );
STATIC bool             sampleEventProc( a_window *, gui_event, void * );
STATIC bint             sampleSetLine( a_window *, int, int, wnd_line_piece * );
STATIC bool             sampleGetLine( a_window *, wnd_row, int, wnd_line_piece * );
STATIC int              simageDetailLine( a_window *, int, bint );
STATIC int              smodDetailLine( a_window *, int, bint );
STATIC int              sfileDetailLine( a_window *, int, bint );
STATIC int              srtnDetailLine( a_window *, int, bint );
STATIC int              ssrcDetailLine( a_window *, int, bint );
STATIC int              sasmDetailLine( a_window *, int, bint );
STATIC int              srtnOpenDetail( sio_data *, bint );
STATIC void             sampleRefresh( a_window * );
STATIC void             sampleMenuItem( a_window *, unsigned, int, int );
STATIC void             sampFixDirtyCurr( a_window * );
STATIC bint             simageGetLine( a_window *, int );
STATIC bint             smodGetLine( a_window *, int );
STATIC bint             sfileGetLine( a_window *, int );
STATIC bint             srtnGetLine( a_window *, int );
STATIC bint             ssrcGetLine( a_window *, int );
STATIC bint             sasmGetLine( a_window *, int );
STATIC void             gatherSort( sio_data * );
STATIC void             setDisplay( a_window *, sio_data *, bint );

typedef bint (SAMPLEGETRTNS)( a_window *wnd, int row );
typedef int (SAMPLEDETAILRTNS)( a_window *wnd, int row, bint multi_level );

enum {
    PIECE_MOUSE_CATCHER,
    PIECE_BAR,
    PIECE_SEPARATOR,
    PIECE_HOOK,
    PIECE_DETAIL_NAME = PIECE_HOOK,
    PIECE_NAME_TITLE,
    PIECE_NAME_TEXT,
    PIECE_LAST
};

enum {
    PIECE_REL_HEADER=PIECE_MOUSE_CATCHER+1,
    PIECE_REL_PERCENT,
    PIECE_ABS_HEADER,
    PIECE_ABS_PERCENT,
    PIECE_PERCENT_SEPARATOR,
    PIECE_DETAIL_TITLE,
    PIECE_HEADER_LAST
};

enum {
    PIECE_DRAW_LINE=PIECE_MOUSE_CATCHER+1,
};

#define STATUS_ROW          8
#define BAR_TAIL_POINT      2500
#define SEPARATOR_POINT     2500

static char * overviewHeaders[] = {
    LIT( Sample_Header ),
    LIT( Image_Header ),
    LIT( Module_Header ),
    LIT( File_Header ),
    LIT( Routine_Header ),
    LIT( Source_Header ),
    LIT( Empty_Str ),
};

static char * statusHeaders[] = {
    LIT( Image_Names ),
    LIT( Module_Names ),
    LIT( File_Names ),
    LIT( Routine_Names ),
    LIT( Source_Line ),
    LIT( Assembler_Instructions ),
};

static SAMPLEGETRTNS * sampleGetRtns[] = {
    &simageGetLine,
    &smodGetLine,
    &sfileGetLine,
    &srtnGetLine,
    &ssrcGetLine,
    &sasmGetLine,
};

static SAMPLEDETAILRTNS * overviewDetailRtns[] = {
    &simageDetailLine,
    &smodDetailLine,
    &sfileDetailLine,
    &srtnDetailLine,
    &ssrcDetailLine,
    &sasmDetailLine,
};

static gui_menu_struct graphBarMenu[] = {
    { "&Stretch", MENU_SAMP_BAR_MAX_TIME, GUI_ENABLED,
                            "Stretch the largest value to the edge of the window" },
    { "&Absolute Bars", MENU_SAMP_ABS, GUI_ENABLED,
                            "Show Absolute Graph Bars" },
    { "&Relative Bars", MENU_SAMP_REL, GUI_ENABLED,
                            "Show Relative Graph Bars" }
};

static gui_menu_struct sortMenu[] = {
    { "&Sample Count", MENU_SORT_COUNT, GUI_ENABLED,
                            "Sort by the number of samples" },
    { "&Name", MENU_SORT_NAME, GUI_ENABLED,
                            "Sort by the name" },
};

static gui_menu_struct sampleMenu[] = {
    { "Zoom &In\tF3", MENU_SAMP_ZOOM_IN, GUI_ENABLED,
                            "Zoom in form more detail" },
    { "Back &Out\tF4", MENU_SAMP_BACK_OUT, GUI_ENABLED,
                            "Back out from the current display" },
    { "&Gather Small Values", MENU_SAMP_GATHER, GUI_ENABLED,
                            "Gather small samples together" },
    { "&Bar Graph", MENU_SAMP_BAR, GUI_ENABLED,
                             "Make adjustments to the bar graph",
                             ArraySize( graphBarMenu ), graphBarMenu },
    { "&Sort", MENU_SAMP_SORT, GUI_ENABLED,
                             "Sort the values",
                             ArraySize( sortMenu ), sortMenu },
};

static char *       nameBuff = NULL;
static wnd_bar_info barData;
static char *       dispName;
static clicks_t     dispCount;
static clicks_t     localTicks;
static clicks_t     maxTime;
static gui_ord      barExtent;
static gui_ord      bar2Extent;
static gui_ord      indentPiece = 0;
static gui_ord      relPctStatusIndent;
static gui_ord      absPctStatusIndent;
static bint         sampNewRow;
static bint         barMaxTime;
static bint         dispHighLight;
static bint         absGraphBar;
static bint         relGraphBar;
static char         relData[20];
static char         absData[20];
static char         lineData[64];


wnd_info WPSampleInfo = {
    sampleEventProc,
    sampleRefresh,
    sampleGetLine,
    sampleMenuItem,
    NoScroll,
    NoBegPaint,
    NoEndPaint,
    WndFirstMenuItem,
    SampleNumRows,
    NoNextRow,
    NoNotify,
    0,
    DefPopUp( sampleMenu )
};



extern void WPSampleOpen( void )
/******************************/
{
    if( CurrSIOData->sample_window == NULL ) {
        CurrSIOData->sample_window = sampleCreateWin();
        if( CurrSIOData->sample_window != NULL ) {
            sampleOpenMainImage();
            WndSetThumb( CurrSIOData->sample_window );
        }
    }
    if( CurrSIOData->sample_window != NULL ) {
        WndToFront( CurrSIOData->sample_window );
        WndShowWindow( CurrSIOData->sample_window );
        WPSetRowHeight( CurrSIOData->sample_window );
    }
}



STATIC void *sampleCreateWin( void )
/**********************************/
{
    a_window            *wnd;
    wnd_create_struct   info;
    char                *title;

#define TITLE_LEN       255

    title = __alloca( TITLE_LEN );
    if( title == NULL ) return( NULL );
    WndInitCreateStruct( &info );
    snprintf( title, TITLE_LEN, LIT( Sample_Data ), CurrSIOData->samp_file_name );
    info.text = title;
    info.info = &WPSampleInfo;
    info.extra = CurrSIOData;
//    info.colour = GetWndColours( class );
    info.title_size = STATUS_ROW + 1;
    info.style |= GUI_INIT_INVISIBLE;
    wnd = WndCreateWithStruct( &info );
    if( wnd == NULL ) return( wnd );
//    WndSetFontInfo( wnd, GetWndFont( wnd ) );
//-//    WndSetSysFont( wnd, B_TRUE );
    WndClrSwitches( wnd, WSW_MUST_CLICK_ON_PIECE|WSW_ONLY_MODIFY_TABSTOP );
    WndSetSwitches( wnd, WSW_RBUTTON_CHANGE_CURR );
    return( wnd );
}



STATIC void sampleOpenMainImage( void )
/*************************************/
{
    image_info      *curr_image;
    int             count;

    gatherSort( CurrSIOData );
    count = CurrSIOData->image_count;
    while( count-- > 0 ) {
        curr_image = CurrSIOData->images[count];
        if( curr_image->main_load ) {
            if( curr_image->dip_handle != NO_MOD && curr_image->mod_count > 2 ) {
                CurrSIOData->curr_image = curr_image;
                CurrSIOData->level_open = LEVEL_IMAGE;
                gatherSort( CurrSIOData );
            }
            break;
        }
    }
    WndNewCurrent( CurrSIOData->sample_window, 0, PIECE_DETAIL_NAME );
    WndDirty( CurrSIOData->sample_window );
}



STATIC bool sampleEventProc( a_window *wnd, gui_event gui_ev, void *parm )
/************************************************************************/
{
    sio_data        *curr_sio;

    parm=parm;
    switch( gui_ev ) {
    case GUI_INIT_WINDOW:
        return( TRUE );
    case GUI_FONT_CHANGED:
        WPSetRowHeight( wnd );
        return( TRUE );
    case GUI_RESIZE:
        WPAdjustRowHeight( wnd, B_FALSE );
        return( TRUE );
    case GUI_NOW_ACTIVE:
        curr_sio = WndExtra( wnd );
        curr_sio->curr_proc_row = -WND_MAX_ROW;
        curr_sio->curr_display_row = -WND_MAX_ROW;
        WPDipSetProc( curr_sio->dip_process );
        SetCurrentMAD( curr_sio->config.mad );
        CurrSIOData = curr_sio;
        return( TRUE );
    case WND_CURRENT_CHANGED:
        sampFixDirtyCurr( wnd );
        return( B_TRUE );
    case GUI_DESTROY:
        curr_sio = WndExtra( wnd );
        if( curr_sio != NULL ) {
            ClearSample( curr_sio );
        }
        return( B_FALSE );
    }
    return( B_FALSE );
}



STATIC bool sampleGetLine( a_window *wnd, wnd_row row, int piece,
                                        wnd_line_piece *line )
/*************************************************************/
{
    sio_data        *curr_sio;

    if( row <= -4  ) {
        return( sampleProcOverview( wnd, row, piece, line ) );
    }
    if( row == -3 ) {
        return( sampleProcTopStatus( wnd, row, piece, line ) );
    }
    if( row == -2  ) {
        return( sampleProcStatus( wnd, row, piece, line ) );
    }
    if( row == -1 ) {
        return( sampleProcBotStatus( wnd, row, piece, line ) );
    }
    curr_sio = WndExtra( wnd );
    if( !sampleGetRtns[curr_sio->level_open]( wnd, row ) ) return( B_FALSE );

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?