src/Pure/Admin/build_log.scala
changeset 65621 551950dccec6
parent 65619 e33b3d57b7cb
child 65622 52f682598f6b
equal deleted inserted replaced
65620:9b99d61be5af 65621:551950dccec6
    26 
    26 
    27   object Prop
    27   object Prop
    28   {
    28   {
    29     val separator = '\u000b'
    29     val separator = '\u000b'
    30 
    30 
       
    31     def cat_multiple(args: List[String]): String =
       
    32       args.mkString(separator.toString)
       
    33 
    31     def multiple(name: String, args: List[String]): Properties.T =
    34     def multiple(name: String, args: List[String]): Properties.T =
    32       if (args.isEmpty) Nil
    35       if (args.isEmpty) Nil
    33       else List(name -> args.mkString(separator.toString))
    36       else List(name -> cat_multiple(args))
    34 
    37 
    35     def multiple_lines(s: String): String =
    38     def multiple_lines(s: String): String =
    36       cat_lines(Library.space_explode(separator, s))
    39       cat_lines(Library.space_explode(separator, s))
    37 
    40 
    38     val build_tags = SQL.Column.string("build_tags")  // multiple
    41     val build_tags = SQL.Column.string("build_tags")  // multiple
   686           }
   689           }
   687         }
   690         }
   688       }
   691       }
   689     }
   692     }
   690 
   693 
       
   694     def read_meta_info(db: SQL.Database, log_name: String): Option[Meta_Info] =
       
   695     {
       
   696       val cs = Meta_Info.table.columns.tail
       
   697       using(db.select(Meta_Info.table, cs, Meta_Info.log_name.sql_where_equal(log_name)))(stmt =>
       
   698       {
       
   699         val rs = stmt.executeQuery
       
   700         if (!rs.next) None
       
   701         else {
       
   702           val results =
       
   703             cs.map(c => c.name ->
       
   704               (if (c.T == SQL.Type.Date)
       
   705                 db.get(rs, c, db.date _).map(Log_File.Date_Format(_))
       
   706                else
       
   707                 db.get(rs, c, db.string _).map(s => Prop.cat_multiple(split_lines(s)))))
       
   708           val n = Prop.all_props.length
       
   709           val props = for ((x, Some(y)) <- results.take(n)) yield (x, y)
       
   710           val settings = for ((x, Some(y)) <- results.drop(n)) yield (x, y)
       
   711           Some(Meta_Info(props, settings))
       
   712         }
       
   713       })
       
   714     }
       
   715 
   691     def write_build_info(db: SQL.Database, files: List[JFile])
   716     def write_build_info(db: SQL.Database, files: List[JFile])
   692     {
   717     {
   693       for (file_group <- filter_files(db, Build_Info.table, files).grouped(100)) {
   718       for (file_group <- filter_files(db, Build_Info.table, files).grouped(100)) {
   694         db.transaction {
   719         db.transaction {
   695           for (file <- file_group) {
   720           for (file <- file_group) {
   720             })
   745             })
   721           }
   746           }
   722         }
   747         }
   723       }
   748       }
   724     }
   749     }
       
   750 
       
   751     def read_build_info(
       
   752       db: SQL.Database, log_name: String, session_names: List[String] = Nil): Build_Info =
       
   753     {
       
   754       val where_log_name = Meta_Info.log_name.sql_where_equal(log_name)
       
   755       val where =
       
   756         if (session_names.isEmpty) where_log_name
       
   757         else
       
   758           where_log_name + " AND " +
       
   759           session_names.map(a => Build_Info.session_name.sql_name + " = " + SQL.quote_string(a)).
       
   760             mkString("(", " OR ", ")")
       
   761       val sessions =
       
   762         using(db.select(Build_Info.table, Build_Info.table.columns.tail, where))(stmt =>
       
   763         {
       
   764           SQL.iterator(stmt.executeQuery)(rs =>
       
   765           {
       
   766             val session_name = db.string(rs, Build_Info.session_name)
       
   767             val chapter = db.string(rs, Build_Info.chapter)
       
   768             val groups = split_lines(db.string(rs, Build_Info.groups))
       
   769             val threads = db.get(rs, Build_Info.threads, db.int _)
       
   770             val timing_elapsed = Time.ms(db.long(rs, Build_Info.timing_elapsed))
       
   771             val timing_cpu = Time.ms(db.long(rs, Build_Info.timing_cpu))
       
   772             val timing_gc = Time.ms(db.long(rs, Build_Info.timing_gc))
       
   773             val ml_timing_elapsed = Time.ms(db.long(rs, Build_Info.ml_timing_elapsed))
       
   774             val ml_timing_cpu = Time.ms(db.long(rs, Build_Info.ml_timing_cpu))
       
   775             val ml_timing_gc = Time.ms(db.long(rs, Build_Info.ml_timing_gc))
       
   776             val ml_statistics = uncompress_properties(db.bytes(rs, Build_Info.ml_statistics))
       
   777             val heap_size = db.get(rs, Build_Info.heap_size, db.long _)
       
   778             val status = Session_Status.withName(db.string(rs, Build_Info.status))
       
   779 
       
   780             session_name ->
       
   781               Session_Entry(chapter, groups, threads, Timing(timing_elapsed, timing_cpu, timing_gc),
       
   782                 Timing(ml_timing_elapsed, ml_timing_cpu, ml_timing_gc), ml_statistics,
       
   783                 heap_size, status)
       
   784           }).toMap
       
   785         })
       
   786       Build_Info(sessions)
       
   787     }
   725   }
   788   }
   726 }
   789 }