How to identify JFR event types - java

I know of three JFR Event types: Instant Event, Duration Event, and Sample Event, but how to identify JFR event types.
I try to distinguish them from the configuration, but it seems doesn't work, for example, jdk.ObjectAllocationInNewTLAB, it only need to configure whether to enable, seems to be an Instant Event, but is actually a Sample of the Event.
This is important to me because I want to analyze with full information, not samples

You can see what options an event type supports by using the setting descriptor:
for(EventType type : FlightRecorder.getFlightRecorder().getEventTypes()) {
System.out.println(type.getName());
System.out.println("Settings:");
for (SettingDescriptor s : type.getSettingDescriptors()) {
String def = " (default: " + s.getDefaultValue() + ")";
System.out.println(" " + s.getName() + def);
}
System.out.println();
}
It's also possible to list event metadata, including settings, using the 'jfr' tool located in JAVA_HOME/bin. For JDK 11, you must supply the file you want metadata to be printed for:
$ jfr metadata recording.jfr
For JDK 17, you can omit the file and you will get the event types for the JDK the tool is located in:
$ jfr metadata

Related

How to filter OpenCV error messages in Java

The issue of this question has already been discussed e.g. for
C++
Python
The OpenCV documentation describes
ErrorCallback cv::redirectError ( ErrorCallback errCallback,
void * userdata = 0,
void ** prevUserdata = 0
)
How can this be made to use to e.g. filter out annoying messages?
An example is
[mjpeg # 0x7fe5a696ea00] unable to decode APP fields: Invalid data found when processing input
from a Logitech USB Webcam mjpeg stream which is created on every single frame and is superflous and not needed.
There is also a loglevel available. Unfortunately the import org.opencv.utils only contains "Converters" but no logging as of OpenCV 3.4.8
How could the loglevel be set from Java?
enum LogLevel {
LOG_LEVEL_SILENT = 0,
LOG_LEVEL_FATAL = 1,
LOG_LEVEL_ERROR = 2,
LOG_LEVEL_WARNING = 3,
LOG_LEVEL_INFO = 4,
LOG_LEVEL_DEBUG = 5,
LOG_LEVEL_VERBOSE = 6
}
Would Redirect System.out and System.err to slf4j help?
How can this be made to use to e.g. filter out annoying messages?
How could the loglevel be set from Java?
At this time (2020-01) it can't. Even if the API would be accessible from Java the bug https://github.com/opencv/opencv/issues/12780 would prevent it.
Would [Redirect System.out and System.err to slf4j][5] help?
No - see Junit test case below. The result is:
11:05:56.407 [main] DEBUG u.o.l.s.c.SysOutOverSLF4JInitialiser - Your logging framework class ch.qos.logback.classic.Logger should not need access to the standard println methods on the console, so you should not need to register a logging system package.
11:05:56.417 [main] INFO u.o.l.s.context.SysOutOverSLF4J - Replaced standard System.out and System.err PrintStreams with SLF4JPrintStreams
11:05:56.420 [main] INFO u.o.l.s.context.SysOutOverSLF4J - Redirected System.out and System.err to SLF4J for this context
11:05:56.421 [main] ERROR org.rcdukes.roi.TestROI - testing stderr via slf4j
[mjpeg # 0x7f958b1b0400] unable to decode APP fields: Invalid data found when processing input
[mjpeg # 0x7f958b027a00] unable to decode APP fields: Invalid data found when processing input
where the decode APP field part is still showing up via some stderr magic.
#Test
public void testLogStderr() throws Exception {
NativeLibrary.logStdErr();
System.err.println("testing stderr via slf4j");
NativeLibrary.load();
VideoCapture capture = new VideoCapture();
// Dorf Appenzell
//String url="http://213.193.89.202/axis-cgi/mjpg/video.cgi";
// Logitech Cam on test car
// url="http://picarford:8080/?action=stream";
File imgRoot = new File(testPath);
File testStream=new File(imgRoot,"logitech_test_stream.mjpg");
assertTrue(testStream.canRead());
capture.open(testStream.getPath());
Mat image=new Mat();
capture.read(image);
assertEquals(640,image.width());
assertEquals(480,image.height());
capture.release();
}
Funny side fact
According to the ffmpeg documentation
Log coloring can be disabled setting the environment variable AV_LOG_FORCE_NOCOLOR or NO_COLOR, or can be forced setting the environment variable AV_LOG_FORCE_COLOR. The use of the environment variable NO_COLOR is deprecated and will be dropped in a future FFmpeg version
But there seems to be no option to change the Logging level from an environment variable ...

JAVA SQLException error message sometimes not parsed

I am new to JDBC, and I found something strange when I use:
catch (SQLException e) {
System.out.println("Error STATE: " + e.getSQLState());
System.out.println("With the following message: " + e.getMessage() );
}
Sometimes the message is parsed, but sometimes not.
Like:
First:
Second:
One is parsed, while the other is not, but I can get the error message through googling the corresponding error code.
I don't know what's going on.. And I have tried googling it but with no similar question posted. Does it mean my java.sql.* library is incomplete?
All help would be appreciated.
It means your operating system settings don't support the symbols for the error message in the language being used. The ORA-01017 message is coming before the database applies your language setting so in in English, and more importantly in Western script. Once you've connected the Java locale is honoured.
For example, I can see both these from the same code run with java -Duser.language=zh -Duser.country=CN; the first has incorrect credentials supplied, the second is trying to create an existing table:
java.sql.SQLException: ORA-01017: invalid username/password; logon denied
java.sql.SQLSyntaxErrorException: ORA-00955: 名称已由现有对象使用
I'm seeing ten symbols, where you are seeing ten question marks. My operating system session (Linux in this case) has LANG=en_US.UTF-8. If I change that to something which has fewer symbols defined, e.g. export LANG="en_US.ASCII", I still see the first message but now I get the same as you for the second one:
java.sql.SQLException: ORA-01017: invalid username/password; logon denied
java.sql.SQLSyntaxErrorException: ORA-00955: ??????????
The Chinese symbols can now no longer be rendered by my operating system session.
So set your operating system locale to something that can represent the symbols of the language you're using, preferably UTF8. For example, if Java is running with a Chinese locale, you could do this to be consistent under Linux:
export LANG="zh_CN.UTF-8"
java -Duser.language=zh -Duser.country=CN
ORA-00955: 名称已由现有对象使用
Or change your Java locale to English-language if you want to see all the messages in English:
export LANG="en_CN.UTF-8"
java -Duser.language=en -Duser.country=CN -
ORA-00955: name is already used by an existing object
(Although Java should pick up the language from your locale by default anyway, so maybe don't supply the language or country explicitly in the java call at all; just setting LANG properly would then be enough)

Error in Map Reduce over HBase, why?

I have the following job, and many others like it, launched like this
String jobName = MR.class
.getSimpleName();
Configuration config = HBaseConfiguration.create();
config.set(
"hbase.master", HBASE_MASTER);
config.set(
"hbase.zookeeper.quorum", HBASE_ZOOKEEPERS);
config.set(
"hbase.zookeeper.property.clientPort", ZK_CLIENT_PORT);
Job job = Job.getInstance(config, jobName);
job.setJarByClass(MR.class);
Scan scan = new Scan();
//gets the raw band data cells
scan.addColumn("gc".getBytes(), "s".getBytes());
System.out.println("Job=" + jobName);
System.out.println("\tHBASE_MASTER=" + HBASE_MASTER);
System.out.println(
"\tHBASE_ZOOKEEPERS=" + HBASE_ZOOKEEPERS);
System.out.println(
"\tINPUT_TABLE=" + INPUT_TABLE);
System.out.println(
"\tOUTPUT_TABLE= " + OUTPUT_TABLE);
System.out.println(
"\tCACHING_LEVEL= " + CACHING_LEVEL);
// TODO: make caching size configurable
scan.setCaching(CACHING_LEVEL);
scan.setCacheBlocks(
false);
// null for output key/value since we're not sending anything to reduce
TableMapReduceUtil.initTableMapperJob(INPUT_TABLE, scan,
MR.MapClass.class,
null,
null,
job);
TableMapReduceUtil.initTableReducerJob(
"PIXELS", // output table
null, // reducer class
job);
job.setNumReduceTasks(0);
// at least one, adjust as required
boolean b = job.waitForCompletion(true);
but I keep getting this error and can't even read the data into the mapper
Error: java.io.BufferedReader.lines()Ljava/util/stream/Stream;
14/09/22 22:11:13 INFO mapreduce.Job: Task Id : attempt_1410880772411_0045_m_000009_2, Status : FAILED
Error: java.io.BufferedReader.lines()Ljava/util/stream/Stream;
14/09/22 22:11:13 INFO mapreduce.Job: Task Id : attempt_1410880772411_0045_m_000018_2, Status : FAILED
Error: java.io.BufferedReader.lines()Ljava/util/stream/Stream;
14/09/22 22:11:13 INFO mapreduce.Job: Task Id : attempt_1410880772411_0045_m_000002_2, Status : FAILED
never seen this before, been using HBase a while....
here is what i've tried:
I can scan the table via the hbase shell no problem in the same way this job does
I can use the java api to scan in the same way no problem
I built and rebuilt my jar thinking some files were corrupt... not the problem
I have at least 5 other jobs setup the same way
I disabled, enabled, compacted, rebuilt everything you can imagine with the table
I am using maven shade to uber jar
I am running HBase 0.98.1-cdh5.1.0
any help or ideas greatly appreciated.
Looks like I should have waited a bit to ask this question. The problem was that I actually was getting to the data, but one of my external jars had been built with Java 8, and .lines() does not exists in a BufferedReader in java 7, i'm running java 7, hence the error. Nothing to do with HBase or Map Reduce.

Warning: File for type '[Insert class here]' created in the last round will not be subject to annotation processing

I switched an existing code base to Java 7 and I keep getting this warning:
warning: File for type '[Insert class here]' created in the last round
will not be subject to annotation processing.
A quick search reveals that no one has hit this warning.
It's not documented in the javac compiler source either:
From OpenJDK\langtools\src\share\classes\com\sun\tools\javac\processing\JavacFiler.java
private JavaFileObject createSourceOrClassFile(boolean isSourceFile, String name) throws IOException {
checkNameAndExistence(name, isSourceFile);
Location loc = (isSourceFile ? SOURCE_OUTPUT : CLASS_OUTPUT);
JavaFileObject.Kind kind = (isSourceFile ?
JavaFileObject.Kind.SOURCE :
JavaFileObject.Kind.CLASS);
JavaFileObject fileObject =
fileManager.getJavaFileForOutput(loc, name, kind, null);
checkFileReopening(fileObject, true);
if (lastRound) // <-------------------------------TRIGGERS WARNING
log.warning("proc.file.create.last.round", name);
if (isSourceFile)
aggregateGeneratedSourceNames.add(name);
else
aggregateGeneratedClassNames.add(name);
openTypeNames.add(name);
return new FilerOutputJavaFileObject(name, fileObject);
}
What does this mean and what steps can I take to clear this warning?
Thanks.
The warning
warning: File for type '[Insert class here]' created in the last round
will not be subject to annotation processing
means that your were running an annotation processor creating a new class or source file using a javax.annotation.processing.Filer implementation (provided through the javax.annotation.processing.ProcessingEnvironment) although the processing tool already decided its "in the last round".
This may be problem (and thus the warning) because the generated file itself may contain annotations being ignored by the annotation processor (because it is not going to do a further round).
The above ought to answer the first part of your question
What does this mean and what steps can I take to clear this warning?
(you figured this out already by yourself, didn't you :-))
What possible steps to take? Check your annotation processors:
1) Do you really have to use filer.createClassFile / filer.createSourceFile on the very last round of the annotaion processor? Usually one uses the filer object inside of a code block like
for (TypeElement annotation : annotations) {
...
}
(in method process). This ensures that the annotation processor will not be in its last round (the last round always being the one having an empty set of annotations).
2) If you really can't avoid writing your generated files in the last round and these files are source files, trick the annotation processor and use the method "createResource" of the filer object (take "SOURCE_OUTPUT" as location).
In OpenJDK test case this warning produced because processor uses "processingOver()" to write new file exactly at last round.
public boolean process(Set<? extends TypeElement> elems, RoundEnvironment renv) {
if (renv.processingOver()) { // Write only at last round
Filer filer = processingEnv.getFiler();
Messager messager = processingEnv.getMessager();
try {
JavaFileObject fo = filer.createSourceFile("Gen");
Writer out = fo.openWriter();
out.write("class Gen { }");
out.close();
messager.printMessage(Diagnostic.Kind.NOTE, "File 'Gen' created");
} catch (IOException e) {
messager.printMessage(Diagnostic.Kind.ERROR, e.toString());
}
}
return false;
}
I modified original example code a bit. Added diagnostic note "File 'Gen' created", replaced "*" mask with "org.junit.runner.RunWith" and set return value to "true". Produced compiler log was:
Round 1:
input files: {ProcFileCreateLastRound}
annotations: [org.junit.runner.RunWith]
last round: false
Processor AnnoProc matches [org.junit.runner.RunWith] and returns true.
Round 2:
input files: {}
annotations: []
last round: true
Note: File 'Gen' created
Compilation completed successfully with 1 warning
0 errors
1 warning
Warning: File for type 'Gen' created in the last round will not be subject to annotation processing.
If we remove my custom note from log, it's hard to tell that file 'Gen' was actually created on 'Round 2' - last round. So, basic advice applies: if in doubt - add more logs.
Where is also a little bit of useful info on this page:
http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/javac.html
Read section about "ANNOTATION PROCESSING" and try to get more info with compiler options:
-XprintProcessorInfo
Print information about which annotations a processor is asked to process.
-XprintRounds Print information about initial and subsequent annotation processing rounds.
I poked around the java 7 compiler options and I found this:
-implicit:{class,none}
Controls the generation of class files for implicitly loaded source files. To automatically generate class files, use -implicit:class. To suppress class file generation, use -implicit:none. If this option is not specified, the default is to automatically generate class files. In this case, the compiler will issue a warning if any such class files are generated when also doing annotation processing. The warning will not be issued if this option is set explicitly. See Searching For Types.
Source
Can you try and implicitly declare the class file.

Problem validating against an XSD with Java5

I'm trying to validate an Atom feed with Java 5 (JRE 1.5.0 update 11). The code I have works without problem in Java 6, but fails when running in Java 5 with a
org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'xml:base' to a(n) 'attribute declaration' component.
I think I remember reading something about the version of Xerces bundled with Java 5 having some problems with some schemas, but i cant find the workaround. Is it a known problem ? Do I have some error in my code ?
public static void validate() throws SAXException, IOException {
List<Source> schemas = new ArrayList<Source>();
schemas.add(new StreamSource(AtomValidator.class.getResourceAsStream("/atom.xsd")));
schemas.add(new StreamSource(AtomValidator.class.getResourceAsStream("/dc.xsd")));
// Lookup a factory for the W3C XML Schema language
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
// Compile the schemas.
Schema schema = factory.newSchema(schemas.toArray(new Source[schemas.size()]));
Validator validator = schema.newValidator();
// load the file to validate
Source source = new StreamSource(AtomValidator.class.getResourceAsStream("/sample-feed.xml"));
// check the document
validator.validate(source);
}
Update : I tried the method below, but I still have the same problem if I use Xerces 2.9.0. I also tried adding xml.xsd to the list of schemas (as xml:base is defined in xml.xsd) but this time I have
Exception in thread "main" org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'null', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
Update 2: I tried to configure a proxy with the VM arguments -Dhttp.proxyHost=<proxy.host.com> -Dhttp.proxyPort=8080 and now it works. I'll try to post a "real answer" from home.
and sorry, I cant reply as a comment : because of security reasons XHR is disabled from work ...
Indeed, people have been mentioning the Java 5 Sun provided SchemaFactory is giving troubles.
So: did you include Xerces in your project yourself?
After including Xerces, you need to ensure it is being used. If you like to hardcode it (well, as a minimal requirement you'd probably use some application properties file to enable and populate the following code):
String schemaFactoryProperty =
"javax.xml.validation.SchemaFactory:" + XMLConstants.W3C_XML_SCHEMA_NS_URI;
System.setProperty(schemaFactoryProperty,
"org.apache.xerces.jaxp.validation.XMLSchemaFactory");
SchemaFactory factory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Or, if you don't want to hardcode, or when your troublesome code would be in some 3rd party library that you cannot change, set it on the java command line or environment options. For example (on one line of course):
set JAVA_OPTS =
"-Djavax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema
=org.apache.xerces.jaxp.validation.XMLSchemaFactory"
By the way: apart from the Sun included SchemaFactory implementation giving trouble (something like com.sun.org.apache.xerces.internal.jaxp.validation.xs.schemaFactoryImpl), it also seems that the "discovery" of non-JDK implementations fails in that version. If I understand correctly than, normally, just including Xerces would in fact make SchemaFactory#newInstance find that included library, and give it precedence over the Sun implementation. To my knowledge, that fails as well in Java 5, making the above configuration required.
I tried to configure a proxy with the VM arguments -Dhttp.proxyHost=<proxy.host.com> -Dhttp.proxyPort=8080 and now it works.
Ah, I didn't realize that xml.xsd is in fact the one referenced as http://www.w3.org/2001/xml.xsd or something like that. That should teach us to always show some XML and XSD fragments as well. ;-)
So, am I correct to assume that 1.) to fix the Java 5 issue, you still needed to include Xerces and set the system property, and that 2.) you did not have xml.xsd available locally?
Before you found your solution, did you happen to try using getResource rather than getResourceAsStream, to see if the exception would then have showed you some more details?
If you actually did have xml.xsd available (so: if getResource did in fact yield a URL) then I wonder what Xerces was trying to fetch from the internet then. Or maybe you did not add that schema to the list prior to adding your own schemas? The order is important: dependencies must be added first.
For whoever gets tot his question using the search: maybe using a custom EntityResolver could have indicated the source of the problem as well (if only writing something to the log and just returning null to tell Xerces to use the default behavior).
Hmmm, just read your "comment" -- editing does not alert people for new replies, so time to ask your boss for some iPhone or some other gadget that is connected to the net directly ;-)
Well, I assume you added:
schemas.add(
new StreamSource(AtomValidator.class.getResourceAsStream("/xml.xsd")));
If so, is xml.xsd actually to be found on the classpath then? I wonder if the getResourceAsStream did not yield null in your case, and how new StreamSource(null) would act then.
Even if getResourceAsStream did not yield null, the resulting StreamSource would still not know where it was loaded from, which may be a problem when trying to include references. So, what if you use the constructor StreamSource(String systemId) instead:
schemas.add(new StreamSource(AtomValidator.class.getResource("/atom.xsd")));
schemas.add(new StreamSource(AtomValidator.class.getResource("/dc.xsd")));
You might also use StreamSource(InputStream inputStream, String systemId), but I don't see any advantage over the above two lines. However, the documentation explains why passing the systemId in either of the 2 constructors seems good:
This constructor allows the systemID to be set in addition to the input stream, which allows relative URIs to be processed.
Likewise, setSystemId(String systemId) explains a bit:
The system identifier is optional if there is a byte stream or a character stream, but it is still useful to provide one, since the application can use it to resolve relative URIs and can include it in error messages and warnings (the parser will attempt to open a connection to the URI only if there is no byte stream or character stream specified).
If this doesn't work out, then maybe some custom error handler can give you more details:
ErrorHandlerImpl errorHandler = new ErrorHandlerImpl();
validator.setErrorHandler(errorHandler);
:
:
validator.validate(source);
if(errorHandler.hasErrors()){
LOG.error(errorHandler.getMessages());
throw new [..];
}
if(errorHandler.hasWarnings()){
LOG.warn(errorHandler.getMessages());
}
...using the following ErrorHandler to capture the validation errors and continue parsing as far as possible:
import org.xml.sax.helpers.DefaultHandler;
private class ErrorHandlerImpl extends DefaultHandler{
private String messages = "";
private boolean validationError = false;
private boolean validationWarning = false;
public void error(SAXParseException exception) throws SAXException{
messages += "Error: " + exception.getMessage() + "\n";
validationError = true;
}
public void fatalError(SAXParseException exception) throws SAXException{
messages += "Fatal: " + exception.getMessage();
validationError = true;
}
public void warning(SAXParseException exception) throws SAXException{
messages += "Warn: " + exception.getMessage();
validationWarning = true;
}
public boolean hasErrors(){
return validationError;
}
public boolean hasWarnings(){
return validationWarning;
}
public String getMessages(){
return messages;
}
}

Categories

Resources