annotate scripts/profiler/profexport.m @ 30564:796f54d4ddbf stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021. In all .txi and .texi files except gpl.txi and gpl.texi in the doc/liboctave and doc/interpreter directories, change the copyright to "Octave Project Developers", the same as used for other source files. Update copyright notices for 2022 (not done since 2019). For gpl.txi and gpl.texi, change the copyright notice to be "Free Software Foundation, Inc." and leave the date at 2007 only because this file only contains the text of the GPL, not anything created by the Octave Project Developers. Add Paul Thomas to contributors.in.
author John W. Eaton <jwe@octave.org>
date Tue, 28 Dec 2021 18:22:40 -0500
parents 363fb10055df
children 5d3faba0342e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30379
diff changeset
3 ## Copyright (C) 2015-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
7 ##
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
8 ## This file is part of Octave.
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24370
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24370
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 21795
diff changeset
13 ## (at your option) any later version.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
14 ##
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 21795
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 21795
diff changeset
18 ## GNU General Public License for more details.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
19 ##
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24370
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
25
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
26 ## -*- texinfo -*-
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
27 ## @deftypefn {} {} profexport (@var{dir})
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
28 ## @deftypefnx {} {} profexport (@var{dir}, @var{data})
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
29 ## @deftypefnx {} {} profexport (@var{dir}, @var{name})
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
30 ## @deftypefnx {} {} profexport (@var{dir}, @var{name}, @var{data})
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
31 ##
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
32 ## Export profiler data as HTML.
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
33 ##
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
34 ## Export the profiling data in @var{data} into a series of HTML files in
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
35 ## the folder @var{dir}. The initial file will be
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
36 ## @file{@var{data}/index.html}.
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
37 ##
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
38 ## If @var{name} is specified, it must be a string that contains a ``name''
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
39 ## for the profile being exported. This name is included in the HTML.
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
40 ##
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
41 ## The input @var{data} is the structure returned by @code{profile ("info")}.
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
42 ## If unspecified, @code{profexport} will use the current profile dataset.
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
43 ##
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
44 ## @seealso{profshow, profexplore, profile}
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
45 ## @end deftypefn
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
46
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
47 ## Built-in profiler.
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
48 function profexport (dir, name = "", data)
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
49
28789
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 27978
diff changeset
50 if (nargin < 1)
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
51 print_usage ();
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
52 endif
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
53
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
54 if (! ischar (dir))
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
55 error ("profexport: DIR must be a string");
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
56 endif
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
57
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
58 if (nargin == 1)
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
59 data = profile ("info");
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
60 elseif (nargin == 2)
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
61 if (isstruct (name))
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
62 data = name;
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
63 name = "";
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
64 else
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
65 if (! ischar (name))
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
66 error ("profexport: NAME must be a string");
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
67 endif
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
68 data = profile ("info");
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
69 endif
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
70 endif
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
71
25787
3293cd2651fb prefer 'isfolder' over 'exist (..., "dir")' in Octave functions
Mike Miller <mtmiller@octave.org>
parents: 25054
diff changeset
72 if (! isfolder (dir))
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
73 ok = mkdir (dir);
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
74 if (! ok)
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
75 error ("profexport: failed to create output directory '%s'", dir);
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
76 endif
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
77 endif
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
78
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
79 if (! copyfile (__dataFilename ("style.css"), dir))
28928
ae7ce8358953 maint: Add semicolon to end of all warning() and error() invocations.
Rik <rik@octave.org>
parents: 28896
diff changeset
80 error ("profexport: failed to copy data file to directory '%s'", dir);
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
81 endif
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
82
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
83 if (isempty (name))
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
84 name = "Profile";
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
85 else
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
86 name = ["Profile - " __escapeHtml(name)];
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
87 endif
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
88
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
89 __writeFlat (fullfile (dir, "index.html"), name, data.FunctionTable);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
90 for i = 1 : length (data.FunctionTable)
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
91 __writeFunc (fullfile (dir, sprintf ("func-%d.html", i)), name, ...
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
92 data.FunctionTable, i);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
93 endfor
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
94
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
95 top = struct ("name", "Top");
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
96 __writeHierarchical (dir, name, data.FunctionTable, ...
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
97 {top}, data.Hierarchical, 1);
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
98
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
99 endfunction
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
100
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
101 ################################################################################
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
102 ## Write flat profile.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
103
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
104 function __writeFlat (file, name, table)
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
105
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
106 template = __readTemplate ("flat.html");
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
107 entryTemplate = __readTemplate ("flat_entry.html");
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
108
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
109 ## Construct the entries string.
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
110 ## This follows the same logic that is used in profshow.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
111 times = [ table.TotalTime ];
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
112 totalTime = sum (times);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
113 [~, p] = sort (times, "descend");
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
114 entries = "";
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
115 for i = 1 : length (table)
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
116 row = table(p(i));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
117
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
118 cur = entryTemplate;
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
119 cur = strrep (cur, "%num", sprintf ("%d", p(i)));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
120 cur = strrep (cur, "%name", __escapeHtml (row.FunctionName));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
121 cur = strrep (cur, "%timeabs", sprintf ("%.3f", row.TotalTime));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
122 cur = strrep (cur, "%timerel", ...
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
123 sprintf ("%.2f", 100 * row.TotalTime / totalTime));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
124 cur = strrep (cur, "%calls", sprintf ("%d", row.NumCalls));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
125
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
126 entries = [entries, cur];
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
127 endfor
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
128
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
129 ## Build full page content.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
130 res = template;
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
131 res = strrep (res, "%title", name);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
132 res = strrep (res, "%entries", entries);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
133
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
134 ## Write out the file.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
135 __writeToFile (file, res);
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
136
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
137 endfunction
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
138
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
139 ################################################################################
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
140 ## Write "function profile" pages.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
141
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
142 function __writeFunc (file, name, table, ind)
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
143
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
144 template = __readTemplate ("function.html");
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
145 row = table(ind);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
146
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
147 ## Fill in basic data.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
148 res = template;
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
149 res = strrep (res, "%title", name);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
150 res = strrep (res, "%name", __escapeHtml (row.FunctionName));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
151 res = strrep (res, "%timeabs", sprintf ("%.3f", row.TotalTime));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
152 res = strrep (res, "%calls", sprintf ("%d", row.NumCalls));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
153
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
154 ## Build up attribute list.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
155 attr = "";
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
156 if (row.IsRecursive)
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
157 attr = "recursive";
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
158 endif
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
159 res = strrep (res, "%attr", attr);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
160
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
161 ## Add parent and child list.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
162 parents = __buildParentOrChildList (table, row.Parents);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
163 res = strrep (res, "%parents", parents);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
164 children = __buildParentOrChildList (table, row.Children);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
165 res = strrep (res, "%children", children);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
166
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
167 ## Write out the file.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
168 __writeToFile (file, res);
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
169
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
170 endfunction
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
171
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
172 function lst = __buildParentOrChildList (table, inds)
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
173
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
174 if (length (inds) == 0)
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
175 lst = "none";
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
176 return;
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
177 endif
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
178
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
179 template = "<a href='func-%num.html'>%name</a>";
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
180
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
181 lst = "";
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
182 for i = 1 : length (inds)
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
183 if (i > 1)
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
184 lst = [lst, ", "];
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
185 endif
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
186
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
187 cur = template;
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
188 cur = strrep (cur, "%num", sprintf ("%d", inds(i)));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
189 cur = strrep (cur, "%name", __escapeHtml (table(inds(i)).FunctionName));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
190 lst = [lst, cur];
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
191 endfor
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
192
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
193 endfunction
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
194
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
195 ################################################################################
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
196 ## Write a hierarchical profile page.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
197
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
198 ## In order to generate unique filenames for the pages, we keep a running
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
199 ## counter that is passed through and updated by the recursive calls.
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
200 ## The function returns two counter values: The one that is chosen
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
201 ## for its own page (so that parent nodes can link down to them)
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
202 ## and the next value to be passed to the next call.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
203
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
204 function [mine, cnt] = __writeHierarchical (dir, name, funcs, ...
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
205 parents, children, cnt)
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
206
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
207 template = __readTemplate ("hierarchical.html");
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
208 entryTemplate = __readTemplate ("hierarchical_entry.html");
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
209
28942
fc4bb4bd1d5e maint: Use '##' as lead-in for full-line comments.
Rik <rik@octave.org>
parents: 28928
diff changeset
210 ## Fill in basic data and parent breadcrumbs.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
211 res = template;
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
212 res = strrep (res, "%title", name);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
213 parentsStr = __hierarchicalParents (parents);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
214 res = strrep (res, "%parents", parentsStr);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
215
28942
fc4bb4bd1d5e maint: Use '##' as lead-in for full-line comments.
Rik <rik@octave.org>
parents: 28928
diff changeset
216 ## Set this page's counter and update parents struct with it.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
217 mine = cnt++;
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
218 parents{end}.cnt = mine;
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
219 file = sprintf ("%s/hierarchy-%d.html", dir, mine);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
220
28942
fc4bb4bd1d5e maint: Use '##' as lead-in for full-line comments.
Rik <rik@octave.org>
parents: 28928
diff changeset
221 ## Sort children by time.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
222 times = -[ children.TotalTime ];
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
223 [~, p] = sort (times);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
224 children = children(p);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
225
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
226 ## Recurse on children and construct entry list.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
227 entries = "";
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
228 for i = 1 : length (children)
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
229 cur = children(i);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
230 curName = funcs(cur.Index).FunctionName;
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
231
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
232 newParents = parents;
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
233 newParents{end + 1} = struct ("name", curName);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
234 [childCnt, cnt] = __writeHierarchical (dir, name, funcs, ...
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
235 newParents, cur.Children, cnt);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
236
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
237 str = entryTemplate;
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
238 str = strrep (str, "%cnt", sprintf ("%d", childCnt));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
239 str = strrep (str, "%name", __escapeHtml (curName));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
240 str = strrep (str, "%total", sprintf ("%.3f", cur.TotalTime));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
241 str = strrep (str, "%self", sprintf ("%.3f", cur.SelfTime));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
242 str = strrep (str, "%calls", sprintf ("%d", cur.NumCalls));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
243
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
244 entries = [entries, str];
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
245 endfor
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
246 res = strrep (res, "%entries", entries);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
247
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
248 ## Write out the file.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
249 __writeToFile (file, res);
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
250
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
251 endfunction
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
252
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
253 function str = __hierarchicalParents (parents)
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
254
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
255 ## We always have at least the "Top" entry!
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
256 assert (length (parents) > 0);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
257
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
258 template = "<a href='hierarchy-%cnt.html'>%name</a>";
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
259 lastTemplate = "<strong>%name</strong>";
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
260
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
261 str = "";
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
262 for i = 1 : length (parents) - 1
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
263 cur = template;
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
264 cur = strrep (cur, "%cnt", sprintf ("%d", parents{i}.cnt));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
265 cur = strrep (cur, "%name", __escapeHtml (parents{i}.name));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
266 str = [str, cur, " > "];
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
267 endfor
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
268
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
269 cur = lastTemplate;
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
270 cur = strrep (cur, "%name", __escapeHtml (parents{end}.name));
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
271 str = [str, cur];
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
272
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
273 endfunction
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
274
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
275 ################################################################################
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
276 ## General helper functions.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
277
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
278 function __writeToFile (file, str)
30379
363fb10055df maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29359
diff changeset
279
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
280 fid = fopen (file, "w");
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
281 if (fid < 0)
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
282 error ("profexport: failed to open '%s' for writing", file);
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
283 endif
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
284 fputs (fid, str);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
285 fclose (fid);
30379
363fb10055df maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29359
diff changeset
286
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
287 endfunction
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
288
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
289 function fn = __dataFilename (name)
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
290 etcdir = __octave_config_info__ ("octetcdir");
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
291 fn = fullfile (etcdir, "profiler", name);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
292 endfunction
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
293
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
294 function str = __readTemplate (name)
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
295 fn = __dataFilename (name);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
296 str = fileread (fn);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
297 endfunction
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
298
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
299 function str = __escapeHtml (str)
24370
b1d1229d9e83 maint: Use single quotes to simplify excessive backslash escapes in code.
Rik <rik@octave.org>
parents: 23220
diff changeset
300 str = strrep (str, '&', "&amp;");
b1d1229d9e83 maint: Use single quotes to simplify excessive backslash escapes in code.
Rik <rik@octave.org>
parents: 23220
diff changeset
301 str = strrep (str, '<', "&lt;");
b1d1229d9e83 maint: Use single quotes to simplify excessive backslash escapes in code.
Rik <rik@octave.org>
parents: 23220
diff changeset
302 str = strrep (str, '>', "&gt;");
b1d1229d9e83 maint: Use single quotes to simplify excessive backslash escapes in code.
Rik <rik@octave.org>
parents: 23220
diff changeset
303 str = strrep (str, '"', "&quot;");
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
304 endfunction
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
305
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
306 ################################################################################
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
307 ## Tests and demo.
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
308
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
309 %!demo
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
310 %! profile on;
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
311 %! A = rand (100);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
312 %! B = expm (A);
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
313 %! profile off;
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
314 %! dir = tempname ();
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
315 %! profexport (dir, "Example Profile");
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
316 %! open (fullfile (dir, "index.html"));
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
317
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
318 ## Test input validation
28896
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 28789
diff changeset
319 %!error <Invalid call> profexport ()
21794
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
320 %!error profexport (1)
807a86834a62 Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff changeset
321 %!error profexport (1, 2, 3, 4)
21795
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
322 %!error <DIR must be a string> profexport (5)
973c16f1c9fc profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 21794
diff changeset
323 %!error <NAME must be a string> profexport ("dir", 5)