Mercurial > octave
annotate scripts/profiler/profexport.m @ 23219:3ac9f9ecfae5 stable
maint: Update copyright dates.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 22 Feb 2017 12:39:29 -0500 |
parents | e9a0469dedd9 |
children | 092078913d54 |
rev | line source |
---|---|
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
1 ## Copyright (C) 2015-2017 Daniel Kraft |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
2 ## |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
3 ## This file is part of Octave. |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
4 ## |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify it |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
8 ## your option) any later version. |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
9 ## |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
10 ## 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
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
13 ## General Public License for more details. |
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 ## 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
|
16 ## along with Octave; see the file COPYING. If not, see |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
18 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
20 ## @deftypefn {} {} profexport (@var{dir}) |
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
21 ## @deftypefnx {} {} profexport (@var{dir}, @var{data}) |
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
22 ## @deftypefnx {} {} profexport (@var{dir}, @var{name}) |
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
23 ## @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
|
24 ## |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
25 ## Export profiler data as HTML. |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
26 ## |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
27 ## 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
|
28 ## 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
|
29 ## @file{@var{data}/index.html}. |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
30 ## |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
31 ## 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
|
32 ## 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
|
33 ## |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
34 ## 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
|
35 ## 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
|
36 ## |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
37 ## @seealso{profshow, profexplore, profile} |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
38 ## @end deftypefn |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
39 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
40 ## Built-in profiler. |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
41 ## Author: Daniel Kraft <dkraft@google.com> |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
42 |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
43 function profexport (dir, name = "", data) |
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
44 |
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
45 if (nargin < 1 || nargin > 3) |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
46 print_usage (); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
47 endif |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
48 |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
49 if (! ischar (dir)) |
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
50 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
|
51 endif |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
52 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
53 if (nargin == 1) |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
54 data = profile ("info"); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
55 elseif (nargin == 2) |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
56 if (isstruct (name)) |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
57 data = name; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
58 name = ""; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
59 else |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
60 if (! ischar (name)) |
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
61 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
|
62 endif |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
63 data = profile ("info"); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
64 endif |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
65 endif |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
66 |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
67 if (! exist (dir, "dir")) |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
68 ok = mkdir (dir); |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
69 if (! ok) |
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
70 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
|
71 endif |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
72 endif |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
73 |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
74 if (! copyfile (__dataFilename ("style.css"), dir)) |
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
75 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
|
76 endif |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
77 |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
78 if (isempty (name)) |
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
79 name = "Profile"; |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
80 else |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
81 name = ["Profile - " __escapeHtml(name)]; |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
82 endif |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
83 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
84 __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
|
85 for i = 1 : length (data.FunctionTable) |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
86 __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
|
87 data.FunctionTable, i); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
88 endfor |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
89 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
90 top = struct ("name", "Top"); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
91 __writeHierarchical (dir, name, data.FunctionTable, ... |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
92 {top}, data.Hierarchical, 1); |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
93 |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
94 endfunction |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
95 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
96 ################################################################################ |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
97 ## Write flat profile. |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
98 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
99 function __writeFlat (file, name, table) |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
100 |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
101 template = __readTemplate ("flat.html"); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
102 entryTemplate = __readTemplate ("flat_entry.html"); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
103 |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
104 ## Construct the entries string. |
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
105 ## 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
|
106 times = [ table.TotalTime ]; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
107 totalTime = sum (times); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
108 [~, p] = sort (times, "descend"); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
109 entries = ""; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
110 for i = 1 : length (table) |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
111 row = table(p(i)); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
112 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
113 cur = entryTemplate; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
114 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
|
115 cur = strrep (cur, "%name", __escapeHtml (row.FunctionName)); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
116 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
|
117 cur = strrep (cur, "%timerel", ... |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
118 sprintf ("%.2f", 100 * row.TotalTime / totalTime)); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
119 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
|
120 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
121 entries = [entries, cur]; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
122 endfor |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
123 |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
124 ## Build full page content. |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
125 res = template; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
126 res = strrep (res, "%title", name); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
127 res = strrep (res, "%entries", entries); |
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 ## Write out the file. |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
130 __writeToFile (file, res); |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
131 |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
132 endfunction |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
133 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
134 ################################################################################ |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
135 ## Write "function profile" pages. |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
136 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
137 function __writeFunc (file, name, table, ind) |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
138 |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
139 template = __readTemplate ("function.html"); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
140 row = table(ind); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
141 |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
142 ## Fill in basic data. |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
143 res = template; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
144 res = strrep (res, "%title", name); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
145 res = strrep (res, "%name", __escapeHtml (row.FunctionName)); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
146 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
|
147 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
|
148 |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
149 ## Build up attribute list. |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
150 attr = ""; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
151 if (row.IsRecursive) |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
152 attr = "recursive"; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
153 endif |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
154 res = strrep (res, "%attr", attr); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
155 |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
156 ## Add parent and child list. |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
157 parents = __buildParentOrChildList (table, row.Parents); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
158 res = strrep (res, "%parents", parents); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
159 children = __buildParentOrChildList (table, row.Children); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
160 res = strrep (res, "%children", children); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
161 |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
162 ## Write out the file. |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
163 __writeToFile (file, res); |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
164 |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
165 endfunction |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
166 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
167 function lst = __buildParentOrChildList (table, inds) |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
168 |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
169 if (length (inds) == 0) |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
170 lst = "none"; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
171 return; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
172 endif |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
173 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
174 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
|
175 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
176 lst = ""; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
177 for i = 1 : length (inds) |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
178 if (i > 1) |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
179 lst = [lst, ", "]; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
180 endif |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
181 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
182 cur = template; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
183 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
|
184 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
|
185 lst = [lst, cur]; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
186 endfor |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
187 |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
188 endfunction |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
189 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
190 ################################################################################ |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
191 ## Write a hierarchical profile page. |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
192 |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
193 ## 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
|
194 ## 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
|
195 ## 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
|
196 ## 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
|
197 ## 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
|
198 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
199 function [mine, cnt] = __writeHierarchical (dir, name, funcs, ... |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
200 parents, children, cnt) |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
201 |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
202 template = __readTemplate ("hierarchical.html"); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
203 entryTemplate = __readTemplate ("hierarchical_entry.html"); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
204 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
205 % Fill in basic data and parent breadcrumbs. |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
206 res = template; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
207 res = strrep (res, "%title", name); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
208 parentsStr = __hierarchicalParents (parents); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
209 res = strrep (res, "%parents", parentsStr); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
210 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
211 % Set this page's counter and update parents struct with it. |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
212 mine = cnt++; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
213 parents{end}.cnt = mine; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
214 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
|
215 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
216 % Sort children by time. |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
217 times = -[ children.TotalTime ]; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
218 [~, p] = sort (times); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
219 children = children(p); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
220 |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
221 ## 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
|
222 entries = ""; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
223 for i = 1 : length (children) |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
224 cur = children(i); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
225 curName = funcs(cur.Index).FunctionName; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
226 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
227 newParents = parents; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
228 newParents{end + 1} = struct ("name", curName); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
229 [childCnt, cnt] = __writeHierarchical (dir, name, funcs, ... |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
230 newParents, cur.Children, cnt); |
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 str = entryTemplate; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
233 str = strrep (str, "%cnt", sprintf ("%d", childCnt)); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
234 str = strrep (str, "%name", __escapeHtml (curName)); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
235 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
|
236 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
|
237 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
|
238 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
239 entries = [entries, str]; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
240 endfor |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
241 res = strrep (res, "%entries", entries); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
242 |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
243 ## Write out the file. |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
244 __writeToFile (file, res); |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
245 |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
246 endfunction |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
247 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
248 function str = __hierarchicalParents (parents) |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
249 |
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
250 ## 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
|
251 assert (length (parents) > 0); |
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 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
|
254 lastTemplate = "<strong>%name</strong>"; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
255 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
256 str = ""; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
257 for i = 1 : length (parents) - 1 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
258 cur = template; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
259 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
|
260 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
|
261 str = [str, cur, " > "]; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
262 endfor |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
263 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
264 cur = lastTemplate; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
265 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
|
266 str = [str, cur]; |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
267 |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
268 endfunction |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
269 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
270 ################################################################################ |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
271 ## General helper functions. |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
272 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
273 function __writeToFile (file, str) |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
274 fid = fopen (file, "w"); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
275 if (fid < 0) |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
276 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
|
277 endif |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
278 fputs (fid, str); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
279 fclose (fid); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
280 endfunction |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
281 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
282 function fn = __dataFilename (name) |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
283 etcdir = __octave_config_info__ ("octetcdir"); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
284 fn = fullfile (etcdir, "profiler", name); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
285 endfunction |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
286 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
287 function str = __readTemplate (name) |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
288 fn = __dataFilename (name); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
289 str = fileread (fn); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
290 endfunction |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
291 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
292 function str = __escapeHtml (str) |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
293 str = strrep (str, "&", "&"); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
294 str = strrep (str, "<", "<"); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
295 str = strrep (str, ">", ">"); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
296 str = strrep (str, "\"", """); |
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 ################################################################################ |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
300 ## Tests and demo. |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
301 |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
302 %!demo |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
303 %! profile on; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
304 %! A = rand (100); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
305 %! B = expm (A); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
306 %! profile off; |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
307 %! dir = tempname (); |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
308 %! profexport (dir, "Example Profile"); |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
309 %! open (fullfile (dir, "index.html")); |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
310 |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
311 ## Test input validation |
21794
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
312 %!error profexport () |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
313 %!error profexport (1) |
807a86834a62
Add profexport to write profiler output as HTML.
Daniel Kraft <dkraft@google.com>
parents:
diff
changeset
|
314 %!error profexport (1, 2, 3, 4) |
21795
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
315 %!error <DIR must be a string> profexport (5) |
973c16f1c9fc
profexport.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
21794
diff
changeset
|
316 %!error <NAME must be a string> profexport ("dir", 5) |