Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-27 Thread Xin Liu
On Tue, 27 Oct 2020 17:08:18 GMT, Xin Liu  wrote:

>> Nick Gasson has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   Update for review comments
>
> src/hotspot/share/code/codeCache.cpp line 1566:
> 
>> 1564: 
>> 1565:   char fname[32];
>> 1566:   jio_snprintf(fname, sizeof(fname), "/tmp/perf-%d.map", 
>> os::current_process_id());
> 
> if you don't use #ifdef LINUX, this line needs a cross-platform temp.

I would like to take back this. I've seen that `CodeCache::write_perf_map` is 
wrapped by #ifdef LINUX. 
I read the older revision of change.

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-27 Thread Xin Liu
On Wed, 21 Oct 2020 09:13:08 GMT, Nick Gasson  wrote:

>> When using the Linux "perf" tool to do system profiling, symbol names of
>> running Java methods cannot be decoded, resulting in unhelpful output
>> such as:
>> 
>>   10.52% [JIT] tid 236748 [.] 0x7f6fdb75d223
>> 
>> Perf can read a simple text file format describing the mapping between
>> address ranges and symbol names for a particular process [1].
>> 
>> It's possible to generate this already for Java processes using a JVMTI
>> plugin such as perf-map-agent [2]. However this requires compiling
>> third-party code and then loading the agent into your Java process. It
>> would be more convenient if Hotspot could write this file directly using
>> a diagnostic command. The information required is almost identical to
>> that of the existing Compiler.codelist command.
>> 
>> This patch adds a Compiler.perfmap diagnostic command on Linux only. To
>> use, first run "jcmd  Compiler.perfmap" and then "perf top" or
>> "perf record" and the report should show decoded Java symbol names for
>> that process.
>> 
>> As this just writes a snapshot of the code cache when the command is
>> run, it will become stale if methods are compiled later or unloaded.
>> However this shouldn't be a big problem in practice if the map file is
>> generated after the application has warmed up.
>> 
>> [1] 
>> https://github.com/torvalds/linux/blob/master/tools/perf/Documentation/jit-interface.txt
>> [2] https://github.com/jvm-profiling-tools/perf-map-agent
>
> Nick Gasson has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Update for review comments

src/hotspot/share/code/codeCache.cpp line 1566:

> 1564: 
> 1565:   char fname[32];
> 1566:   jio_snprintf(fname, sizeof(fname), "/tmp/perf-%d.map", 
> os::current_process_id());

if you don't use #ifdef LINUX, this line needs a cross-platform temp.

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-26 Thread David Holmes
On Mon, 26 Oct 2020 06:10:52 GMT, Nick Gasson  wrote:

