Skip to content

Commit eed7a0f

Browse files
committed
refactor profiler to support http with html crawling in additional to local filesystem #798
1 parent b2d6bed commit eed7a0f

25 files changed

+925
-214
lines changed

META-INF/plugin.xml

+7
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@
285285
nonDefaultProject="true"
286286
/>
287287

288+
<projectConfigurable instance="fr.adrienbrault.idea.symfony2plugin.profiler.ui.ProfilerSettingsDialog"
289+
displayName="Profiler"
290+
parentId="Symfony2.SettingsForm"
291+
id="Symfony.ProfilerSettingsForm"
292+
nonDefaultProject="true"
293+
/>
294+
288295
<php.typeProvider2 implementation="fr.adrienbrault.idea.symfony2plugin.dic.SymfonyContainerTypeProvider"/>
289296
<php.typeProvider2 implementation="fr.adrienbrault.idea.symfony2plugin.doctrine.ObjectRepositoryTypeProvider"/>
290297
<php.typeProvider2 implementation="fr.adrienbrault.idea.symfony2plugin.doctrine.ObjectRepositoryResultTypeProvider"/>

src/fr/adrienbrault/idea/symfony2plugin/Settings.java

+6
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ public class Settings implements PersistentStateComponent<Settings> {
8888

8989
public boolean dismissEnableNotification = false;
9090

91+
public boolean profilerLocalEnabled = false;
92+
public String profilerLocalUrl = "http://127.0.0.1:8000";
93+
94+
public boolean profilerHttpEnabled = false;
95+
public String profilerHttpUrl = "http://127.0.0.1:8000";
96+
9197
@Nullable
9298
public List<TwigNamespaceSetting> twigNamespaces = new ArrayList<>();
9399

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package fr.adrienbrault.idea.symfony2plugin.profiler;
2+
3+
import com.intellij.openapi.project.Project;
4+
import fr.adrienbrault.idea.symfony2plugin.profiler.dict.ProfilerRequestInterface;
5+
import org.apache.commons.lang.StringUtils;
6+
import org.jetbrains.annotations.NotNull;
7+
8+
import java.util.ArrayList;
9+
import java.util.Collections;
10+
import java.util.List;
11+
12+
/**
13+
* @author Daniel Espendiller <daniel@espendiller.net>
14+
*/
15+
public class HttpProfilerIndex implements ProfilerIndexInterface {
16+
/**
17+
* http://127.0.0.1:8080/_profiler
18+
*/
19+
private static String PROFILER_PATH = "_profiler";
20+
21+
@NotNull
22+
private final Project project;
23+
24+
@NotNull
25+
private final String url;
26+
27+
public HttpProfilerIndex(@NotNull Project project, @NotNull String url) {
28+
this.project = project;
29+
this.url = StringUtils.stripEnd(url, "/");
30+
}
31+
32+
@NotNull
33+
@Override
34+
public List<ProfilerRequestInterface> getRequests() {
35+
String content = ProfilerUtil.getProfilerUrlContent(String.format("%s/%s/empty/search/results?ip=&limit=10", this.url, PROFILER_PATH));
36+
if(content == null) {
37+
return Collections.emptyList();
38+
}
39+
40+
return new ArrayList<>(ProfilerUtil.collectHttpDataForRequest(
41+
project, ProfilerUtil.createRequestsFromIndexHtml(this.project, content, this.url))
42+
);
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,53 @@
11
package fr.adrienbrault.idea.symfony2plugin.profiler;
22

33
import fr.adrienbrault.idea.symfony2plugin.profiler.dict.ProfilerRequest;
4+
import fr.adrienbrault.idea.symfony2plugin.profiler.dict.ProfilerRequestInterface;
5+
import org.jetbrains.annotations.NotNull;
46
import org.jetbrains.annotations.Nullable;
57

68
import java.io.BufferedReader;
79
import java.io.File;
810
import java.io.FileReader;
911
import java.io.IOException;
1012
import java.util.ArrayList;
13+
import java.util.List;
1114

12-
public class ProfilerIndex {
13-
15+
/**
16+
* @author Daniel Espendiller <daniel@espendiller.net>
17+
*/
18+
public class LocalProfilerIndex implements ProfilerIndexInterface {
19+
@NotNull
1420
private File file;
1521

16-
public ProfilerIndex(File file) {
22+
public LocalProfilerIndex(@NotNull File file) {
1723
this.file = file;
1824
}
1925

20-
public ArrayList<ProfilerRequest> getRequests() {
21-
ArrayList<ProfilerRequest> list = new ArrayList<>();
22-
23-
String trennzeichen = ",";
24-
26+
@NotNull
27+
public List<ProfilerRequestInterface> getRequests() {
28+
List<ProfilerRequestInterface> list = new ArrayList<>();
2529
try {
2630
BufferedReader in = new BufferedReader(new FileReader(this.file));
2731
String readString;
2832
while ((readString = in.readLine()) != null) {
29-
list.add(new ProfilerRequest(readString.split(trennzeichen), this));
33+
list.add(new ProfilerRequest(readString.split(","), this));
3034
}
3135

3236
in.close();
3337
} catch (IOException ignored) {
34-
3538
}
3639

37-
3840
return list;
3941
}
4042

41-
public String getPath(ProfilerRequest profilerRequest) {
43+
@NotNull
44+
public String getPath(@NotNull ProfilerRequestInterface profilerRequest) {
4245
String[] hash = profilerRequest.getHash().split("(?<=\\G.{2})");
43-
4446
return hash[2] + "/" + hash[1] + "/" + profilerRequest.getHash();
45-
4647
}
4748

4849
@Nullable
49-
public File getFile(ProfilerRequest profilerRequest) {
50+
public File getFile(@NotNull ProfilerRequestInterface profilerRequest) {
5051
String path = this.getPath(profilerRequest);
5152

5253
File file = new File(this.file.getParentFile().getAbsolutePath() + "/" + path);
@@ -59,8 +60,8 @@ public File getFile(ProfilerRequest profilerRequest) {
5960
}
6061

6162
@Nullable
62-
public ProfilerRequest getRequestOnHash(String hash) {
63-
for(ProfilerRequest profilerRequest :this.getRequests()) {
63+
public ProfilerRequestInterface getRequestOnHash(@NotNull String hash) {
64+
for(ProfilerRequestInterface profilerRequest :this.getRequests()) {
6465
if(profilerRequest.getHash().equals(hash)) {
6566
return profilerRequest;
6667
}
@@ -70,7 +71,7 @@ public ProfilerRequest getRequestOnHash(String hash) {
7071
}
7172

7273
@Nullable
73-
public String getContent(ProfilerRequest profilerRequest) {
74+
public String getContent(@NotNull ProfilerRequestInterface profilerRequest) {
7475
File file = this.getFile(profilerRequest);
7576
if(file == null) {
7677
return null;
@@ -88,8 +89,6 @@ public String getContent(ProfilerRequest profilerRequest) {
8889
} catch (IOException ignored) {
8990
}
9091

91-
9292
return content.toString();
9393
}
94-
9594
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package fr.adrienbrault.idea.symfony2plugin.profiler;
2+
3+
import fr.adrienbrault.idea.symfony2plugin.profiler.dict.ProfilerRequestInterface;
4+
import org.jetbrains.annotations.NotNull;
5+
6+
import java.util.List;
7+
8+
/**
9+
* @author Daniel Espendiller <daniel@espendiller.net>
10+
*/
11+
public interface ProfilerIndexInterface {
12+
@NotNull
13+
List<ProfilerRequestInterface> getRequests();
14+
}

0 commit comments

Comments
 (0)