mirror of
https://github.com/StarBeat/UnityDependencyAnalyzer.git
synced 2026-03-08 05:35:27 +08:00
Compare commits
No commits in common. "835ede37f61b83b47e0cc29f6f8d9f32f8f44376" and "d2239d7f291457a41690749c05d39c4ad79f3a00" have entirely different histories.
835ede37f6
...
d2239d7f29
21
LICENSE
21
LICENSE
@ -1,21 +0,0 @@
|
|||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2025 StarBeats
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
@ -1,5 +1,4 @@
|
|||||||
using MemoryPack;
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
using MongoDB.Bson.Serialization.Attributes;
|
|
||||||
using MongoDB.Driver;
|
using MongoDB.Driver;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
@ -9,8 +8,7 @@ using System.Text.Json.Serialization;
|
|||||||
namespace AssetDependencyGraph
|
namespace AssetDependencyGraph
|
||||||
{
|
{
|
||||||
[BsonIgnoreExtraElements]
|
[BsonIgnoreExtraElements]
|
||||||
[MemoryPackable]
|
public class AssetIdentify
|
||||||
public partial class AssetIdentify
|
|
||||||
{
|
{
|
||||||
public string Path = null!;
|
public string Path = null!;
|
||||||
public string AssetType = null!;
|
public string AssetType = null!;
|
||||||
@ -46,8 +44,7 @@ namespace AssetDependencyGraph
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BsonIgnoreExtraElements]
|
[BsonIgnoreExtraElements]
|
||||||
[MemoryPackable]
|
public class AssetNode
|
||||||
public partial class AssetNode
|
|
||||||
{
|
{
|
||||||
public AssetIdentify Self=null!;
|
public AssetIdentify Self=null!;
|
||||||
public string AssetType=null!;
|
public string AssetType=null!;
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using MemoryPack;
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
using MongoDB.Bson.Serialization.Attributes;
|
|
||||||
using MongoDB.Bson.Serialization.Options;
|
using MongoDB.Bson.Serialization.Options;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
@ -240,7 +239,7 @@ namespace AssetDependencyGraph
|
|||||||
[BsonDictionaryOptions(Representation = DictionaryRepresentation.ArrayOfArrays)]
|
[BsonDictionaryOptions(Representation = DictionaryRepresentation.ArrayOfArrays)]
|
||||||
private ConcurrentDictionary<AssetIdentify, AssetNode> assetIdentify2AssetNodeDic = new();
|
private ConcurrentDictionary<AssetIdentify, AssetNode> assetIdentify2AssetNodeDic = new();
|
||||||
private ConcurrentDictionary<string, AssetIdentify> path2Id = new();
|
private ConcurrentDictionary<string, AssetIdentify> path2Id = new();
|
||||||
private ConcurrentBag<(string path, bool isDir)> allPath = new();
|
private List<(string path, bool isDir)> allPath = new();
|
||||||
private UnityLmdb unityLmdb;
|
private UnityLmdb unityLmdb;
|
||||||
private static Regex isGuid = new Regex("^[\\da-f]{32}$");
|
private static Regex isGuid = new Regex("^[\\da-f]{32}$");
|
||||||
|
|
||||||
@ -336,19 +335,19 @@ namespace AssetDependencyGraph
|
|||||||
unityLmdb.ResolveGuidPath();
|
unityLmdb.ResolveGuidPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask AnalyzeMainProcess(string projectPath, string rootFolder, int processCnt = 8)
|
public void AnalyzeMainProcess(string rootFolder, int processCnt = 8)
|
||||||
{
|
{
|
||||||
Stopwatch sw = Stopwatch.StartNew();
|
Stopwatch sw = Stopwatch.StartNew();
|
||||||
sw.Start();
|
sw.Start();
|
||||||
Utils.TraverseDirectoryParallel(rootFolder, Visivt);
|
Utils.TraverseDirectory(rootFolder, Visivt, -1);
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
Console.WriteLine($"遍历目录耗时:{sw.ElapsedMilliseconds / 1000f}s");
|
Console.WriteLine($"遍历目录耗时:{sw.ElapsedMilliseconds / 1000f}s");
|
||||||
|
|
||||||
sw.Restart();
|
sw.Restart();
|
||||||
var itemCnt = allPath.Count / processCnt;
|
var itemCnt = allPath.Count / processCnt;
|
||||||
List<string> subProcessArgs = new();
|
List<string> subProcessArgs = new();
|
||||||
List<string> resultPaths = new();
|
List<string> resultJsonPaths = new();
|
||||||
var allPathArray = allPath.ToArray();
|
var projectPath = Environment.GetCommandLineArgs()[1];
|
||||||
for (int i = 0; i < processCnt; i++)
|
for (int i = 0; i < processCnt; i++)
|
||||||
{
|
{
|
||||||
int r = (itemCnt * (i + 1));
|
int r = (itemCnt * (i + 1));
|
||||||
@ -356,12 +355,12 @@ namespace AssetDependencyGraph
|
|||||||
{
|
{
|
||||||
r = allPath.Count;
|
r = allPath.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
var s = JsonSerializer.Serialize(allPathArray[(i * itemCnt)..r], options);
|
var s = JsonSerializer.Serialize(allPath[(i * itemCnt)..r], options);
|
||||||
var jsonPath = Path.Combine(Path.GetTempPath(), $"path{i}.json");
|
var jsonPath = Path.Combine(Path.GetTempPath(), $"path{i}.json");
|
||||||
var resulPath = Path.Combine(Path.GetTempPath(), $"result{i}.bin");
|
var resulJsonPath = Path.Combine(Path.GetTempPath(), $"result{i}.json");
|
||||||
resultPaths.Add(resulPath);
|
resultJsonPaths.Add(resulJsonPath);
|
||||||
subProcessArgs.Add($"-reference {projectPath} SubProcess {jsonPath} {resulPath}");
|
subProcessArgs.Add($"-reference {projectPath} SubProcess {jsonPath} {resulJsonPath}");
|
||||||
File.WriteAllText(jsonPath, s);
|
File.WriteAllText(jsonPath, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,10 +400,10 @@ namespace AssetDependencyGraph
|
|||||||
|
|
||||||
Task.WaitAll(subProcessTask);
|
Task.WaitAll(subProcessTask);
|
||||||
List<Dictionary<string, HashSet<string>>> subProcessResults = new();
|
List<Dictionary<string, HashSet<string>>> subProcessResults = new();
|
||||||
foreach (var item in resultPaths)
|
foreach (var item in resultJsonPaths)
|
||||||
{
|
{
|
||||||
var s = File.ReadAllBytes(item);
|
var s = File.ReadAllText(item);
|
||||||
subProcessResults.Add(MemoryPackSerializer.Deserialize<Dictionary<string, HashSet<string>>>(s.AsSpan())!);
|
subProcessResults.Add(JsonSerializer.Deserialize<Dictionary<string, HashSet<string>>>(s, options)!);
|
||||||
}
|
}
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
Console.WriteLine($"分析引用耗时:{sw.ElapsedMilliseconds / 1000f}s");
|
Console.WriteLine($"分析引用耗时:{sw.ElapsedMilliseconds / 1000f}s");
|
||||||
@ -419,10 +418,14 @@ namespace AssetDependencyGraph
|
|||||||
item.Value.DependentSet = item.Value.Dependent.ToHashSet();
|
item.Value.DependentSet = item.Value.Dependent.ToHashSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
using var wr = File.OpenWrite(Path.Combine(UnityLmdb.ProjPath, "Library", "dependencyGraph.bin"));
|
string js = JsonSerializer.Serialize(assetIdentify2AssetNodeDic, options: new()
|
||||||
await MemoryPackSerializer.SerializeAsync(wr, assetIdentify2AssetNodeDic);
|
{
|
||||||
sw.Stop();
|
IncludeFields = true,
|
||||||
Console.WriteLine($"写入文件耗时:{sw.ElapsedMilliseconds / 1000f}s");
|
Converters = { new AssetIdentifyJsonConverter(), new AssetNodeJsonConverter() }
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
File.WriteAllText(Path.Combine(UnityLmdb.ProjPath, "Library", "dependencyGraph.json"), js);
|
||||||
|
|
||||||
//AssetDependencyGraphDB db = new AssetDependencyGraphDB(Environment.GetCommandLineArgs()[2], Environment.GetCommandLineArgs()[3], Environment.GetCommandLineArgs()[4]);
|
//AssetDependencyGraphDB db = new AssetDependencyGraphDB(Environment.GetCommandLineArgs()[2], Environment.GetCommandLineArgs()[3], Environment.GetCommandLineArgs()[4]);
|
||||||
//sw.Restart();
|
//sw.Restart();
|
||||||
@ -431,8 +434,8 @@ namespace AssetDependencyGraph
|
|||||||
//{
|
//{
|
||||||
// db.Insert(item.Value);
|
// db.Insert(item.Value);
|
||||||
//});
|
//});
|
||||||
//sw.Stop();
|
sw.Stop();
|
||||||
//Console.WriteLine($"更新数据库:{sw.ElapsedMilliseconds / 1000f}s");
|
Console.WriteLine($"更新数据库:{sw.ElapsedMilliseconds / 1000f}s");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResolveSubProcessResult(Dictionary<string, HashSet<string>> subProcessResult)
|
private void ResolveSubProcessResult(Dictionary<string, HashSet<string>> subProcessResult)
|
||||||
@ -488,26 +491,25 @@ namespace AssetDependencyGraph
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask AnalyzeSubProcess(string pathFile, string resultFilePath)
|
public void AnalyzeSubProcess(string pathFile, string resultFilePath)
|
||||||
{
|
{
|
||||||
var s = File.ReadAllText(pathFile);
|
var s = File.ReadAllText(pathFile);
|
||||||
var allPath = JsonSerializer.Deserialize<List<(string path, bool isDir)>>(s, options)!;
|
allPath = JsonSerializer.Deserialize<List<(string path, bool isDir)>>(s, options)!;
|
||||||
if (allPath != null)
|
if (allPath != null)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < allPath.Count; i++)
|
foreach (var item in allPath)
|
||||||
{
|
{
|
||||||
var path = allPath[i];
|
|
||||||
foreach (var item1 in dependencyAnalysisDic)
|
foreach (var item1 in dependencyAnalysisDic)
|
||||||
{
|
{
|
||||||
if (item1.Key(path))
|
if (item1.Key(item))
|
||||||
{
|
{
|
||||||
item1.Value.Analyze(path.path, path2Dependences);
|
item1.Value.Analyze(item.path, path2Dependences);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using var wr = File.OpenWrite(resultFilePath);
|
var json = JsonSerializer.Serialize(path2Dependences, options);
|
||||||
await MemoryPackSerializer.SerializeAsync(wr, path2Dependences);
|
File.WriteAllText(resultFilePath, json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@ -34,15 +34,14 @@ switch (Environment.GetCommandLineArgs()[1])
|
|||||||
{
|
{
|
||||||
UnityLmdb.ProjPath = Environment.GetCommandLineArgs()[2];
|
UnityLmdb.ProjPath = Environment.GetCommandLineArgs()[2];
|
||||||
Utils.DataPath = Path.Combine(UnityLmdb.ProjPath, "Assets").ToUniversalPath();
|
Utils.DataPath = Path.Combine(UnityLmdb.ProjPath, "Assets").ToUniversalPath();
|
||||||
Console.WriteLine(string.Join(' ', Environment.GetCommandLineArgs()));
|
|
||||||
if (Environment.GetCommandLineArgs().Length > 3 && Environment.GetCommandLineArgs()[3].Equals("SubProcess"))
|
if (Environment.GetCommandLineArgs().Length > 3 && Environment.GetCommandLineArgs()[3].Equals("SubProcess"))
|
||||||
{
|
{
|
||||||
//System.Diagnostics.Process.GetCurrentProcess().ProcessorAffinity = (IntPtr)0x00FF;
|
new DependencyAnalyzer().AnalyzeSubProcess(Environment.GetCommandLineArgs()[4], Environment.GetCommandLineArgs()[5]);
|
||||||
await new DependencyAnalyzer().AnalyzeSubProcess(Environment.GetCommandLineArgs()[4], Environment.GetCommandLineArgs()[5]);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await new DependencyAnalyzer().AnalyzeMainProcess(UnityLmdb.ProjPath, Utils.DataPath, 10);
|
new DependencyAnalyzer().AnalyzeMainProcess(Utils.DataPath, 10);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"profiles": {
|
"profiles": {
|
||||||
"UnityDependencyAnalyzer": {
|
"UnityDependencyAnalyzer": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"commandLineArgs": "-reference G:/G_android \" \" \" \" localhost"
|
"commandLineArgs": "G:/G_android \" \" \" \" localhost"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -8,10 +8,6 @@
|
|||||||
<PublishAot>False</PublishAot>
|
<PublishAot>False</PublishAot>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="MemoryPack" Version="1.21.4" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\UnityFileDumper\UnityFileDumper.csproj" />
|
<ProjectReference Include="..\UnityFileDumper\UnityFileDumper.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@ -55,8 +51,4 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
|
||||||
<Exec Command="copy /Y $(ProjectDir)\Libs\lmdb.dll $(TargetDir)
copy /Y $(ProjectDir)\Libs\UnityFileSystemApi.dll $(TargetDir)" />
|
|
||||||
</Target>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -25,27 +25,9 @@ namespace AssetDependencyGraph
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TraverseDirectoryParallel(string path, Action<string> action)
|
|
||||||
{
|
|
||||||
Parallel.ForEach(Directory.EnumerateFileSystemEntries(path, "*", SearchOption.AllDirectories), action);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void TraverseDirectory(string path, Action<string> action, int depth = 1)
|
public static void TraverseDirectory(string path, Action<string> action, int depth = 1)
|
||||||
{
|
{
|
||||||
//if (depth == -1)
|
if(depth == 0)
|
||||||
//{
|
|
||||||
// //foreach (string file in Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories))
|
|
||||||
// //{
|
|
||||||
// // action.Invoke(file);
|
|
||||||
// //}
|
|
||||||
|
|
||||||
// //foreach (string directory in Directory.EnumerateDirectories(path, "*.*", SearchOption.AllDirectories))
|
|
||||||
// //{
|
|
||||||
// // action.Invoke(directory);
|
|
||||||
// //}
|
|
||||||
//}
|
|
||||||
|
|
||||||
if (depth == 0)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user