Skip to contentSkip to conversation

perf, tools: Make build fail on JSON parse error

PATCH In review Andi Kleen 4 participants 6 messages Jul 21, 2017 – Jul 24, 2017 perf events

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/1 perf, tools: Make build fail on JSON parse error

From: Andi Kleen <[email protected]>

Today, when a JSON file fails parsing the build continues, but there are no json files built in, which is difficult to debug later. Make the build stop on a parse error instead.

---
 tools/perf/pmu-events/jevents.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/pmu-events/jevents.c +5 -1
index 70cbd5bc4819..58b42508c333 100644
@@ -890,6 +890,9 @@ int main(int argc, char *argv[])
 	if (rc && verbose) {
 		pr_info("%s: Error walking file tree %s\n", prog, ldirname);
 		goto empty_map;
+	} else if (rc < 0) {
+		/* Make build fail */
+		return 1;
 	} else if (rc) {
 		goto empty_map;
 	}
@@ -904,7 +907,8 @@ int main(int argc, char *argv[])
 
 	if (process_mapfile(eventsfp, mapfile)) {
 		pr_info("%s: Error processing mapfile %s\n", prog, mapfile);
-		goto empty_map;
+		/* Make build fail */
+		return 1;
 	}
 
 	return 0;
Signature · 1 line
2.9.4
#1 lore raw
Quoted 5 lines · Andi Kleen [[email protected]] wrote:

From: Andi Kleen <[email protected]>

Today, when a JSON file fails parsing the build continues, but there are no json files built in, which is difficult to debug later. Make the build stop on a parse error instead.

I see the problem and we were being defensive to not break the build on architectures that don't yet have the PMU event lists. It will be good to check build on an architecture other than x86/powerpc.

Also, following comments may no longer be applicable?

tools/perf/pmu-events/README +0 -4
index 1408ade0d773..c2ee3e4417fe 100644
@@ -85,10 +85,6 @@ users to specify events by their name:
 
 where 'pm_1plus_ppc_cmpl' is a Power8 PMU event.
 
-In case of errors when processing files in the tools/perf/pmu-events/arch
-directory, 'jevents' tries to create an empty mapping file to allow the perf
-build to succeed even if the PMU event aliases cannot be used.
-
 However some errors in processing may cause the perf build to fail.
 
 Mapfile format