>>> 
>>> 1. Like Alexey, I would really wish for an print-at-exit switch. The 
>>> common naming seems to be xxxAtExit (so not, OnExit). "PrintXxx" seems to 
>>> be printing stuff out to tty, "DumpXxxx" for writing separate files (e.g. 
>>> CDS map). So I would name it DumpPerfMapAtExit.
>>> 
>> 
>> OK, makes sense.
>> 
>>> 2. Dumping to /tmp is unexpected for me, I would prefer if the default 
>>> were dumping to the current directory. That seems to be the default for 
>>> other files too (cds map, hs-err file etc).
>>> 
>>> 3. Not necessary but nice would be a an option to specify location of 
>>> the dump file.
>>> 
>> 
>> The `/tmp/perf-.map` is hardcoded into perf though ([see 
>> here](https://github.com/torvalds/linux/blob/master/tools/perf/util/map.c#L155)),
>>  so I don't think it's useful for the user to be able to change the location.
>
>> 
>> I think we should use this option carefully because nmethod might be 
>> unloaded. So we should use this with `-XX:-UseCodeCacheFlushing`.
>> 
> 
> Thanks for the information. `-XX:+DumpPerfMapAtExit` will turn on 
> `UseCodeCacheFlushing` if it's set to default.

I don't see any reason for this to be a product flag, rather than diagnostic.

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-26 Thread Nick Gasson
On Wed, 21 Oct 2020 18:03:11 GMT, Chris Plummer  wrote:

>> Nick Gasson has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   Update for review comments
>
> src/hotspot/share/code/codeCache.cpp line 1582:
> 
>> 1580:   cb->is_compiled() ? 
>> cb->as_compiled_method()->method()->external_name()
>> 1581: : cb->name();
>> 1582: fs.print_cr(INTPTR_FORMAT " " INTPTR_FORMAT " %s",
> 
> Indentation isn't right.

Do you mean how the arguments are lined up on the continuation line below?

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-26 Thread Nick Gasson
On Thu, 22 Oct 2020 07:09:47 GMT, Nick Gasson  wrote:

>> Hi Nick,
>> 
>> this is a very useful idea! I missed this in the past.
>> 
>> Some remarks. I'll try to keep bikeshedding to a minimum since you already 
>> have enough input. Mostly ergonomics.
>> 
>> 1) Like Alexey, I would really wish for an print-at-exit switch. The common 
>> naming seems to be xxxAtExit (so not, OnExit). "PrintXxx" seems to be 
>> printing stuff out to tty, "DumpXxxx" for writing separate files (e.g. CDS 
>> map). So I would name it DumpPerfMapAtExit.
>> 
>> 2) Dumping to /tmp is unexpected for me, I would prefer if the default were 
>> dumping to the current directory. That seems to be the default for other 
>> files too (cds map, hs-err file etc).
>> 
>> 3) Not necessary but nice would be a an option to specify location of the 
>> dump file.
>> 
>> 4) I think it would be nice to have these switches always available, so real 
>> product switches. Which would require you to write up a small CSR but I 
>> still think it would make sense.
>> 
>> Cheers, Thomas
>
>> 
>> 1. Like Alexey, I would really wish for an print-at-exit switch. The 
>> common naming seems to be xxxAtExit (so not, OnExit). "PrintXxx" seems to be 
>> printing stuff out to tty, "DumpXxxx" for writing separate files (e.g. CDS 
>> map). So I would name it DumpPerfMapAtExit.
>> 
> 
> OK, makes sense.
> 
>> 2. Dumping to /tmp is unexpected for me, I would prefer if the default 
>> were dumping to the current directory. That seems to be the default for 
>> other files too (cds map, hs-err file etc).
>> 
>> 3. Not necessary but nice would be a an option to specify location of 
>> the dump file.
>> 
> 
> The `/tmp/perf-.map` is hardcoded into perf though ([see 
> here](https://github.com/torvalds/linux/blob/master/tools/perf/util/map.c#L155)),
>  so I don't think it's useful for the user to be able to change the location.

> 
> I think we should use this option carefully because nmethod might be 
> unloaded. So we should use this with `-XX:-UseCodeCacheFlushing`.
> 

Thanks for the information. `-XX:+DumpPerfMapAtExit` will turn on 
`UseCodeCacheFlushing` if it's set to default.

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-26 Thread Nick Gasson
On Thu, 22 Oct 2020 02:06:25 GMT, Yasumasa Suenaga  wrote:

>> Nick Gasson has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   Update for review comments
>
> src/hotspot/share/code/codeCache.cpp line 1571:
> 
>> 1569:   if (!fs.is_open()) {
>> 1570: log_warning(codecache)("Failed to create %s for perf map", fname);
>> 1571: st->print_cr("Failed to create %s", fname);
> 
> `st->print_cr()` is still needed? and also I've intended to replace all 
> `print_cr()` to UL (L1587)

It's gone now.

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-22 Thread Nick Gasson
On Thu, 22 Oct 2020 05:00:10 GMT, Thomas Stuefe  wrote:

> 
> 1. Like Alexey, I would really wish for an print-at-exit switch. The 
> common naming seems to be xxxAtExit (so not, OnExit). "PrintXxx" seems to be 
> printing stuff out to tty, "DumpXxxx" for writing separate files (e.g. CDS 
> map). So I would name it DumpPerfMapAtExit.
> 

OK, makes sense.

> 2. Dumping to /tmp is unexpected for me, I would prefer if the default 
> were dumping to the current directory. That seems to be the default for other 
> files too (cds map, hs-err file etc).
> 
> 3. Not necessary but nice would be a an option to specify location of the 
> dump file.
> 

The `/tmp/perf-.map` is hardcoded into perf though ([see 
here](https://github.com/torvalds/linux/blob/master/tools/perf/util/map.c#L155)),
 so I don't think it's useful for the user to be able to change the location.

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-22 Thread Nick Gasson
On Thu, 22 Oct 2020 04:57:18 GMT, Thomas Stuefe  wrote:

>> Nick Gasson has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   Update for review comments
>
> src/hotspot/share/code/codeCache.hpp line 194:
> 
>> 192:   static void print_summary(outputStream* st, bool detailed = true); // 
>> Prints a summary of the code cache usage
>> 193:   static void log_state(outputStream* st);
>> 194:   static void write_perf_map(outputStream* st);
> 
> Seems weird for this function to have an outputStream parameter only to write 
> the dump to an unrelated file and ignore the stream for everything but the 
> final message.
> 
> I would either pass in the file name as an option - preferably configurable - 
> and write the last message out here; or just write the whole perf dump to the 
> outputstream itself, piping it to jcmd and let the caller do what he wants 
> with it (e.g. just redirecting). The latter is what most commands do. Not 
> sure how large the perf dump gets though, may be impractical.

OK. I think I'll change it so `write_perf_map()` writes to the `outputStream` 
and then `PerfMapDCmd::execute()` handles redirecting it to a file. I don't 
think it makes sense to write it directly to the jcmd output though.

> src/hotspot/share/code/codeCache.cpp line 1562:
> 
>> 1560: }
>> 1561: 
>> 1562: void CodeCache::write_perf_map(outputStream* st) {
> 
> Could this whole function possibly live inside os/linux in an own file? Or 
> would that expose too many code heap internals?

Probably creates too much dependency between the os layer and the codeCache 
internals? I'll put it all in `#ifdef LINUX` though.

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-22 Thread Nick Gasson
On Wed, 21 Oct 2020 17:57:46 GMT, Chris Plummer  wrote:

>> I'm not sure, I didn't want to add too much `#ifdef` mess. The code will 
>> compile on other platforms, it just won't be called. Better to add `#ifdef`s 
>> around all of it?
>
> Any reason not to have this dcmd supported on all platforms even though the 
> output is really targeted for use with the perf tool on linux? Would a user 
> ever have any other use for the output other than with the perf tool on linux?

@plummercj I'm not sure: it's just a text file so could be easily consumed by 
tools other than perf. But I'm not aware of any tools on other platforms that 
could use it.

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-21 Thread Thomas Stuefe
On Wed, 21 Oct 2020 09:13:08 GMT, Nick Gasson  wrote:

>> When using the Linux "perf" tool to do system profiling, symbol names of
>> running Java methods cannot be decoded, resulting in unhelpful output
>> such as:
>> 
>>   10.52% [JIT] tid 236748 [.] 0x7f6fdb75d223
>> 
>> Perf can read a simple text file format describing the mapping between
>> address ranges and symbol names for a particular process [1].
>> 
>> It's possible to generate this already for Java processes using a JVMTI
>> plugin such as perf-map-agent [2]. However this requires compiling
>> third-party code and then loading the agent into your Java process. It
>> would be more convenient if Hotspot could write this file directly using
>> a diagnostic command. The information required is almost identical to
>> that of the existing Compiler.codelist command.
>> 
>> This patch adds a Compiler.perfmap diagnostic command on Linux only. To
>> use, first run "jcmd  Compiler.perfmap" and then "perf top" or
>> "perf record" and the report should show decoded Java symbol names for
>> that process.
>> 
>> As this just writes a snapshot of the code cache when the command is
>> run, it will become stale if methods are compiled later or unloaded.
>> However this shouldn't be a big problem in practice if the map file is
>> generated after the application has warmed up.
>> 
>> [1] 
>> https://github.com/torvalds/linux/blob/master/tools/perf/Documentation/jit-interface.txt
>> [2] https://github.com/jvm-profiling-tools/perf-map-agent
>
> Nick Gasson has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Update for review comments

Hi Nick,

this is a very useful idea! I missed this in the past.

Some remarks. I'll try to keep bikeshedding to a minimum since you already have 
enough input. Mostly ergonomics.

1) Like Alexey, I would really wish for an print-at-exit switch. The common 
naming seems to be xxxAtExit (so not, OnExit). "PrintXxx" seems to be printing 
stuff out to tty, "DumpXxxx" for writing separate files (e.g. CDS map). So I 
would name it DumpPerfMapAtExit.

2) Dumping to /tmp is unexpected for me, I would prefer if the default were 
dumping to the current directory. That seems to be the default for other files 
too (cds map, hs-err file etc).

3) Not necessary but nice would be a an option to specify location of the dump 
file.

4) I think it would be nice to have these switches always available, so real 
product switches. Which would require you to write up a small CSR but I still 
think it would make sense.

Cheers, Thomas

src/hotspot/share/code/codeCache.hpp line 194:

> 192:   static void print_summary(outputStream* st, bool detailed = true); // 
> Prints a summary of the code cache usage
> 193:   static void log_state(outputStream* st);
> 194:   static void write_perf_map(outputStream* st);

Seems weird for this function to have an outputStream parameter only to write 
the dump to an unrelated file and ignore the stream for everything but the 
final message.

I would either pass in the file name as an option - preferably configurable - 
and write the last message out here; or just write the whole perf dump to the 
outputstream itself, piping it to jcmd and let the caller do what he wants with 
it (e.g. just redirecting). The latter is what most commands do. Not sure how 
large the perf dump gets though, may be impractical.

src/hotspot/share/code/codeCache.cpp line 1562:

> 1560: }
> 1561: 
> 1562: void CodeCache::write_perf_map(outputStream* st) {

Could this whole function possibly live inside os/linux in an own file? Or 
would that expose too many code heap internals?

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-21 Thread Yasumasa Suenaga
On Wed, 21 Oct 2020 09:13:08 GMT, Nick Gasson  wrote:

>> When using the Linux "perf" tool to do system profiling, symbol names of
>> running Java methods cannot be decoded, resulting in unhelpful output
>> such as:
>> 
>>   10.52% [JIT] tid 236748 [.] 0x7f6fdb75d223
>> 
>> Perf can read a simple text file format describing the mapping between
>> address ranges and symbol names for a particular process [1].
>> 
>> It's possible to generate this already for Java processes using a JVMTI
>> plugin such as perf-map-agent [2]. However this requires compiling
>> third-party code and then loading the agent into your Java process. It
>> would be more convenient if Hotspot could write this file directly using
>> a diagnostic command. The information required is almost identical to
>> that of the existing Compiler.codelist command.
>> 
>> This patch adds a Compiler.perfmap diagnostic command on Linux only. To
>> use, first run "jcmd  Compiler.perfmap" and then "perf top" or
>> "perf record" and the report should show decoded Java symbol names for
>> that process.
>> 
>> As this just writes a snapshot of the code cache when the command is
>> run, it will become stale if methods are compiled later or unloaded.
>> However this shouldn't be a big problem in practice if the map file is
>> generated after the application has warmed up.
>> 
>> [1] 
>> https://github.com/torvalds/linux/blob/master/tools/perf/Documentation/jit-interface.txt
>> [2] https://github.com/jvm-profiling-tools/perf-map-agent
>
> Nick Gasson has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Update for review comments

src/hotspot/share/code/codeCache.cpp line 1571:

> 1569:   if (!fs.is_open()) {
> 1570: log_warning(codecache)("Failed to create %s for perf map", fname);
> 1571: st->print_cr("Failed to create %s", fname);

`st->print_cr()` is still needed? and also I've intended to replace all 
`print_cr()` to UL (L1587)

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-21 Thread Vicente Romero
On Thu, 22 Oct 2020 01:24:20 GMT, Yasumasa Suenaga  wrote:

>>> 
>>> Because it seems that for the short jobs, we would like to just do "perf 
>>> record java -XX:+WhatEver", followed by "perf report", without requiring 
>>> user to invoke the diagnostic command while JVM is still running?
>> 
>> Yes that sounds like a good idea. Add a (diagnostic?) option 
>> `-XX:+WritePerfMapOnExit`?
>
>> Yes that sounds like a good idea. Add a (diagnostic?) option 
>> `-XX:+WritePerfMapOnExit`?
> 
> I think we should use this option carefully because nmethod might be 
> unloaded. So we should use this with `-XX:-UseCodeCacheFlushing`.
> 
> BTW we can use `Compiler.codelist` dcmd for this purpose now. If you 
> implement `WritePerfMapOnExit`, we should consider code cache flushing and 
> should use `Compiler.codelist` in some case. I've published perfmap generator 
> from `Compiler.codelist` https://github.com/YaSuenag/saperf

\label remove compiler

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-21 Thread Yasumasa Suenaga
On Wed, 21 Oct 2020 09:09:49 GMT, Nick Gasson  wrote:

> Yes that sounds like a good idea. Add a (diagnostic?) option 
> `-XX:+WritePerfMapOnExit`?

I think we should use this option carefully because nmethod might be unloaded. 
So we should use this with `-XX:-UseCodeCacheFlushing`.

BTW we can use `Compiler.codelist` dcmd for this purpose now. If you implement 
`WritePerfMapOnExit`, we should consider code cache flushing and should use 
`Compiler.codelist` in some case. I've published perfmap generator from 
`Compiler.codelist` https://github.com/YaSuenag/saperf

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-21 Thread Serguei Spitsyn
On Wed, 21 Oct 2020 21:00:01 GMT, Serguei Spitsyn  wrote:

>> Any reason not to have this dcmd supported on all platforms even though the 
>> output is really targeted for use with the perf tool on linux? Would a user 
>> ever have any other use for the output other than with the perf tool on 
>> linux?
>
> +#ifdef LINUX
> +  DCmdFactory::register_DCmdFactory(new 
> DCmdFactoryImpl(full_export, true, false));
> +#endif // LINUX
> 
> If this PR is for Linux only then I wonder if all changes have to be ifdef'ed 
> the same or similar way.

Sorry, I've overlooked that @YaSuenag posted similar comment.

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-21 Thread Serguei Spitsyn
On Wed, 21 Oct 2020 17:57:46 GMT, Chris Plummer  wrote:

>> I'm not sure, I didn't want to add too much `#ifdef` mess. The code will 
>> compile on other platforms, it just won't be called. Better to add `#ifdef`s 
>> around all of it?
>
> Any reason not to have this dcmd supported on all platforms even though the 
> output is really targeted for use with the perf tool on linux? Would a user 
> ever have any other use for the output other than with the perf tool on linux?

+#ifdef LINUX
+  DCmdFactory::register_DCmdFactory(new 
DCmdFactoryImpl(full_export, true, false));
+#endif // LINUX

If this PR is for Linux only then I wonder if all changes have to be ifdef'ed 
the same or similar way.

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-21 Thread Chris Plummer
On Wed, 21 Oct 2020 09:13:08 GMT, Nick Gasson  wrote:

>> When using the Linux "perf" tool to do system profiling, symbol names of
>> running Java methods cannot be decoded, resulting in unhelpful output
>> such as:
>> 
>>   10.52% [JIT] tid 236748 [.] 0x7f6fdb75d223
>> 
>> Perf can read a simple text file format describing the mapping between
>> address ranges and symbol names for a particular process [1].
>> 
>> It's possible to generate this already for Java processes using a JVMTI
>> plugin such as perf-map-agent [2]. However this requires compiling
>> third-party code and then loading the agent into your Java process. It
>> would be more convenient if Hotspot could write this file directly using
>> a diagnostic command. The information required is almost identical to
>> that of the existing Compiler.codelist command.
>> 
>> This patch adds a Compiler.perfmap diagnostic command on Linux only. To
>> use, first run "jcmd  Compiler.perfmap" and then "perf top" or
>> "perf record" and the report should show decoded Java symbol names for
>> that process.
>> 
>> As this just writes a snapshot of the code cache when the command is
>> run, it will become stale if methods are compiled later or unloaded.
>> However this shouldn't be a big problem in practice if the map file is
>> generated after the application has warmed up.
>> 
>> [1] 
>> https://github.com/torvalds/linux/blob/master/tools/perf/Documentation/jit-interface.txt
>> [2] https://github.com/jvm-profiling-tools/perf-map-agent
>
> Nick Gasson has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Update for review comments

src/hotspot/share/code/codeCache.cpp line 1582:

> 1580:   cb->is_compiled() ? 
> cb->as_compiled_method()->method()->external_name()
> 1581: : cb->name();
> 1582: fs.print_cr(INTPTR_FORMAT " " INTPTR_FORMAT " %s",

Indentation isn't right.

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-21 Thread Chris Plummer
On Wed, 21 Oct 2020 09:08:06 GMT, Nick Gasson  wrote:

>> src/hotspot/share/code/codeCache.cpp line 1562:
>> 
>>> 1560: }
>>> 1561: 
>>> 1562: void CodeCache::write_perf_map(outputStream* st) {
>> 
>> Should this code (and changes in header files) be included for Linux only? 
>> (`#ifdef LINUX` like the change in diagnosticCommand.cpp)
>
> I'm not sure, I didn't want to add too much `#ifdef` mess. The code will 
> compile on other platforms, it just won't be called. Better to add `#ifdef`s 
> around all of it?

Any reason not to have this dcmd supported on all platforms even though the 
output is really targeted for use with the perf tool on linux? Would a user 
ever have any other use for the output other than with the perf tool on linux?

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-21 Thread Nick Gasson
On Wed, 21 Oct 2020 04:34:44 GMT, Yasumasa Suenaga  wrote:

>> Nick Gasson has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   Update for review comments
>
> src/hotspot/share/code/codeCache.cpp line 1562:
> 
>> 1560: }
>> 1561: 
>> 1562: void CodeCache::write_perf_map(outputStream* st) {
> 
> Should this code (and changes in header files) be included for Linux only? 
> (`#ifdef LINUX` like the change in diagnosticCommand.cpp)

I'm not sure, I didn't want to add too much `#ifdef` mess. The code will 
compile on other platforms, it just won't be called. Better to add `#ifdef`s 
around all of it?

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-21 Thread Nick Gasson
On Tue, 20 Oct 2020 11:43:17 GMT, Vladimir Sitnikov 
 wrote:

>> Nick Gasson has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   Update for review comments
>
> test/hotspot/jtreg/serviceability/dcmd/compiler/PerfMapTest.java line 68:
> 
>> 66: Matcher m = outputPattern.matcher(line);
>> 67: 
>> 68: Assert.assertTrue(m.matches(), "Did not print map file name");
> 
> Suggestion:
> 
> Assert.assertTrue(m.matches(), "Did not print map file name, line = " 
> + line);

Done, thanks.

-

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-21 Thread Nick Gasson
> When using the Linux "perf" tool to do system profiling, symbol names of
> running Java methods cannot be decoded, resulting in unhelpful output
> such as:
> 
>   10.52% [JIT] tid 236748 [.] 0x7f6fdb75d223
> 
> Perf can read a simple text file format describing the mapping between
> address ranges and symbol names for a particular process [1].
> 
> It's possible to generate this already for Java processes using a JVMTI
> plugin such as perf-map-agent [2]. However this requires compiling
> third-party code and then loading the agent into your Java process. It
> would be more convenient if Hotspot could write this file directly using
> a diagnostic command. The information required is almost identical to
> that of the existing Compiler.codelist command.
> 
> This patch adds a Compiler.perfmap diagnostic command on Linux only. To
> use, first run "jcmd  Compiler.perfmap" and then "perf top" or
> "perf record" and the report should show decoded Java symbol names for
> that process.
> 
> As this just writes a snapshot of the code cache when the command is
> run, it will become stale if methods are compiled later or unloaded.
> However this shouldn't be a big problem in practice if the map file is
> generated after the application has warmed up.
> 
> [1] 
> https://github.com/torvalds/linux/blob/master/tools/perf/Documentation/jit-interface.txt
> [2] https://github.com/jvm-profiling-tools/perf-map-agent

Nick Gasson has updated the pull request incrementally with one additional 
commit since the last revision:

  Update for review comments

-

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/760/files
  - new: https://git.openjdk.java.net/jdk/pull/760/files/5b0c2695..a3cb0ed4

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk=760=01
 - incr: https://webrevs.openjdk.java.net/?repo=jdk=760=00-01

  Stats: 16 lines in 3 files changed: 1 ins; 2 del; 13 mod
  Patch: https://git.openjdk.java.net/jdk/pull/760.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/760/head:pull/760

PR: https://git.openjdk.java.net/jdk/pull/760


Re: RFR: 8254723: add diagnostic command to write Linux perf map file [v2]

2020-10-21 Thread Nick Gasson
On Tue, 20 Oct 2020 10:52:27 GMT, Aleksey Shipilev  wrote:

> 
> Because it seems that for the short jobs, we would like to just do "perf 
> record java -XX:+WhatEver", followed by "perf report", without requiring user 
> to invoke the diagnostic command while JVM is still running?

Yes that sounds like a good idea. Add a (diagnostic?) option 
`-XX:+WritePerfMapOnExit`?

-

PR: https://git.openjdk.java.net/jdk/pull/760