forked from eXistence/valgrind-plugin
/
ValgrindResult.java
139 lines (112 loc) · 3.99 KB
/
ValgrindResult.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package org.jenkinsci.plugins.valgrind;
import hudson.model.Run;
import hudson.FilePath;
import java.io.IOException;
import java.io.Serializable;
import java.util.Map;
import org.jenkinsci.plugins.valgrind.config.ValgrindPublisherConfig;
import org.jenkinsci.plugins.valgrind.model.ValgrindError;
import org.jenkinsci.plugins.valgrind.model.ValgrindProcess;
import org.jenkinsci.plugins.valgrind.model.ValgrindReport;
import org.jenkinsci.plugins.valgrind.model.ValgrindThread;
import org.jenkinsci.plugins.valgrind.parser.ValgrindParserResult;
import org.jenkinsci.plugins.valgrind.util.ValgrindSourceFile;
import org.jenkinsci.plugins.valgrind.util.ValgrindSummary;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
public class ValgrindResult implements Serializable
{
private static final long serialVersionUID = -5347879997716170059L;
private static final String PID_TOKEN = "pid=";
private ValgrindParserResult parser;
private transient Run<?, ?> owner;
private Map<String, String> sourceFiles;
public ValgrindResult( Run<?, ?> build, ValgrindParserResult parser)
{
this.owner = build;
this.parser = parser;
}
public Run<?, ?> getOwner()
{
return owner;
}
public ValgrindPublisherConfig getConfig()
{
ValgrindBuildAction action = owner.getAction(ValgrindBuildAction.class);
if ( action == null )
return null;
return action.getConfig();
}
/**
* @return a ValgrindReport
* @throws IOException
* @throws InterruptedException
*/
public ValgrindReport getReport() throws IOException, InterruptedException
{
FilePath file = new FilePath(owner.getRootDir());
return file.act(parser);
}
public Map<String, String> getSourceFiles()
{
return sourceFiles;
}
public void setSourceFiles(Map<String, String> sourceFiles)
{
this.sourceFiles = sourceFiles;
}
/**
* Renders the summary Valgrind report for the build result.
*
* @return the HTML fragment of the summary Valgrind report
* @throws InterruptedException
* @throws IOException
*/
public String getSummary() throws IOException, InterruptedException
{
return ValgrindSummary.createReportSummary(this);
}
/**
*
* @param link expected to be in format "id=<executable name>,<unique error id>"
* @param request
* @param response
* @return valgrind detail(s)
* @throws IOException
* @throws InterruptedException
*/
public Object getDynamic(final String link, final StaplerRequest request, final StaplerResponse response)
throws IOException, InterruptedException
{
final String[] s = link.split("/");
final String data = s[s.length -1];
if ( !data.startsWith(PID_TOKEN) )
return null;
int sep = data.indexOf(",");
ValgrindReport report = getReport();
if ( sep > PID_TOKEN.length() )
{
String pid = data.substring(PID_TOKEN.length(), sep);
String uniqueId = data.substring( sep + 1 );
if (uniqueId.startsWith("tid")) {
ValgrindThread thread = report.findThread(pid, uniqueId.substring(3));
if ( thread == null )
return null;
ValgrindSourceFile sourceFile = new ValgrindSourceFile( ValgrindPublisher.DESCRIPTOR.getLinesBefore(), ValgrindPublisher.DESCRIPTOR.getLinesAfter(), sourceFiles, owner );
return new ValgrindThreadDetail( owner, report.findProcess(pid), thread, sourceFile );
} else {
ValgrindError error = report.findError(pid, uniqueId);
if ( error == null )
return null;
ValgrindSourceFile sourceFile = new ValgrindSourceFile( ValgrindPublisher.DESCRIPTOR.getLinesBefore(), ValgrindPublisher.DESCRIPTOR.getLinesAfter(), sourceFiles, owner );
return new ValgrindErrorDetail( owner, report.findProcess(pid), error, sourceFile );
}
}
else
{
String pid = data.substring(PID_TOKEN.length());
ValgrindProcess process = report.findProcess(pid);
return new ValgrindProcessDetails(owner, process);
}
}
}