tools/perf/pmu-events/jevents.c +0 -4
index baa073f38334..f6fb0eebf488 100644
@@ -826,10 +826,6 @@ static int process_one_file(const char *fpath, const struct stat *sb,
  * PMU event tables (see struct pmu_events_map).
  *
  * Write out the PMU events tables and the mapping table to pmu-event.c.
- *
- * If unable to process the JSON or arch files, create an empty mapping
- * table so we can continue to build/use  perf even if we cannot use the
- * PMU event aliases.
  */
 int main(int argc, char *argv[])
 {
Quoted 33 lines
---
 tools/perf/pmu-events/jevents.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/pmu-events/jevents.c +5 -1
index 70cbd5bc4819..58b42508c333 100644
@@ -890,6 +890,9 @@ int main(int argc, char *argv[])
 	if (rc && verbose) {
 		pr_info("%s: Error walking file tree %s\n", prog, ldirname);
 		goto empty_map;
+	} else if (rc < 0) {
+		/* Make build fail */
+		return 1;
 	} else if (rc) {
 		goto empty_map;
 	}
@@ -904,7 +907,8 @@ int main(int argc, char *argv[])
 
 	if (process_mapfile(eventsfp, mapfile)) {
 		pr_info("%s: Error processing mapfile %s\n", prog, mapfile);
-		goto empty_map;
+		/* Make build fail */
+		return 1;
 	}
 
 	return 0;
Signature · 1 line
2.9.4
#2 lore raw
Quoted 7 lines · Sukadev Bhattiprolu
Quoted 5 lines · Andi Kleen [[email protected]] wrote:

From: Andi Kleen <[email protected]>

Today, when a JSON file fails parsing the build continues, but there are no json files built in, which is difficult to debug later. Make the build stop on a parse error instead.

Quoted 5 lines

I see the problem and we were being defensive to not break the build on architectures that don't yet have the PMU event lists. It will be good to check build on an architecture other than x86/powerpc.

Also, following comments may no longer be applicable?

Isn't the Andi's change only to fail in case there's a real error in process_one_file? I think you can still have empty events dir.

jirka

#3 lore raw

Em Mon, Jul 24, 2017 at 04:16:49PM +0200, Jiri Olsa escreveu:

Quoted 12 lines · Sukadev Bhattiprolu
Quoted 11 lines
Quoted 5 lines · Andi Kleen [[email protected]] wrote:

From: Andi Kleen <[email protected]>

Today, when a JSON file fails parsing the build continues, but there are no json files built in, which is difficult to debug later. Make the build stop on a parse error instead.

I see the problem and we were being defensive to not break the build on architectures that don't yet have the PMU event lists. It will be good to check build on an architecture other than x86/powerpc.

Quoted 5 lines
Quoted 1 line

Also, following comments may no longer be applicable?

Isn't the Andi's change only to fail in case there's a real error in process_one_file? I think you can still have empty events dir.

That explains why all the cross builds failed when I added that cset?

- Arnaldo

author
#4 lore raw
Quoted 13 lines · Arnaldo Carvalho de Melo

Em Mon, Jul 24, 2017 at 04:16:49PM +0200, Jiri Olsa escreveu:

Quoted 12 lines · Sukadev Bhattiprolu
Quoted 11 lines
Quoted 5 lines · Andi Kleen [[email protected]] wrote:

From: Andi Kleen <[email protected]>

Today, when a JSON file fails parsing the build continues, but there are no json files built in, which is difficult to debug later. Make the build stop on a parse error instead.

I see the problem and we were being defensive to not break the build on architectures that don't yet have the PMU event lists. It will be good to check build on an architecture other than x86/powerpc.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Also, following comments may no longer be applicable?

Isn't the Andi's change only to fail in case there's a real error in process_one_file? I think you can still have empty events dir.

That explains why all the cross builds failed when I added that cset?

Hmm, let me test. It was supposed to only fail when there is a file, but it cannot be parsed.

-Andi

#5 lore raw
Quoted 16 lines · Andi Kleen [[email protected]] wrote:
Quoted 15 lines · Arnaldo Carvalho de Melo

Em Mon, Jul 24, 2017 at 04:16:49PM +0200, Jiri Olsa escreveu:

Quoted 14 lines · Sukadev Bhattiprolu
Quoted 12 lines
Quoted 5 lines · Andi Kleen [[email protected]] wrote:

From: Andi Kleen <[email protected]>

Today, when a JSON file fails parsing the build continues, but there are no json files built in, which is difficult to debug later. Make the build stop on a parse error instead.

I see the problem and we were being defensive to not break the build on architectures that don't yet have the PMU event lists. It will be good to check build on an architecture other than x86/powerpc.

Also, following comments may no longer be applicable?

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Isn't the Andi's change only to fail in case there's a real error in process_one_file? I think you can still have empty events dir.

That explains why all the cross builds failed when I added that cset?

Hmm, let me test. It was supposed to only fail when there is a file, but it cannot be parsed.

Wonder if adding this check for event lists helps.

---

tools/perf/pmu-events/jevents.c +14 -3
index baa073f..4de5c87 100644
@@ -840,6 +840,7 @@ int main(int argc, char *argv[])
 	const char *arch;
 	const char *output_file;
 	const char *start_dirname;
+	struct stat stbuf;
 
 	prog = basename(argv[0]);
 	if (argc < 4) {
@@ -861,11 +862,17 @@ int main(int argc, char *argv[])
 		return 2;
 	}
 
+	sprintf(ldirname, "%s/%s", start_dirname, arch);
+
+	/* If architecture does not have any event lists, bail out */
+	if (stat(ldirname, &stbuf) < 0) {
+		pr_info("%s: Arch %s has no PMU event lists\n", prog, arch);
+		goto empty_map;
+	}
+
 	/* Include pmu-events.h first */
 	fprintf(eventsfp, "#include \"../../pmu-events/pmu-events.h\"\n");
 
-	sprintf(ldirname, "%s/%s", start_dirname, arch);
-
 	/*
 	 * The mapfile allows multiple CPUids to point to the same JSON file,
 	 * so, not sure if there is a need for symlinks within the pmu-events
@@ -882,6 +889,9 @@ int main(int argc, char *argv[])
 	if (rc && verbose) {
 		pr_info("%s: Error walking file tree %s\n", prog, ldirname);
 		goto empty_map;
+	} else if (rc < 0) {
+		/* Make build fail */
+		return 1;
 	} else if (rc) {
 		goto empty_map;
 	}
@@ -896,7 +906,8 @@ int main(int argc, char *argv[])
 
 	if (process_mapfile(eventsfp, mapfile)) {
 		pr_info("%s: Error processing mapfile %s\n", prog, mapfile);
-		goto empty_map;
+		/* Make build fail */
+		return 1;
 	}
 
 	return 0;