forked from open-telemetry/opentelemetry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Marshalers for profiling signal type (open-telemetry#6565)
- Loading branch information
1 parent
4545c12
commit 80f3bce
Showing
16 changed files
with
1,352 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...rofiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/AttributeUnitMarshaler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.exporter.otlp.profiles; | ||
|
||
import io.opentelemetry.exporter.internal.marshal.MarshalerUtil; | ||
import io.opentelemetry.exporter.internal.marshal.MarshalerWithSize; | ||
import io.opentelemetry.exporter.internal.marshal.Serializer; | ||
import io.opentelemetry.proto.profiles.v1experimental.internal.AttributeUnit; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
final class AttributeUnitMarshaler extends MarshalerWithSize { | ||
|
||
private static final AttributeUnitMarshaler[] EMPTY_REPEATED = new AttributeUnitMarshaler[0]; | ||
|
||
private final long attributeKey; | ||
private final long unitIndex; | ||
|
||
static AttributeUnitMarshaler create(AttributeUnitData attributeUnitData) { | ||
return new AttributeUnitMarshaler( | ||
attributeUnitData.getAttributeKey(), attributeUnitData.getUnitIndex()); | ||
} | ||
|
||
static AttributeUnitMarshaler[] createRepeated(List<AttributeUnitData> items) { | ||
if (items.isEmpty()) { | ||
return EMPTY_REPEATED; | ||
} | ||
|
||
AttributeUnitMarshaler[] attributeUnitMarshalers = new AttributeUnitMarshaler[items.size()]; | ||
items.forEach( | ||
item -> | ||
new Consumer<AttributeUnitData>() { | ||
int index = 0; | ||
|
||
@Override | ||
public void accept(AttributeUnitData attributeUnitData) { | ||
attributeUnitMarshalers[index++] = AttributeUnitMarshaler.create(attributeUnitData); | ||
} | ||
}); | ||
return attributeUnitMarshalers; | ||
} | ||
|
||
private AttributeUnitMarshaler(long attributeKey, long unitIndex) { | ||
super(calculateSize(attributeKey, unitIndex)); | ||
this.attributeKey = attributeKey; | ||
this.unitIndex = unitIndex; | ||
} | ||
|
||
@Override | ||
protected void writeTo(Serializer output) throws IOException { | ||
output.serializeInt64(AttributeUnit.ATTRIBUTE_KEY, attributeKey); | ||
output.serializeInt64(AttributeUnit.UNIT, unitIndex); | ||
} | ||
|
||
private static int calculateSize(long attributeKey, long unitIndex) { | ||
int size; | ||
size = 0; | ||
size += MarshalerUtil.sizeInt64(AttributeUnit.ATTRIBUTE_KEY, attributeKey); | ||
size += MarshalerUtil.sizeInt64(AttributeUnit.UNIT, unitIndex); | ||
return size; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...tlp/profiles/src/main/java/io/opentelemetry/exporter/otlp/profiles/FunctionMarshaler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.exporter.otlp.profiles; | ||
|
||
import io.opentelemetry.exporter.internal.marshal.MarshalerUtil; | ||
import io.opentelemetry.exporter.internal.marshal.MarshalerWithSize; | ||
import io.opentelemetry.exporter.internal.marshal.Serializer; | ||
import io.opentelemetry.proto.profiles.v1experimental.internal.Function; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
final class FunctionMarshaler extends MarshalerWithSize { | ||
|
||
private static final FunctionMarshaler[] EMPTY_REPEATED = new FunctionMarshaler[0]; | ||
|
||
private final long nameIndex; | ||
private final long systemNameIndex; | ||
private final long filenameIndex; | ||
private final long startLine; | ||
|
||
static FunctionMarshaler create(FunctionData functionData) { | ||
return new FunctionMarshaler( | ||
functionData.getNameIndex(), | ||
functionData.getSystemNameIndex(), | ||
functionData.getFilenameIndex(), | ||
functionData.getStartLine()); | ||
} | ||
|
||
static FunctionMarshaler[] createRepeated(List<FunctionData> items) { | ||
if (items.isEmpty()) { | ||
return EMPTY_REPEATED; | ||
} | ||
|
||
FunctionMarshaler[] functionMarshalers = new FunctionMarshaler[items.size()]; | ||
items.forEach( | ||
item -> | ||
new Consumer<FunctionData>() { | ||
int index = 0; | ||
|
||
@Override | ||
public void accept(FunctionData functionData) { | ||
functionMarshalers[index++] = FunctionMarshaler.create(functionData); | ||
} | ||
}); | ||
return functionMarshalers; | ||
} | ||
|
||
private FunctionMarshaler( | ||
long nameIndex, long systemNameIndex, long filenameIndex, long startLine) { | ||
super(calculateSize(nameIndex, systemNameIndex, filenameIndex, startLine)); | ||
this.nameIndex = nameIndex; | ||
this.systemNameIndex = systemNameIndex; | ||
this.filenameIndex = filenameIndex; | ||
this.startLine = startLine; | ||
} | ||
|
||
@Override | ||
protected void writeTo(Serializer output) throws IOException { | ||
output.serializeInt64(Function.NAME, nameIndex); | ||
output.serializeInt64(Function.SYSTEM_NAME, systemNameIndex); | ||
output.serializeInt64(Function.FILENAME, filenameIndex); | ||
output.serializeInt64(Function.START_LINE, startLine); | ||
} | ||
|
||
private static int calculateSize( | ||
long nameIndex, long systemNameIndex, long filenameIndex, long startLine) { | ||
int size = 0; | ||
size += MarshalerUtil.sizeInt64(Function.NAME, nameIndex); | ||
size += MarshalerUtil.sizeInt64(Function.SYSTEM_NAME, systemNameIndex); | ||
size += MarshalerUtil.sizeInt64(Function.FILENAME, filenameIndex); | ||
size += MarshalerUtil.sizeInt64(Function.START_LINE, startLine); | ||
return size; | ||
} | ||
} |
Oops, something went wrong.