Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: delta_diff_generator.cc

Issue 3526012: AU: generate a delta payload usage report (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: review feedback Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "update_engine/delta_diff_generator.h" 5 #include "update_engine/delta_diff_generator.h"
6
7 #include <errno.h>
8 #include <fcntl.h>
6 #include <sys/stat.h> 9 #include <sys/stat.h>
7 #include <sys/types.h> 10 #include <sys/types.h>
8 #include <errno.h> 11
9 #include <fcntl.h>
10 #include <algorithm> 12 #include <algorithm>
11 #include <set> 13 #include <set>
12 #include <string> 14 #include <string>
13 #include <utility> 15 #include <utility>
14 #include <vector> 16 #include <vector>
17
18 #include <base/logging.h>
19 #include <base/string_util.h>
15 #include <bzlib.h> 20 #include <bzlib.h>
16 #include "base/logging.h" 21
17 #include "update_engine/bzip.h" 22 #include "update_engine/bzip.h"
18 #include "update_engine/cycle_breaker.h" 23 #include "update_engine/cycle_breaker.h"
19 #include "update_engine/extent_mapper.h" 24 #include "update_engine/extent_mapper.h"
20 #include "update_engine/file_writer.h" 25 #include "update_engine/file_writer.h"
21 #include "update_engine/filesystem_iterator.h" 26 #include "update_engine/filesystem_iterator.h"
22 #include "update_engine/graph_types.h" 27 #include "update_engine/graph_types.h"
23 #include "update_engine/graph_utils.h" 28 #include "update_engine/graph_utils.h"
24 #include "update_engine/payload_signer.h" 29 #include "update_engine/payload_signer.h"
25 #include "update_engine/subprocess.h" 30 #include "update_engine/subprocess.h"
26 #include "update_engine/topological_sort.h" 31 #include "update_engine/topological_sort.h"
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 465
461 // There's a single dest extent 466 // There's a single dest extent
462 Extent* dst_extent = op->add_dst_extents(); 467 Extent* dst_extent = op->add_dst_extents();
463 dst_extent->set_start_block(0); 468 dst_extent->set_start_block(0);
464 dst_extent->set_num_blocks((new_part_size + kBlockSize - 1) / kBlockSize); 469 dst_extent->set_num_blocks((new_part_size + kBlockSize - 1) / kBlockSize);
465 470
466 LOG(INFO) << "Done compressing kernel partition."; 471 LOG(INFO) << "Done compressing kernel partition.";
467 return true; 472 return true;
468 } 473 }
469 474
475 struct DeltaObject {
476 DeltaObject(const string& in_name, const int in_type, const off_t in_size)
477 : name(in_name),
478 type(in_type),
479 size(in_size) {}
480 bool operator <(const DeltaObject& object) const {
481 return size < object.size;
482 }
483 string name;
484 int type;
485 off_t size;
486 };
487
488 static const char* kInstallOperationTypes[] = {
489 "REPLACE",
490 "REPLACE_BZ",
491 "MOVE",
492 "BSDIFF"
493 };
494
495 void ReportPayloadUsage(const Graph& graph,
496 const DeltaArchiveManifest& manifest) {
497 vector<DeltaObject> objects;
498 off_t total_size = 0;
499
500 // Graph nodes with information about file names.
501 for (Vertex::Index node = 0; node < graph.size(); node++) {
502 objects.push_back(DeltaObject(graph[node].file_name,
503 graph[node].op.type(),
504 graph[node].op.data_length()));
505 total_size += graph[node].op.data_length();
506 }
507
508 // Final rootfs operation writing non-file-data.
509 const DeltaArchiveManifest_InstallOperation& final_op =
510 manifest.install_operations(manifest.install_operations_size() - 1);
511 objects.push_back(DeltaObject("<rootfs-final-operation>",
512 final_op.type(),
513 final_op.data_length()));
514 total_size += final_op.data_length();
515
516 // Kernel install operations.
517 for (int i = 0; i < manifest.kernel_install_operations_size(); ++i) {
518 const DeltaArchiveManifest_InstallOperation& op =
519 manifest.kernel_install_operations(i);
520 objects.push_back(DeltaObject(StringPrintf("<kernel-operation-%d>", i),
521 op.type(),
522 op.data_length()));
523 total_size += op.data_length();
524 }
525
526 std::sort(objects.begin(), objects.end());
527
528 static const char kFormatString[] = "%6.2f%% %10llu %-10s %s\n";
529 for (vector<DeltaObject>::const_iterator it = objects.begin();
530 it != objects.end(); ++it) {
531 const DeltaObject& object = *it;
532 fprintf(stderr, kFormatString,
533 object.size * 100.0 / total_size,
534 object.size,
535 kInstallOperationTypes[object.type],
536 object.name.c_str());
537 }
538 fprintf(stderr, kFormatString, 100.0, total_size, "", "<total>");
539 }
540
470 } // namespace {} 541 } // namespace {}
471 542
472 bool DeltaDiffGenerator::ReadFileToDiff( 543 bool DeltaDiffGenerator::ReadFileToDiff(
473 const string& old_filename, 544 const string& old_filename,
474 const string& new_filename, 545 const string& new_filename,
475 vector<char>* out_data, 546 vector<char>* out_data,
476 DeltaArchiveManifest_InstallOperation* out_op) { 547 DeltaArchiveManifest_InstallOperation* out_op) {
477 // Read new data in 548 // Read new data in
478 vector<char> new_data; 549 vector<char> new_data;
479 TEST_AND_RETURN_FALSE(utils::ReadFile(new_filename, &new_data)); 550 TEST_AND_RETURN_FALSE(utils::ReadFile(new_filename, &new_data));
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 LOG(INFO) << "Signing the update..."; 1048 LOG(INFO) << "Signing the update...";
978 vector<char> signature_blob; 1049 vector<char> signature_blob;
979 TEST_AND_RETURN_FALSE(PayloadSigner::SignPayload(output_path, 1050 TEST_AND_RETURN_FALSE(PayloadSigner::SignPayload(output_path,
980 private_key_path, 1051 private_key_path,
981 &signature_blob)); 1052 &signature_blob));
982 TEST_AND_RETURN_FALSE(writer.Write(&signature_blob[0], 1053 TEST_AND_RETURN_FALSE(writer.Write(&signature_blob[0],
983 signature_blob.size()) == 1054 signature_blob.size()) ==
984 static_cast<ssize_t>(signature_blob.size())); 1055 static_cast<ssize_t>(signature_blob.size()));
985 } 1056 }
986 1057
1058 ReportPayloadUsage(graph, manifest);
1059
987 LOG(INFO) << "All done. Successfully created delta file."; 1060 LOG(INFO) << "All done. Successfully created delta file.";
988 return true; 1061 return true;
989 } 1062 }
990 1063
991 const char* const kBsdiffPath = "/usr/bin/bsdiff"; 1064 const char* const kBsdiffPath = "/usr/bin/bsdiff";
992 const char* const kBspatchPath = "/usr/bin/bspatch"; 1065 const char* const kBspatchPath = "/usr/bin/bspatch";
993 const char* const kDeltaMagic = "CrAU"; 1066 const char* const kDeltaMagic = "CrAU";
994 1067
995 }; // namespace chromeos_update_engine 1068 }; // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698