HPCToolkit
display.c
Go to the documentation of this file.
1 // -*-Mode: C++;-*- // technically C99
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // --------------------------------------------------------------------------
6 // Part of HPCToolkit (hpctoolkit.org)
7 //
8 // Information about sources of support for research and development of
9 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
10 // --------------------------------------------------------------------------
11 //
12 // Copyright ((c)) 2002-2019, Rice University
13 // All rights reserved.
14 //
15 // Redistribution and use in source and binary forms, with or without
16 // modification, are permitted provided that the following conditions are
17 // met:
18 //
19 // * Redistributions of source code must retain the above copyright
20 // notice, this list of conditions and the following disclaimer.
21 //
22 // * Redistributions in binary form must reproduce the above copyright
23 // notice, this list of conditions and the following disclaimer in the
24 // documentation and/or other materials provided with the distribution.
25 //
26 // * Neither the name of Rice University (RICE) nor the names of its
27 // contributors may be used to endorse or promote products derived from
28 // this software without specific prior written permission.
29 //
30 // This software is provided by RICE and contributors "as is" and any
31 // express or implied warranties, including, but not limited to, the
32 // implied warranties of merchantability and fitness for a particular
33 // purpose are disclaimed. In no event shall RICE or contributors be
34 // liable for any direct, indirect, incidental, special, exemplary, or
35 // consequential damages (including, but not limited to, procurement of
36 // substitute goods or services; loss of use, data, or profits; or
37 // business interruption) however caused and on any theory of liability,
38 // whether in contract, strict liability, or tort (including negligence
39 // or otherwise) arising in any way out of the use of this software, even
40 // if advised of the possibility of such damage.
41 //
42 // ******************************************************* EndRiceCopyright *
43 
44 
45 /******************************************************************************
46  * system includes
47  *****************************************************************************/
48 
49 #include <stdio.h>
50 #include <string.h>
51 #include <stdlib.h>
52 
53 
54 //******************************************************************************
55 // local header
56 //******************************************************************************
57 
58 #include "line_wrapping.h"
59 
60 
61 //******************************************************************************
62 // Constants
63 //******************************************************************************
64 
65 const int MAXBUF = 1024;
66 const int MAX_DESC_PER_LINE = 65;
67 const int MAX_EVENT_NAME = 15;
68 
69 static const char *line_double = "===========================================================================\n";
70 static const char *line_single = "---------------------------------------------------------------------------\n";
71 
72 static const char *newline = "\n";
73 
74 //******************************************************************************
75 // Local methods
76 //******************************************************************************
77 
78 static void
79 printw(FILE *output, const char *name, const char *desc)
80 {
81  char **line;
82  int *len;
83  char sdesc[MAX_DESC_PER_LINE];
84 
85  int lines = strwrap((char *)desc, MAX_DESC_PER_LINE, &line, &len);
86  if (lines == 0) {
87  fprintf(output, "%s\n", name);
88  } else {
89  for (int i=0; i<lines; i++) {
90  strncpy(sdesc, line[i], len[i]);
91  sdesc[len[i]] = '\0';
92  const char *name_ptr = " ";
93 
94  if (i == 0) {
95  int len = strlen(name);
96  if (len > MAX_EVENT_NAME) {
97  fprintf(output, "%s\n", name);
98  } else {
99  name_ptr = name;
100  }
101  }
102  fprintf(output, "%-*s %s\n", MAX_EVENT_NAME, name_ptr, sdesc);
103  }
104  free (line);
105  free (len);
106  }
107 }
108 
109 
110 //******************************************************************************
111 // Interfaces
112 //******************************************************************************
113 
114 void
115 display_line_single(FILE *output)
116 {
117  fprintf(output, line_single);
118 }
119 
120 void
121 display_line_double(FILE *output)
122 {
123  fprintf(output, line_double);
124 }
125 
126 void
127 display_header(FILE *output, const char *title)
128 {
129  display_line_double(output);
130  fprintf(output, "%s\n", title);
131  display_line_double(output);
132 }
133 
134 void
135 display_header_event(FILE *output)
136 {
137  fprintf(output, "Name\t\tDescription\n");
138  display_line_single(output);
139 }
140 
141 void
142 display_event_info(FILE *output, const char *event, const char *desc)
143 {
144  printw(output, event, desc);
145  fprintf(output, newline);
146 }
147 
int strwrap(char *s, int w, char ***line_ret, int **len_ret)
Definition: line_wrapping.c:60
static void printw(FILE *output, const char *name, const char *desc)
Definition: display.c:79
void MONITOR_EXT_WRAP_NAME() free(void *ptr)
const char * event
Definition: pmu_x86.h:55
void display_header_event(FILE *output)
Definition: display.c:135
const int MAXBUF
Definition: display.c:65
static const char * newline
Definition: display.c:72
void display_line_double(FILE *output)
Definition: display.c:121
void display_event_info(FILE *output, const char *event, const char *desc)
Definition: display.c:142
static const char * line_double
Definition: display.c:69
void display_line_single(FILE *output)
Definition: display.c:115
const int MAX_DESC_PER_LINE
Definition: display.c:66
static const char * line_single
Definition: display.c:70
void display_header(FILE *output, const char *title)
Definition: display.c:127
const int MAX_EVENT_NAME
Definition: display.c:67