Skip to content

Commit 0fb21bf

Browse files
dthomson-commitscloud-profiler-team
authored andcommitted
Internal change
PiperOrigin-RevId: 263209458
1 parent 4f82e27 commit 0fb21bf

4 files changed

Lines changed: 58 additions & 51 deletions

File tree

src/proto.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ uint64_t ProfileProtoBuilder::LocationID(const string &class_name,
189189
frame_name += signature;
190190
}
191191

192-
const string simplified_name =
193-
::google::javaprofiler::SimplifyFunctionName(frame_name);
192+
string simplified_name = frame_name;
193+
::google::javaprofiler::SimplifyFunctionName(&simplified_name);
194194

195195
uint64_t function_id = builder_.FunctionId(
196196
simplified_name.c_str(), frame_name.c_str(), file_name.c_str(), 0);

third_party/javaprofiler/profile_proto_builder.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ perftools::profiles::Location *LocationBuilder::LocationFor(
316316

317317
auto line = location->add_line();
318318

319-
auto simplified_name = SimplifyFunctionName(function_name);
319+
string simplified_name = function_name;
320+
SimplifyFunctionName(&simplified_name);
320321
auto function_id = builder_->FunctionId(
321322
simplified_name.c_str(), function_name.c_str(), file_name.c_str(), 0);
322323

third_party/javaprofiler/stacktrace_fixer.cc

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -27,94 +27,101 @@ namespace {
2727
// followed by specified suffix chars and removing those. For example,
2828
// calling the function with ("foo123bar", "foo", "321") returns "foobar".
2929
template <size_t M, size_t N>
30-
string SimplifySuffixedName(string name, const char (&trigger)[M],
31-
const char (&suffix_chars)[N]) {
30+
void SimplifySuffixedName(string *name, const char (&trigger)[M],
31+
const char (&suffix_chars)[N]) {
3232
size_t first = 0;
33-
while ((first = name.find(trigger, first)) != std::string::npos) {
33+
while ((first = name->find(trigger, first)) != std::string::npos) {
3434
first += M - 1; // Exclude last zero char.
35-
size_t last = name.find_first_not_of(suffix_chars, first, N);
35+
size_t last = name->find_first_not_of(suffix_chars, first, N);
3636
if (last == std::string::npos) {
37-
name.erase(first);
37+
name->erase(first);
3838
break;
3939
}
40-
name.erase(first, last - first);
40+
name->erase(first, last - first);
4141
}
42-
return name;
4342
}
4443

4544
// Simplifies the name of a method in a dynamic class (with '$$FastClassBy*$$'
4645
// or '$$EnhancedBy*$$' in its name) to make it more human readable, and group
4746
// related functions under a single name. This could be done with a regexp
4847
// replacement, but including RE2 increases the size of the agent.
49-
string SimplifyDynamicClassName(string name) {
48+
void SimplifyDynamicClassName(string *name) {
5049
// Replace $$[0-9a-f]+ by $$ to remove unique values, for example in
5150
// $FastClassByCGLIB$$fd6bdf6d.invoke.
52-
return SimplifySuffixedName(std::move(name), "$$", "0123456789abcdef");
51+
SimplifySuffixedName(name, "$$", "0123456789abcdef");
5352
}
5453

5554
// Simplifies the name of a lambda method to replace $$Lambda$[0-9]+\.[0-9]+ by
5655
// $$Lambda$ to remove unique values, for example in
5756
// com.google.something.Something$$Lambda$197.1849072452.run.
58-
string SimplifyLambdaName(string name) {
57+
void SimplifyLambdaName(string *name) {
5958
constexpr char trigger[] = "$$Lambda$";
6059
constexpr char digits[] = "0123456789";
6160
const size_t trigger_length = strlen(trigger);
6261

6362
// Assume and handle just one instance of a $$Lambda$ pattern.
64-
size_t first = name.find(trigger);
63+
size_t first = name->find(trigger);
6564
if (first == std::string::npos) {
66-
return name;
65+
return;
6766
}
6867
first += trigger_length;
69-
if (first >= name.size() || !isdigit(name[first])) {
70-
return name;
68+
if (first >= name->size() || !isdigit((*name)[first])) {
69+
return;
7170
}
72-
size_t last = name.find_first_not_of(digits, first);
73-
if (last == std::string::npos || name[last] != '.') {
74-
return name;
71+
size_t last = name->find_first_not_of(digits, first);
72+
if (last == std::string::npos || (*name)[last] != '.') {
73+
return;
7574
}
7675
last++; // skip the dot
77-
if (last >= name.size() || !isdigit(name[last])) {
78-
return name;
76+
if (last >= name->size() || !isdigit((*name)[last])) {
77+
return;
7978
}
80-
last = name.find_first_not_of(digits, last);
79+
last = name->find_first_not_of(digits, last);
8180
if (last == std::string::npos) {
82-
name.erase(first);
83-
return name;
81+
name->erase(first);
82+
return;
8483
}
85-
name.erase(first, last - first);
86-
return name;
84+
name->erase(first, last - first);
8785
}
8886

8987
constexpr char digits[] = "0123456789";
9088

9189
// Simplifies the name of a method generated by the runtime as a reflection
9290
// stub. See the test file for examples, or generateName() in
9391
// jdk/internal/reflect/MethodAccessorGenerator.java.
94-
string SimplifyInternalReflectionMethodName(string name) {
95-
return SimplifySuffixedName(
96-
SimplifySuffixedName(
97-
SimplifySuffixedName(
98-
std::move(name),
99-
"jdk.internal.reflect.GeneratedConstructorAccessor",
100-
digits),
101-
"jdk.internal.reflect.GeneratedMethodAccessor",
102-
digits),
92+
void SimplifyInternalReflectionMethodName(string *name) {
93+
SimplifySuffixedName(
94+
name,
95+
"jdk.internal.reflect.GeneratedConstructorAccessor",
96+
digits);
97+
98+
SimplifySuffixedName(
99+
name,
100+
"jdk.internal.reflect.GeneratedMethodAccessor",
101+
digits);
102+
103+
SimplifySuffixedName(
104+
name,
103105
"jdk.internal.reflect.GeneratedSerializationConstructorAccessor",
104106
digits);
105107
}
106108

107109
// Simplifies the name of a method generated by the runtime as a reflection
108110
// stub. See the test file for examples, or generateName() in
109111
// sun/reflect/MethodAccessorGenerator.java.
110-
string SimplifyReflectionMethodName(string name) {
111-
return SimplifySuffixedName(
112-
SimplifySuffixedName(
113-
SimplifySuffixedName(std::move(name),
114-
"sun.reflect.GeneratedConstructorAccessor",
115-
digits),
116-
"sun.reflect.GeneratedMethodAccessor",
117-
digits),
112+
void SimplifyReflectionMethodName(string *name) {
113+
SimplifySuffixedName(
114+
name,
115+
"sun.reflect.GeneratedConstructorAccessor",
116+
digits);
117+
118+
SimplifySuffixedName(
119+
name,
120+
"sun.reflect.GeneratedMethodAccessor",
121+
digits);
122+
123+
SimplifySuffixedName(
124+
name,
118125
"sun.reflect.GeneratedSerializationConstructorAccessor",
119126
digits);
120127
}
@@ -247,12 +254,11 @@ string ParseMethodTypeSignatureWithReturn(const char *buffer, int buffer_size,
247254

248255
} // namespace
249256

250-
string SimplifyFunctionName(const string& name) {
251-
// The calls should be kept nested, without explicit string declarations, so
252-
// that move semantics can be applied to minimize copies.
253-
return SimplifyInternalReflectionMethodName(
254-
SimplifyReflectionMethodName(
255-
SimplifyLambdaName(SimplifyDynamicClassName(name))));
257+
void SimplifyFunctionName(string* name) {
258+
SimplifyDynamicClassName(name);
259+
SimplifyLambdaName(name);
260+
SimplifyReflectionMethodName(name);
261+
SimplifyInternalReflectionMethodName(name);
256262
}
257263

258264
void FixPath(string *s) {

third_party/javaprofiler/stacktrace_fixer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace google {
2626
namespace javaprofiler {
2727
// Simplifies the name of a function to make it more human readable, and group
2828
// related functions under a single name.
29-
string SimplifyFunctionName(const string& name);
29+
void SimplifyFunctionName(string *name);
3030

3131
// Fix the parameter signature from a JVM type signature to a pretty-print
3232
// one.

0 commit comments

Comments
 (0)