Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
673 changes: 1 addition & 672 deletions Analyzer/Properties/Resources.Designer.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Analyzer/Resources/AssetBundle.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- tables related to the AssetBundle and PreloadData objects

-- Do not confuse the AssetBundle Unity object (the source of much of this data)
-- with the asset_bundles table, which is general to any Unity Archive.
-- with the archives table, which is general to any Unity Archive.

-- The "assets" that an AssetBundle explicitly exposes: each m_Container entry of the AssetBundle
-- object names an object (the addressable/asset name -> object it maps to). Populated only from
Expand Down Expand Up @@ -34,7 +34,7 @@ SELECT
FROM assetbundle_assets a INNER JOIN object_view o ON o.id = a.object;

CREATE VIEW IF NOT EXISTS preload_dependencies_view AS
SELECT a.id, a.asset_name, a.asset_bundle, a.type, od.id dep_id, od.asset_bundle dep_asset_bundle, od.name dep_name, od.type dep_type
SELECT a.id, a.asset_name, a.archive, a.type, od.id dep_id, od.archive dep_archive, od.name dep_name, od.type dep_type
FROM assetbundle_asset_view a
INNER JOIN preload_dependencies d ON a.id = d.object
INNER JOIN object_view od ON od.id = d.dependency;
6 changes: 3 additions & 3 deletions Analyzer/Resources/BuildReport.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ CREATE TABLE IF NOT EXISTS build_report_files(

CREATE TABLE IF NOT EXISTS build_report_archive_contents(
build_report_id INTEGER NOT NULL,
assetbundle TEXT NOT NULL,
assetbundle_content TEXT NOT NULL,
PRIMARY KEY (build_report_id, assetbundle_content),
archive TEXT NOT NULL,
archive_content TEXT NOT NULL,
PRIMARY KEY (build_report_id, archive_content),
FOREIGN KEY (build_report_id) REFERENCES build_reports(id)
);

Expand Down
23 changes: 11 additions & 12 deletions Analyzer/Resources/Init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ CREATE TABLE IF NOT EXISTS types
-- Describes a unity archive that contains serialized files and other built content.
-- A common use of the unity archive is for AssetBundles but it can also be used for
-- Player, Content Archive and ContentDirectory builds.
--
-- See issue 68 for proposed rename
CREATE TABLE IF NOT EXISTS asset_bundles
CREATE TABLE IF NOT EXISTS archives
(
id INTEGER,
name TEXT,
Expand All @@ -26,12 +24,12 @@ CREATE TABLE IF NOT EXISTS asset_bundles
-- "BuildPlayer-<SceneName>"; the Scriptable Build Pipeline / Addressables uses
-- "CAB-<hash of scene path>"; the Multi-Process Build Pipeline uses "CAB-<scene GUID>".
-- * Player builds name scenes "level0", "level1", ... in scene-list order.
-- asset_bundle references the row from asset_bundles table of the unity archive containing this file,
-- archive references the row from archives table of the unity archive containing this file,
-- or is '' when the file is not inside an unity archive; object_view turns that '' into NULL.
Comment on lines +27 to 28

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment below

CREATE TABLE IF NOT EXISTS serialized_files
(
id INTEGER,
asset_bundle INTEGER,
archive INTEGER,
name TEXT,
PRIMARY KEY (id)
);
Expand Down Expand Up @@ -91,7 +89,7 @@ INNER JOIN property_names pn ON r.property_path = pn.id
INNER JOIN property_types pt ON r.property_type = pt.id;

CREATE VIEW object_view AS
SELECT o.id, o.object_id, ab.name AS asset_bundle, sf.name AS serialized_file, t.name AS type, o.name, o.game_object, o.size,
SELECT o.id, o.object_id, ab.name AS archive, sf.name AS serialized_file, t.name AS type, o.name, o.game_object, o.size,
CASE
WHEN size < 1024 THEN printf('%!5.1f B', size * 1.0)
WHEN size >= 1024 AND size < (1024 * 1024) THEN printf('%!5.1f KB', size / 1024.0)
Expand All @@ -101,7 +99,7 @@ END AS pretty_size, o.crc32
FROM objects o
INNER JOIN types t ON o.type = t.id
INNER JOIN serialized_files sf ON o.serialized_file = sf.id
LEFT JOIN asset_bundles ab ON sf.asset_bundle = ab.id;
LEFT JOIN archives ab ON sf.archive = ab.id;

CREATE VIEW view_breakdown_by_type AS
SELECT *,
Expand All @@ -128,21 +126,21 @@ END AS pretty_total_size,
sum(size) AS total_size,
size,
pretty_size,
REPLACE(GROUP_CONCAT(DISTINCT IIF(asset_bundle IS NULL, serialized_file, asset_bundle)), ',', ',' || CHAR(13)) AS in_files
REPLACE(GROUP_CONCAT(DISTINCT IIF(archive IS NULL, serialized_file, archive)), ',', ',' || CHAR(13)) AS in_files
FROM object_view
GROUP BY name, type, size, crc32
HAVING instances > 1
ORDER BY size DESC, instances DESC;

CREATE VIEW view_material_shader_refs AS
SELECT m.id material_id, m.name material_name, a.name material_path, m.asset_bundle material_asset_bundle, s.id shader_id, s.name shader_name, s.asset_bundle shader_asset_bundle
SELECT m.id material_id, m.name material_name, a.name material_path, m.archive material_archive, s.id shader_id, s.name shader_name, s.archive shader_archive
FROM object_view m
INNER JOIN refs_view r ON m.id = r.object AND r.property_path = 'm_Shader'
INNER JOIN object_view s ON r.referenced_object = s.id
LEFT JOIN assetbundle_assets a ON m.id = a.object;

CREATE VIEW view_material_texture_refs AS
SELECT m.id material_id, m.name material_name, a.name material_path, m.asset_bundle material_asset_bundle, t.id texture_id, t.name texture_name, t.asset_bundle texture_asset_bundle
SELECT m.id material_id, m.name material_name, a.name material_path, m.archive material_archive, t.id texture_id, t.name texture_name, t.archive texture_archive
FROM object_view m
INNER JOIN refs_view r ON r.object = m.id AND property_type = 'Texture'
INNER JOIN object_view t ON r.referenced_object = t.id
Expand All @@ -156,8 +154,9 @@ INSERT INTO types (id, name) VALUES (-1, 'Scene');
-- Database schema version. Bump when the schema changes in a way that tools relying on it
-- (e.g. find-refs) cannot read from an older database. 1 = normalized refs table (issue #44);
-- 2 = renamed assets/asset_dependencies tables to assetbundle_assets/preload_dependencies
-- (issue #82); databases produced before versioning report 0.
PRAGMA user_version = 2;
-- (issue #82); 3 = renamed asset_bundles table to archives and the asset_bundle column/alias
-- to archive (issue #68); databases produced before versioning report 0.
PRAGMA user_version = 3;

PRAGMA synchronous = OFF;
PRAGMA journal_mode = MEMORY;
4 changes: 2 additions & 2 deletions Analyzer/Resources/MonoScript.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CREATE VIEW monoscript_view AS
SELECT
o.id,
o.object_id,
o.asset_bundle,
o.archive,
o.serialized_file,
m.class_name,
m.namespace,
Expand All @@ -21,7 +21,7 @@ CREATE VIEW script_object_view AS
SELECT
mb.id,
mb.object_id,
mb.asset_bundle,
mb.archive,
mb.serialized_file,
ms.class_name,
ms.namespace,
Expand Down
8 changes: 4 additions & 4 deletions Analyzer/Resources/PackedAssets.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CREATE VIEW build_report_packed_assets_view AS
SELECT
pa.id,
o.object_id,
brac.assetbundle,
brac.archive,
pa.path,
pa.file_header_size,
br_obj.id as build_report_id,
Expand All @@ -36,12 +36,12 @@ FROM build_report_packed_assets pa
INNER JOIN objects o ON pa.id = o.id
INNER JOIN serialized_files sf ON o.serialized_file = sf.id
LEFT JOIN objects br_obj ON o.serialized_file = br_obj.serialized_file AND br_obj.type = 1125
LEFT JOIN build_report_archive_contents brac ON br_obj.id = brac.build_report_id AND pa.path = brac.assetbundle_content;
LEFT JOIN build_report_archive_contents brac ON br_obj.id = brac.build_report_id AND pa.path = brac.archive_content;

CREATE VIEW build_report_packed_asset_contents_view AS
SELECT
sf.name as serialized_file,
brac.assetbundle,
brac.archive,
pa.path,
pac.packed_assets_id,
pac.object_id,
Expand All @@ -57,5 +57,5 @@ LEFT JOIN objects o ON o.id = pa.id
INNER JOIN serialized_files sf ON o.serialized_file = sf.id
LEFT JOIN build_report_source_assets sa ON pac.source_asset_id = sa.id
LEFT JOIN objects br_obj ON o.serialized_file = br_obj.serialized_file AND br_obj.type = 1125
LEFT JOIN build_report_archive_contents brac ON br_obj.id = brac.build_report_id AND pa.path = brac.assetbundle_content;
LEFT JOIN build_report_archive_contents brac ON br_obj.id = brac.build_report_id AND pa.path = brac.archive_content;

2 changes: 1 addition & 1 deletion Analyzer/Resources/Shader.sql
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ CASE
WHEN sum(size) >= (1024 * 1024) AND sum(size) < (1024 * 1024 * 1024) THEN printf('%!5.1f MB', sum(size) / 1024.0 / 1024)
WHEN sum(size) >= (1024 * 1024 * 1024) THEN printf('%!5.1f GB', sum(size) / 1024.0 / 1024 / 1024)
END AS pretty_total_size,
sum(size) AS total_size, GROUP_CONCAT(asset_bundle, ',' || CHAR(13)) AS in_bundles
sum(size) AS total_size, GROUP_CONCAT(archive, ',' || CHAR(13)) AS in_archives
FROM shader_view
GROUP BY name
ORDER BY total_size DESC, instances DESC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
namespace UnityDataTools.Analyzer.SQLite.Commands.SerializedFile
{
/* TABLE DEFINITION:
create table asset_bundles
create table archives
(
id INTEGER,
name TEXT,
file_size INTEGER,
PRIMARY KEY (id)
);
*/
internal class AddAssetBundle : AbstractCommand
internal class AddArchive : AbstractCommand
{
protected override string TableName => "asset_bundles";
protected override string TableName => "archives";

protected override string DDLSource => null;

Expand Down
4 changes: 2 additions & 2 deletions Analyzer/SQLite/Commands/SerializedFile/AddSerializedFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace UnityDataTools.Analyzer.SQLite.Commands.SerializedFile
create table serialized_files
(
id INTEGER,
asset_bundle INTEGER,
archive INTEGER,
name TEXT,
PRIMARY KEY (id)
);
Expand All @@ -22,7 +22,7 @@ internal class AddSerializedFile : AbstractCommand
protected override Dictionary<string, SqliteType> Fields => new()
{
{ "id", SqliteType.Integer },
{ "asset_bundle", SqliteType.Integer },
{ "archive", SqliteType.Integer },
{ "name", SqliteType.Text }
};
}
Expand Down
14 changes: 7 additions & 7 deletions Analyzer/SQLite/Handlers/BuildReportHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ public void Init(SqliteConnection db)

m_InsertArchiveContentCommand = db.CreateCommand();
m_InsertArchiveContentCommand.CommandText = @"INSERT INTO build_report_archive_contents(
build_report_id, assetbundle, assetbundle_content
build_report_id, archive, archive_content
) VALUES(
@build_report_id, @assetbundle, @assetbundle_content
@build_report_id, @archive, @archive_content
)";

m_InsertArchiveContentCommand.Parameters.Add("@build_report_id", SqliteType.Integer);
m_InsertArchiveContentCommand.Parameters.Add("@assetbundle", SqliteType.Text);
m_InsertArchiveContentCommand.Parameters.Add("@assetbundle_content", SqliteType.Text);
m_InsertArchiveContentCommand.Parameters.Add("@archive", SqliteType.Text);
m_InsertArchiveContentCommand.Parameters.Add("@archive_content", SqliteType.Text);
}

public void Process(Context ctx, long objectId, RandomAccessReader reader, out string name, out long streamDataSize)
Expand Down Expand Up @@ -106,12 +106,12 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
}

// Insert archive contents mapping
foreach (var mapping in buildReport.fileListAssetBundleHelper.internalNameToArchiveMapping)
foreach (var mapping in buildReport.fileListArchiveHelper.internalNameToArchiveMapping)
{
m_InsertArchiveContentCommand.Transaction = ctx.Transaction;
m_InsertArchiveContentCommand.Parameters["@build_report_id"].Value = objectId;
m_InsertArchiveContentCommand.Parameters["@assetbundle"].Value = mapping.Value;
m_InsertArchiveContentCommand.Parameters["@assetbundle_content"].Value = mapping.Key;
m_InsertArchiveContentCommand.Parameters["@archive"].Value = mapping.Value;
m_InsertArchiveContentCommand.Parameters["@archive_content"].Value = mapping.Key;
m_InsertArchiveContentCommand.ExecuteNonQuery();
}

Expand Down
2 changes: 1 addition & 1 deletion Analyzer/SQLite/Handlers/ISQLiteHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace UnityDataTools.Analyzer.SQLite.Handlers;

public class Context
{
public int AssetBundleId { get; init; }
public int ArchiveId { get; init; }
public int SerializedFileId { get; init; }
public int SceneId { get; init; }
public Util.ObjectIdProvider ObjectIdProvider { get; init; }
Expand Down
8 changes: 4 additions & 4 deletions Analyzer/SQLite/Parsers/SerializedFileParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ void ProcessFile(string file, string rootDirectory)

try
{
var assetBundleName = Path.GetRelativePath(rootDirectory, file);
var archiveName = Path.GetRelativePath(rootDirectory, file);

m_Writer.BeginAssetBundle(assetBundleName, new FileInfo(file).Length);
m_Writer.BeginArchive(archiveName, new FileInfo(file).Length);

foreach (var node in archive.Nodes)
{
Expand All @@ -114,7 +114,7 @@ void ProcessFile(string file, string rootDirectory)
// or 'UNIQUE constraint failed: objects.id' which can happen
// if AssetBundles from different builds are being processed by a single call to Analyze
// or if there is a Unity Data Tool bug.
Console.Error.WriteLine($"Error processing {node.Path} in archive {assetBundleName}");
Console.Error.WriteLine($"Error processing {node.Path} in archive {archiveName}");
Console.Error.WriteLine(e.Message);
Console.Error.WriteLine();

Expand All @@ -127,7 +127,7 @@ void ProcessFile(string file, string rootDirectory)
}
finally
{
m_Writer.EndAssetBundle();
m_Writer.EndArchive();
}
}

Expand Down
38 changes: 19 additions & 19 deletions Analyzer/SQLite/Writers/SerializedFileSQLiteWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class SerializedFileSQLiteWriter : IDisposable
{
private HashSet<int> m_TypeSet = new();

private int m_CurrentAssetBundleId = -1;
private int m_NextAssetBundleId = 0;
private int m_CurrentArchiveId = -1;
private int m_NextArchiveId = 0;

private bool m_SkipReferences;
private bool m_SkipCrc;
Expand Down Expand Up @@ -69,7 +69,7 @@ public class SerializedFileSQLiteWriter : IDisposable
private AddReference m_AddReferenceCommand = new AddReference();
private AddPropertyName m_AddPropertyNameCommand = new AddPropertyName();
private AddPropertyType m_AddPropertyTypeCommand = new AddPropertyType();
private AddAssetBundle m_AddAssetBundleCommand = new AddAssetBundle();
private AddArchive m_AddArchiveCommand = new AddArchive();
private AddSerializedFile m_AddSerializedFileCommand = new AddSerializedFile();
private AddObject m_AddObjectCommand = new AddObject();
private AddType m_AddTypeCommand = new AddType();
Expand Down Expand Up @@ -107,7 +107,7 @@ private void CreateSQLiteCommands()
m_AddReferenceCommand.CreateCommand(m_Database);
m_AddPropertyNameCommand.CreateCommand(m_Database);
m_AddPropertyTypeCommand.CreateCommand(m_Database);
m_AddAssetBundleCommand.CreateCommand(m_Database);
m_AddArchiveCommand.CreateCommand(m_Database);
m_AddSerializedFileCommand.CreateCommand(m_Database);
m_AddObjectCommand.CreateCommand(m_Database);
m_AddTypeCommand.CreateCommand(m_Database);
Expand All @@ -116,28 +116,28 @@ private void CreateSQLiteCommands()
m_LastId = m_Database.CreateCommand();
m_LastId.CommandText = "SELECT last_insert_rowid()";
}
public void BeginAssetBundle(string name, long size)
public void BeginArchive(string name, long size)
{
if (m_CurrentAssetBundleId != -1)
if (m_CurrentArchiveId != -1)
{
throw new InvalidOperationException("SQLWriter.BeginAssetBundle called twice");
throw new InvalidOperationException("SQLWriter.BeginArchive called twice");
}

m_CurrentAssetBundleId = m_NextAssetBundleId++;
m_AddAssetBundleCommand.SetValue("id", m_CurrentAssetBundleId);
m_AddAssetBundleCommand.SetValue("name", name);
m_AddAssetBundleCommand.SetValue("file_size", size);
m_AddAssetBundleCommand.ExecuteNonQuery();
m_CurrentArchiveId = m_NextArchiveId++;
m_AddArchiveCommand.SetValue("id", m_CurrentArchiveId);
m_AddArchiveCommand.SetValue("name", name);
m_AddArchiveCommand.SetValue("file_size", size);
m_AddArchiveCommand.ExecuteNonQuery();
}

public void EndAssetBundle()
public void EndArchive()
{
if (m_CurrentAssetBundleId == -1)
if (m_CurrentArchiveId == -1)
{
throw new InvalidOperationException("SQLWriter.EndAssetBundle called before SQLWriter.BeginAssetBundle");
throw new InvalidOperationException("SQLWriter.EndArchive called before SQLWriter.BeginArchive");
}

m_CurrentAssetBundleId = -1;
m_CurrentArchiveId = -1;
}

public void WriteSerializedFile(string relativePath, string fullPath, string containingFolder)
Expand Down Expand Up @@ -214,7 +214,7 @@ public void WriteSerializedFile(string relativePath, string fullPath, string con

Context ctx = new()
{
AssetBundleId = m_CurrentAssetBundleId,
ArchiveId = m_CurrentArchiveId,
SerializedFileId = serializedFileId,
SceneId = sceneId,
ObjectIdProvider = m_ObjectIdProvider,
Expand All @@ -228,7 +228,7 @@ public void WriteSerializedFile(string relativePath, string fullPath, string con
{
m_AddSerializedFileCommand.SetTransaction(transaction);
m_AddSerializedFileCommand.SetValue("id", serializedFileId);
m_AddSerializedFileCommand.SetValue("asset_bundle", m_CurrentAssetBundleId == -1 ? "" : m_CurrentAssetBundleId);
m_AddSerializedFileCommand.SetValue("archive", m_CurrentArchiveId == -1 ? "" : m_CurrentArchiveId);
m_AddSerializedFileCommand.SetValue("name", relativePath);
Comment on lines 229 to 232

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment below

m_AddSerializedFileCommand.ExecuteNonQuery();

Expand Down Expand Up @@ -387,7 +387,7 @@ public void Dispose()
}

// Serialized file dispose calls
m_AddAssetBundleCommand.Dispose();
m_AddArchiveCommand.Dispose();
m_AddSerializedFileCommand.Dispose();
m_AddReferenceCommand.Dispose();
m_AddPropertyNameCommand.Dispose();
Expand Down
Loading
Loading